Quick start
Install Logy, create a logger, and configure your first output
Introduction
Logy is a configurable logger for Go applications. In this guide, you install the package, create a logger, write messages, attach request context, and enable structured output.
If the package is not installed yet, add it first:
go get go.codnect.io/logyCreate a logger
Use logy.Get when the logger should be named from the package where it is
called. This keeps logs tied to the code that produced them without passing names
around manually.
package main
import "go.codnect.io/logy"
func main() {
log := logy.Get()
log.Info("application started")
log.Warn("cache miss for key {}", "user:42")
log.Error("request failed")
log.Debug("loaded {} routes", 12)
log.Trace("created internal cache")
}Info, Warn, Error, Debug, and Trace write at different levels. Message
arguments use {} placeholders, so call sites stay compact while the logger
handles formatting.
Run the program:
go run .The console output stays readable while keeping time, level, logger name, and message visible:
Add request context
Use context fields when each request, job, or operation should carry values such as trace IDs, span IDs, tenant IDs, or user IDs.
package main
import (
"context"
"go.codnect.io/logy"
)
func main() {
log := logy.Get()
ctx := logy.WithValue(context.Background(), "traceId", "trace-123")
ctx = logy.WithValue(ctx, "spanId", "span-456")
log.I(ctx, "request completed")
}Context values are attached to the log record by the handler. Your application
code can keep the same logger while request-specific metadata moves through
context.Context.
With trace and span values in context, the formatted output includes them next to the timestamp:
Configure output
Use logy.LoadConfig when output settings are assembled by the application.
This example enables JSON records for the console handler.
err := logy.LoadConfig(&logy.Config{
Console: &logy.ConsoleConfig{
Enabled: true,
Json: &logy.JsonConfig{
Enabled: true,
},
},
})
if err != nil {
panic(err)
}Configuration controls levels, handlers, output format, JSON fields, and package specific behavior without changing the logging calls.
What happened?
logy.Get created a package-based logger. The level methods wrote messages, the
context helpers attached request metadata, and LoadConfig changed how records
are emitted.
Continue with Configuration to customize levels, handlers, formats, and JSON fields.
