gookit / slog

📑 Lightweight, configurable, extensible logging library written in Go. Support multi level, multi outputs and built-in multi file logger, buffers, clean, rotate-file handling.一个易于使用的,轻量级、可配置、可扩展的日志库。支持多个级别,输出到多文件;内置文件日志处理、自动切割、清理、压缩等增强功能

Home Page:https://pkg.go.dev/github.com/gookit/slog

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not change to customization format Template

tonyho opened this issue · comments

System (please complete the following information):

  • OS: Windows 10 X64
  • GO Version: 1.18
  • Pkg Version: don't know, I use the go get to use the code

Describe the bug

Customization template is not taken for printing.

To Reproduce

import 	log "github.com/gookit/slog"

const simplestTemplate = "[{{datetime}}] [{{level}}] {{message}} {{data}} {{extra}}"

func init() {
	log.GetFormatter().(*log.TextFormatter).Template = simplestTemplate
	log.SetLogLevel(log.ErrorLevel)
	log.Errorf("Test\n")
}
func main() {
}

Expected behavior

I think it should output the following log:

[2022/05/18T17:20:39] [ERROR] Test

While, it outputs:

[2022/05/18T17:20:39] [application] [ERROR] [proc.go:6222,doInit] Test

A bug has been fixed, version v0.3.1.
Please upgrade to the latest version.

The README has an error and should use SetTemplate()

const simplestTemplate = "[{{datetime}}] [{{level}}] {{message}} {{data}} {{extra}}"

log.GetFormatter().(*log.TextFormatter).SetTemplate(simplestTemplate)

Fix verified. Thanks for the lighting speed fix.