https://github.com/mengdu/mo
A leveled logger library for golang.
https://github.com/mengdu/mo
golang log logger mo
Last synced: 11 months ago
JSON representation
A leveled logger library for golang.
- Host: GitHub
- URL: https://github.com/mengdu/mo
- Owner: mengdu
- License: other
- Created: 2023-05-25T01:31:59.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-02T10:08:07.000Z (11 months ago)
- Last Synced: 2025-08-02T11:36:59.003Z (11 months ago)
- Topics: golang, log, logger, mo
- Language: Go
- Homepage:
- Size: 580 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mo

A leveled logger library for golang.
```sh
go get github.com/mengdu/mo
```
```go
package main
import (
"github.com/mengdu/mo"
)
func main() {
mo.SetBase(
mo.Value("ts", mo.Timestamp("15:04:05.000")),
mo.Value("caller", mo.Caller(4)),
mo.Value("tag", "dev"),
)
mo.Debug("debug message")
mo.Info("info message")
mo.Warn("warn message")
mo.Error("error message")
// mo.Fatal("fatal message")
mo.Debugf("debugf message %s", "test")
mo.Infof("infof message %s", "test")
mo.Warnf("warnf message %s", "test")
mo.Errorf("errorf message %s", "test")
// mo.Fatalf("fatalf message %s", "test")
mo.Debugw("debugw message", mo.Value("k1", 123), mo.Value("k2", true), mo.Value("k3", []int{1, 2, 3}))
mo.Infow("infow message", mo.Value("k1", 123), mo.Value("k2", true), mo.Value("k3", []int{1, 2, 3}))
mo.Warnw("warnw message", mo.Value("k1", 123), mo.Value("k2", true), mo.Value("k3", []int{1, 2, 3}))
mo.Errorw("errorw message", mo.Value("k1", 123), mo.Value("k2", true), mo.Value("k3", []int{1, 2, 3}))
// mo.Fatalw("fatalw message", mo.Value("k1", 123), mo.Value("k2", true), mo.Value("k3", []int{1, 2, 3}))
}
```
- [Example](examples/main.go)
- [Rotate Example](examples/rotate/main.go)
- [Opentelemetry Example](examples/otel/main.go)
## Benchmark
```
go test -cpu=4 -benchmem -benchtime=5s -bench "^Benchmark"
goos: darwin
goarch: amd64
pkg: github.com/mengdu/mo
cpu: Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
BenchmarkDefault-4 39429948 138.1 ns/op 64 B/op 2 allocs/op
BenchmarkDefaultWithCaller-4 8169790 660.9 ns/op 496 B/op 18 allocs/op
BenchmarkJson-4 17008795 339.4 ns/op 124 B/op 6 allocs/op
BenchmarkJsonWithCaller-4 5119900 1157 ns/op 512 B/op 16 allocs/op
BenchmarkJsonWithCallerFull-4 3169348 1869 ns/op 720 B/op 24 allocs/op
PASS
ok github.com/mengdu/mo 38.280s
```