https://github.com/adwpc/xlog
simple and powerful golang logger which support console|file|rorate|k-v print|...
https://github.com/adwpc/xlog
console golang k-v-print logger rorate save-to-file
Last synced: about 1 year ago
JSON representation
simple and powerful golang logger which support console|file|rorate|k-v print|...
- Host: GitHub
- URL: https://github.com/adwpc/xlog
- Owner: adwpc
- Created: 2020-06-04T15:22:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-05T07:48:26.000Z (over 2 years ago)
- Last Synced: 2025-02-02T13:44:51.379Z (over 1 year ago)
- Topics: console, golang, k-v-print, logger, rorate, save-to-file
- Language: Go
- Homepage:
- Size: 207 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[中文](https://github.com/adwpc/xlog/blob/master/README_CN.md)
## Getting Started
```
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)
}
```
## Feature
- [x] Easy to use
- [x] High performance base on zerolog
- [x] Support printing field
- [x] log level
- [x] caller code line (eg:`example.go:32` you can go to this line by alt+click it in IDE)
- [x] caller function name
- [x] time format
- [x] format message (use Infof/Debugf/Xxxxf like fmt.Printf())
- [x] key-value message (use Info/Debug/Xxxx recommend, without writing %v)
- [x] all type support(int/string/float64/map/struct/interface)
- [x] Support output to console
- [x] pretty logging

- [x] Support output format normal
```
[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]}
```
- [x] 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"}
```
- [x] Support output to file
- [x] Support file rolling
```
TestOutputToFileJson.log
TestOutputToFileJson.log.2023-08-24 17:10:44
TestOutputToFileJson.log.2023-08-24 17:30:03
```
- [x] 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]}
```
- [x] 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]}"}
```