internal, log: make parameter out of formatter

This commit is contained in:
Kurkó Mihály 2018-04-23 14:38:55 +03:00
parent 53d2cc21ce
commit 9a1ee019d1
2 changed files with 10 additions and 3 deletions

View file

@ -116,7 +116,14 @@ func Setup(ctx *cli.Context, disklogs string) error {
// logging // logging
log.PrintOrigins(ctx.GlobalBool(debugFlag.Name)) log.PrintOrigins(ctx.GlobalBool(debugFlag.Name))
if disklogs != "" { if disklogs != "" {
glogger.SetHandler(log.MultiHandler(ostream, log.RotatingFileHandler(disklogs, 262144))) glogger.SetHandler(log.MultiHandler(
ostream,
log.RotatingFileHandler(
disklogs,
262144,
log.JsonFormatOrderedCtx(false, true),
),
))
} }
glogger.Verbosity(log.Lvl(ctx.GlobalInt(verbosityFlag.Name))) glogger.Verbosity(log.Lvl(ctx.GlobalInt(verbosityFlag.Name)))
glogger.Vmodule(ctx.GlobalString(vmoduleFlag.Name)) glogger.Vmodule(ctx.GlobalString(vmoduleFlag.Name))

View file

@ -88,7 +88,7 @@ func (w *writeCounter) Write(p []byte) (n int, err error) {
// RotatingFileHandler returns a handler which writes log records to file chunks // RotatingFileHandler returns a handler which writes log records to file chunks
// at the given path. When a file's size reaches the limit, the handler creates // at the given path. When a file's size reaches the limit, the handler creates
// a new file named after the timestamp of the first log record it will contain. // a new file named after the timestamp of the first log record it will contain.
func RotatingFileHandler(path string, limit uint) Handler { func RotatingFileHandler(path string, limit uint, formatter Format) Handler {
if err := os.MkdirAll(path, 0755); err != nil { if err := os.MkdirAll(path, 0755); err != nil {
panic(err) panic(err)
} }
@ -98,7 +98,7 @@ func RotatingFileHandler(path string, limit uint) Handler {
panic(err) panic(err)
} }
counter := new(writeCounter) counter := new(writeCounter)
h := StreamHandler(counter, JsonFormatOrderedCtx(false, true)) h := StreamHandler(counter, formatter)
re := regexp.MustCompile(".log$") re := regexp.MustCompile(".log$")
var i int var i int