https://github.com/yeqown/log
A light log library for go application.
https://github.com/yeqown/log
golang lite logging
Last synced: 5 months ago
JSON representation
A light log library for go application.
- Host: GitHub
- URL: https://github.com/yeqown/log
- Owner: yeqown
- License: mit
- Created: 2018-04-21T08:52:42.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2025-05-21T02:08:49.000Z (about 1 year ago)
- Last Synced: 2025-05-21T03:25:00.132Z (about 1 year ago)
- Topics: golang, lite, logging
- Language: Go
- Homepage:
- Size: 957 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## log
[](https://goreportcard.com/report/github.com/yeqown/log) [](https://pkg.go.dev/github.com/yeqown/log)
a lite golang log library, easy to get start and no dependency.
### Features
- [x] `consolt` and `filelog` support
- [x] `WithFields` support
- [x] lite and easy to use
### Install
```sh
go get -u github.com/yeqown/log
```
### Quick Start
There is sample code of using `log`.
```go
package main
type embed struct {
FieldA string
FieldB int
}
func main() {
// using builtin logger
log.Info(1, 2, 3, 4, 5)
log.Infof("this is format: %d", 2)
log.
WithField("key1", "value1").
WithFields(log.Fields{
"key2": "value2",
"key3": "value3",
"key4": "value4",
"key5": "value5",
"key6": "value6",
"key7": "value7",
"key8": "value8",
}).Error("test error")
// using new logger
logger, _ := log.NewLogger(
log.WithLevel(log.LevelError),
log.WithGlobalFields(log.Fields{"global_key": "global_value"}),
)
logger.Info(1, 2, 3, 4, 5)
logger.Infof("this is format: %d", 2)
logger.WithField("logger", "it's me").
WithFields(log.Fields{
"key2": "value2",
"key3": "value3",
"key4": "value4",
"key5": "value5",
"key6": "value6",
"key7": "value7",
"embed": embed{
FieldA: "aaa",
FieldB: 112091,
},
"embed_ptr": &embed{
FieldA: "aaa",
FieldB: 112091,
},
}).Error("test error")
// [Error] file="/Users/yeqown/projects/opensource/log/logger_entry.go" fn="github.com/yeqown/log.(*entry).output"
// line="109" timestamp="1596090798" formatted_time="2020-07-30T14:33:18+08:00" embed="{aaa 112091}"
// embed_ptr="&{aaa 112091}" global_key="global_value" key2="value2" logger="it's me" msg="test error"
}
```
### Migrate
Here is a broken change from `d68941c` to `v1.x`. `v1.x` is advised to use.
### shots
Here are some shots of using example.
##### 1. stdout shots

##### 2. file shots
> output to stdout and file both.