██╗░░░░░░█████╗░░██████╗░░██████╗░███████╗██████╗░ ██║░░░░░██╔══██╗██╔════╝░██╔════╝░██╔════╝██╔══██╗ ██║░░░░░██║░░██║██║░░██╗░██║░░██╗░█████╗░░██████╔╝ ██║░░░░░██║░░██║██║░░╚██╗██║░░╚██╗██╔══╝░░██╔══██╗ ███████╗╚█████╔╝╚██████╔╝╚██████╔╝███████╗██║░░██║ ╚══════╝░╚════╝░░╚═════╝░░╚═════╝░╚══════╝╚═╝░░╚═╝ logger is an attempt to improve log visualization by embedding parent/child relationships within the logging context, making it easier to trace log flows. It is uses log/slog package under the hood.
To install the logger binary, run the following command:
go install ella.to/logger/cmd/logger-server@latestThis binary includes both the UI and server components. You can start the logger server by simply running:
logger-serverBy default, the server runs on address localhost:2022. To change the port, specify it as an argument:
logger-server localhost:2021You can then access the UI via your browser at:
http://localhost:2022
First, include the logger library in your project by running:
go get ella.to/logger@latestNext, add the following code to the main function of your project to set up the logger:
package main import ( // other imports "log/slog" "os" "ella.to/logger" ) func main() { slog.SetDefault( slog.New( logger.NewHttpExporter( "http://localhost:2022", // logger server address slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ Level: slog.LevelDebug, }), ), ), ) // your application logic }The logger provides four logging functions—Info, Debug, Warn, and Error—which work similarly to slog.InfoContext.
Example:
ctx := context.Background() logger.Info(ctx, "first log message", "request_id", 1)Each of these functions returns a new context, allowing you to pass it to subsequent logs, creating parent/child relationships between logs.
This library also includes an HTTP middleware compatible with Go's http.Handler signature:
func(http.Handler) http.HandlerYou can use this middleware to either retrieve the parent log ID from the incoming request headers or generate a new parent ID, ensuring all logs within an HTTP request are grouped together for better traceability.