Skip to content

sinlovgo/zlog

Repository files navigation

TravisBuildStatus GoDoc GoReportCard codecov

for what

depends

in go mod project, last version is v1.1.0

# before above global settings
# test version info
$ git ls-remote -q http://github.com/sinlovgo/zlog.git

# test depends see full version
$ go list -v -m -versions github.com/sinlovgo/zlog
# or use last version add go.mod by script
$ echo "go mod edit -require=$(go list -m -versions github.com/sinlovgo/zlog.git | awk '{print $1 "@" $NF}')"
$ echo "go mod vendor"

config file

zap:
  AtomicLevel: -1 # DebugLevel:-1 InfoLevel:0 WarnLevel:1 ErrorLevel:2
  FieldsAuto: false # is use auto Fields key set
  Fields:
    Key: key
    Val: val
  Development: true # is open Open file and line number
  Encoding: console # output format, only use console or json, default is console
  rotate:
    Filename: log/zlog.log # Log file path
    MaxSize: 16 # Maximum size of each log file, Unit: M
    MaxBackups: 10 # How many backups are saved in the log file
    MaxAge: 7 # How many days can the file be keep, Unit: day
    Compress: true # need compress
  EncoderConfig:
    TimeKey: time
    LevelKey: level
    NameKey: logger
    CallerKey: caller
    MessageKey: msg
    StacktraceKey: stacktrace

use-code

import (
	"github.com/sinlovgo/zlog"
)
func main() {
    // default config conf/config.yaml
	err := zlog.Init("")
	if err != nil {
		fmt.Printf("zlog init error %v\n", err)
		return
	}
	zlog.Sugared.Debugf("Sugared DEBUG info %s", "message")
	zlog.Sugared.Infof("Sugared INFO info %v", "message")
	zlog.Sugared.Infof("Sugared info num %d", 10)
	zlog.Sugared.Debug("Sugared Debug can not format %v", "debug-info")
}

dev

  • use to replace sinlovgo/zlog to you code

  • and run

make init
  • test code
make test

add main.go file and run

make run

dev

evn

  • golang sdk 1.13+

docker

base docker file can replace

About

golang log rotation by zap and read config by viper

Resources

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENCE
Apache-2.0
LICENCE-APACHE

Stars

Watchers

Forks

Packages

No packages published