Encore provides built-in support for Structured Logging, meaning log messages that combine a free-form log message with structured and type-safe key-value pairs. This powerful combination enables straightforward, ad-hoc analysis of what your application is doing, in a way that is easy for a computer to parse and analyze.
Structured logging also enables the logs to be easily indexed, meaning they can be quickly filtered and searched through to find all logs that match a particular query.
Encore’s built-in logging support is fully integrated with its Distributed Tracing, which means that all logs you emit automatically become included in the active trace. This dramatically simplifies debugging of your application.
encore.dev/rlog in your package. Then simply call one of the package methods
Debug. For example:
rlog.Info("log message", "user_id", 12345, "is_subscriber", true) rlog.Error("something went terribly wrong!", "err", err)
The first parameter is the log message. After that follows zero or more key-value pairs for structured logging for context.
If you’re logging many log messages with the same key-value pairs each time it can be a bit cumbersome. To help with that, use
rlog.With() to group them into a context object, which then copies the key-value pairs into each log event:
ctx := rlog.With("user_id", 12345) ctx.Info("user logged in", "is_subscriber", true) // includes user_id=12345
For more information, see the API Documentation.
Encore also makes it easy to live-stream logs directly to your terminal from any environment, simply by running:
$ encore logs --env=prod