Go-Mojito's logger interface provides a dependency-independent way to dependency inject a logger into your handlers and middleware. By default, the built-in fmt-based logger is used, but you can easily replace it with a custom implementation like zerolog.

  • Built-in Implementation available
  • Can be replaced
  • Multi-Implementation suppported
  • Decorate logs with fields

Of course you can also have multiple loggers injected by using named dependencies, even without replacing the builtin logger, although we recommend doing so.

Quick Start

  1. Create a new Go-Mojito Handler that has a mojito.Logger argument.

    func SomeHandler(ctx mojito.Context, logger mojito.Logger) {}
  2. Go-Mojito will now detect that you want the default logger injected into your handler. If Go-Mojito was unable to link the dependency, you will see error logs when you start up your web app.

  3. Make use of the dependency-injected logger instance

    func SomeHandler(ctx mojito.Context, logger mojito.Logger) {
        logger.Field("key", "value").Info("SomeHander was called, great!")


No frequently asked questions yet!