Overview
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.
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
-
Create a new Go-Mojito Handler that has a
mojito.Logger
argument.func SomeHandler(ctx mojito.Context, logger mojito.Logger) {}
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.
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!") }
FAQ
No frequently asked questions yet!