A simple and opinionated library that lets you set up and use zap quickly.
Simplog is a small library that sets zap up in a way that is easy to use and provides some additional features. Simplog is opinionated and tries to provide a good default configuration for most use cases. If you need more features, you may use the resulting zap logger directly.
- Client and server modes
- Visualized log levels
- Optional context-binding support
- Easy to use
go get -u github.com/nikoksr/simplog
For more examples, see the examples directory.
package main
import "github.com/nikoksr/simplog"
func main() {
// Using the manual configuration; alternatively you can use NewClientLogger() or NewServerLogger().
logger := simplog.NewWithOptions(&simplog.Options{
Debug: false,
IsServer: true,
})
// At this point, you're using a zap.SugaredLogger and can use it as you would normally do.
logger.Info("You're awesome!")
logger.Warn("Coffee is almost empty!")
logger.Error("Unable to operate, caffein levels too low.")
}
In debug mode, independent of the mode, the logger will print all messages greater-equal than the debug-level in a human readable format.
2022-10-23T14:25:15.537+0200 INFO simplog test-simplog/main.go:12 You're awesome!
2022-10-23T14:25:15.537+0200 WARN simplog test-simplog/main.go:13 Coffee is almost empty!
2022-10-23T14:25:15.537+0200 ERROR simplog test-simplog/main.go:14 Unable to operate, caffein levels too low.
In production mode, the client logger will print all messages greater-equal than the info-level in a human readable format and replace the log level with a colored emoji.
The symbols are configurable and can be set to any string.
💡 You're awesome!
⚠️ Coffee is almost empty!
🔥 Unable to operate, caffein levels too low.
In production mode, the server logger will print all messages greater-equal than the info-level in a structured format.
{"level":"info","ts":1666528089.4873903,"logger":"simplog","caller":"test-simplog/main.go:12","msg":"You're awesome!"}
{"level":"warn","ts":1666528089.4874253,"logger":"simplog","caller":"test-simplog/main.go:13","msg":"Coffee is almost empty!"}
{"level":"error","ts":1666528089.487434,"logger":"simplog","caller":"test-simplog/main.go:14","msg":"Unable to operate, caffein levels too low."}
- Logo by the amazing MariaLetta/free-gophers-pack