package main
import (
xlog "github.com/adwpc/xlog"
)
func main() {
xlog.Init(xlog.TinyCoderConsoleConfig)
defer xlog.Close()
xlog.Infof("Call Infof: %s %d %v", "abc", 123, 1.23)
xlog.Info("Call Info", "string", "abc", "int", 123, "float", 1.23)
}
-
Easy to use
-
High performance base on zerolog
-
Support printing field
- log level
- caller code line (eg:
example.go:32
you can go to this line by alt+click it in IDE) - caller function name
- time format
- format message (use Infof/Debugf/Xxxxf like fmt.Printf())
- key-value message (use Info/Debug/Xxxx recommend, without writing %v)
- all type support(int/string/float64/map/struct/interface)
-
Support output to console
[2023-08-24 17:48:17.227] [I] [example.go:88][TestOutputToConsoleNormal] TestOutputToConsoleNormal Info float=1.23 int=123 map={"a":1,"b":2} string=abc struct="{a:1 b:{b:1} c:map[a:1 b:2]}" [2023-08-24 17:48:17.227] [I] [example.go:88][TestOutputToConsoleNormal] TestOutputToConsoleNormal Infof: abc 123 1.23 map[a:1 b:2] {a:1 b:{b:1} c:map[a:1 b:2]}
- Support output format json
{"level":"info","time":"2023-08-24 18:12:04.099","caller":"example.go:32","message":"TestOutputToConsoleJson Infof: abc 123 1.23 map[a:1 b:2] {a:1 b:{b:1} c:map[a:1 b:2]}"} {"level":"info","string":"abc","int":123,"float":1.23,"map":{"a":1,"b":2},"struct":"{a:1 b:{b:1} c:map[a:1 b:2]}","time":"2023-08-24 18:12:04.099","caller":"example.go:33","message":"TestOutputToConsoleJson Info"}
-
Support output to file
- Support file rolling
TestOutputToFileJson.log TestOutputToFileJson.log.2023-08-24 17:10:44 TestOutputToFileJson.log.2023-08-24 17:30:03
- Support output format normal
[2023-08-24 17:30:08.343] [I] [example.go:75][TestOutputToFileNormal] TestOutputToFileNormal Info float=1.23 int=123 map={"a":1,"b":2} string=abc struct="{a:1 b:{b:1} c:map[a:1 b:2]}" [2023-08-24 17:30:08.343] [I] [example.go:75][TestOutputToFileNormal] TestOutputToFileNormal Infof: abc 123 1.23 map[a:1 b:2] {a:1 b:{b:1} c:map[a:1 b:2]}
- Support output format json
{"level":"info","string":"abc","int":123,"float":1.23,"map":{"a":1,"b":2},"struct":"{a:1 b:{b:1} c:map[a:1 b:2]}","time":"2023-08-24 18:13:10.455","caller":"example.go:33","message":"TestOutputToFileJson Info"} {"level":"info","time":"2023-08-24 18:13:10.455","caller":"example.go:32","message":"TestOutputToFileJson Infof: abc 123 1.23 map[a:1 b:2] {a:1 b:{b:1} c:map[a:1 b:2]}"}