# README
for what
- this project used to golang log management
Contributing
We welcome community contributions to this project.
Please read Contributor Guide for more information on how to get started.
depends
in go mod project
# warning use privte git host must set
# global set for once
# add private git host like github.com to evn GOPRIVATE
$ go env -w GOPRIVATE='github.com'
# use ssh proxy
# set ssh-key to use ssh as http
$ git config --global url."[email protected]:".insteadOf "http://github.com/"
# or use PRIVATE-TOKEN
# set PRIVATE-TOKEN as gitlab or gitea
$ git config --global http.extraheader "PRIVATE-TOKEN: {PRIVATE-TOKEN}"
# set this rep to download ssh as https use PRIVATE-TOKEN
$ git config --global url."ssh://github.com/".insteadOf "https://github.com/"
# before above global settings
# test version info
$ git ls-remote -q http://github.com/bar-counter/slog.git
# test depends see full version
$ go list -mod readonly -v -m -versions github.com/bar-counter/slog
# or use last version add go.mod by script
$ echo "go mod edit -require=$(go list -mod=readonly -m -versions github.com/bar-counter/slog | awk '{print $1 "@" $NF}')"
$ echo "go mod vendor"
evn
- golang sdk 1.17+
Features
- easy API to use,
slog.Debug("this is debug")
... - easy config new
slog.DefaultLagerDefinition()
- config load by
yaml file
- support stdout and file
- color stdout support
- show/hide code line number
- format json/stdout
- rolling policy at file output
- log_rotate_date: max 10 days, greater than will change to 1, rotate date, coordinate
log_rotate_date: daily
- log_rotate_size: max 64M, greater than will change to 10, rotate size,coordinate
rollingPolicy: size
- log_backup_count: max 100 files, greater than will change to 7, log system will compress the log file when log reaches rotate set, this set is max file count
- log_rotate_date: max 10 days, greater than will change to 1, rotate date, coordinate
- more perfect test case coverage
- more perfect benchmark case
usage
- use
slog.DefaultLagerDefinition()
package main
import (
"fmt"
"github.com/bar-counter/slog"
"testing"
)
func TestMainLog(t *testing.T) {
lagerDefinition := slog.DefaultLagerDefinition()
err := slog.InitWithConfig(lagerDefinition)
if err != nil {
t.Fatal(err)
}
slog.Debug("this is debug")
slog.Infof("this is info %v", "some info")
slog.Warn("this is warn")
slog.Error("this is error", fmt.Errorf("some error"))
}
- load with
*.yaml
writers: stdout # file,stdout.`file` will let `logger_file` to file,`stdout` will show at std, most of the time use bose
logger_level: DEBUG # DEBUG INFO WARN ERROR FATAL
logger_file: logs/foo.log # "" is not writer log file, and this will cover by env: CHASSIS_HOME
log_hide_lineno: false # `true` will hide code line number, `false` will show code line number, default is false
log_format_text: false # format_text `false` will format json, `true` will out stdout
rolling_policy: size # rotate policy, can choose as: daily, size. `daily` store as daily,`size` will save as max
log_rotate_date: 1 # max 10 days, greater than will change to 1, rotate date, coordinate `log_rotate_date: daily`
log_rotate_size: 8 # max 64M, greater than will change to 10, rotate size,coordinate `rollingPolicy: size`
log_backup_count: 7 # max 100 files, greater than will change to 7, log system will compress the log file when log reaches rotate set, this set is max file count
- use
slog.InitWithFile("log.yaml")
package main
import (
"fmt"
"github.com/bar-counter/slog"
)
func main() {
err := slog.InitWithFile("log.yaml")
if err != nil {
panic(err)
}
slog.Debug("this is debug")
slog.Infof("this is info %v", "some info")
slog.Warn("this is warn")
slog.Error("this is error", fmt.Errorf("some error"))
}
dev
make init dep
- test code
make test
add main.go file and run
# run at env dev
make dev
# run at env ordinary
make run
- ci to fast check
make ci
docker
# then test build as test/Dockerfile
$ make dockerTestRestartLatest
# clean test build
$ make dockerTestPruneLatest
# more info see
$ make helpDocker
use
- use to replace
bar-counter/slog
to you code
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
CopyFile copy file.
No description provided by the author
No description provided by the author
DefaultLagerDefinition
use default lager definition.
No description provided by the author
No description provided by the author
EscapPath escape path.
No description provided by the author
No description provided by the author
FilterFileList function for filter file list path : where the file will be filtered pat : regexp pattern to filter the matched file.
No description provided by the author
No description provided by the author
InitWithConfig
use pass lager configuration.
InitWithFile
readPassLagerConfigFile is unmarshal the paas lager configuration file(log.yaml).
LogRotate function for log rotate path: where log files need rollover MaxFileSize: MaxSize of a file before rotate.
NewLoggerExt is a function which is used to write new logs.
RegisterWriter is used to register a io writer.
No description provided by the author
No description provided by the author
# Constants
DEBUG is a constant of string type.
No description provided by the author
No description provided by the author
No description provided by the author
constant values for logrotate parameters.
constant values for logrotate parameters.
constant values for logrotate parameters.
constant values for logrotate parameters.
constant values for logrotate parameters.
No description provided by the author
# Variables
PassLagerDefinition
is having the information about logging.
# Structs
Config
is a struct which stores details for maintaining logs.
Lager struct for logger parameters.
PassLagerCfg is the struct for lager information(passlager.yaml).