https://github.com/miiton/miilog
miiton san no logger (zap wrapper)
https://github.com/miiton/miilog
golang logging loki wrapper zap
Last synced: 5 months ago
JSON representation
miiton san no logger (zap wrapper)
- Host: GitHub
- URL: https://github.com/miiton/miilog
- Owner: miiton
- License: mit
- Created: 2022-06-14T14:01:15.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-09T23:09:43.000Z (almost 4 years ago)
- Last Synced: 2024-06-21T12:59:31.764Z (about 2 years ago)
- Topics: golang, logging, loki, wrapper, zap
- Language: Go
- Homepage:
- Size: 70.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# miilog
A [zap](https://github.com/uber-go/zap) wrapper for a slacker :zany_face:
## Example
```go
package main
import (
"github.com/miiton/miilog"
)
func init() {
miilog.SetLoggerProductionMust()
// or miilog.SetLoggerDevelopmentMust()
// or miilog.SetLoggerProductionWithLokiMust("https://loki.example.com/", "MYTENANTID", "{source=\"mygo_source\", job=\"mygo_job\", host=\"awesomehost\"}")
// or miilog.SetLoggerProductionWithLokiMust("https://loki.example.com/", "MYTENANTID", "{source=\"mygo_source\", job=\"mygo_job\", host=\"awesomehost\"}")
// or miilog.SetLoggerProductionWithFileAndLokiMust("/var/log/hoge.log","https://loki.example.com/", "MYTENANTID", "{source=\"mygo_source\", job=\"mygo_job\", host=\"awesomehost\"}")
}
func main() {
defer miilog.Sync()
miilog.Infow("hoge",
"job", "fuga",
"moreinfo", "moremore",
)
miilog.Warn("ahhhhhhhhh?")
miilog.Errorf("%s", "omgomgomgomgomg")
}
```
### Output
`SetLoggerProductionMust()`
```
{"level":"info","ts":"2022-06-15T06:54:43.072224552+09:00","caller":"tmp-zap/main.go:15","msg":"hoge","job":"fuga","moreinfo":"moremore"}
{"level":"warn","ts":"2022-06-15T06:54:43.072297729+09:00","caller":"tmp-zap/main.go:19","msg":"ahhhhhhhhh?"}
{"level":"error","ts":"2022-06-15T06:54:43.072306135+09:00","caller":"tmp-zap/main.go:20","msg":"omgomgomgomgomg","stacktrace":"main.main\n\t/home/USERNAME/dev/src/github.com/miiton/tmp-zap/main.go:20\nruntime.main\n\t/home/linuxbrew/.linuxbrew/Cellar/go/1.18/libexec/src/runtime/proc.go:250"}
```
`SetLoggerDevelopmentMust()`
```
2022-06-15T06:55:24.467+0900 INFO tmp-zap/main.go:15 hoge {"job": "fuga", "moreinfo": "moremore"}
2022-06-15T06:55:24.467+0900 WARN tmp-zap/main.go:19 ahhhhhhhhh?
2022-06-15T06:55:24.467+0900 ERROR tmp-zap/main.go:20 omgomgomgomgomg
main.main
/home/USERNAME/dev/src/github.com/miiton/tmp-zap/main.go:20
runtime.main
/home/linuxbrew/.linuxbrew/Cellar/go/1.18/libexec/src/runtime/proc.go:250
```