- this project used to golang log management
We welcome community contributions to this project.
Please read Contributor Guide for more information on how to get started.
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"
- golang sdk 1.17+
- 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
- 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"))
}
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
# then test build as test/Dockerfile
$ make dockerTestRestartLatest
# clean test build
$ make dockerTestPruneLatest
# more info see
$ make helpDocker
- use to replace
bar-counter/slog
to you code