Logger

Go-Mojito provides you with an easy to use logging system, which can be backed by any existing logger by writing an adapter. By default Go-Mojito ships with Zerolog as well was a no-dependency builtin logger. The Zerolog logger is set as default.

Logging Methods

The logger interface defines a few log levels for which there is a regular and a printf version each. For example Info(val) and Infof(msg, values...)

  • Trace
  • Debug
  • Info
  • Warn
  • Error
  • Fatal Exits

Fields

Sometimes you want to annotate your log message with small pieces of information to help you understand what's going on. For example an affected user's id or a request id. This is what Fields are for.

package main

// imports

func main() {
  // Write an informational log
  mojito.DefaultLogger().Field("id", "1").Info("Hello World")

  // Use .Fields when you have multiple fields to apply
  mojito.DefaultLogger().Fields(logger.Fields{
    "id": "1",
  }).Info("Hello World")
}

Easy Default Logger Package

To make the default logger as easy to use as possible, go-mojito ships with a log package which offers all the methods as a package method, internally it will call up the default Go-Mojito logger to print out the log. This is an alternative of doing mojito.DefaultLogger() and has no other purpose.