tlog provides structured logging for Go applications on top of zerolog. It integrates with tcfg for configuration, ttrace for trace propagation, optional rotating file output, and optional Sentry reporting for error-level events.
- Process-wide default logger configured during package initialization
- Structured leveled logging through
D,I,W,E,F, andP - Optional
detailanderrorfields throughDetail,Detailf, andErr - Automatic
trace_idinjection fromcontext.Contextwhen a validttraceidentifier is present - Optional size-based and time-based file rotation with retention and gzip compression
- Optional forwarding of error-level log entries to Sentry
go get github.com/choveylee/tlogpackage main
import (
"context"
"github.com/choveylee/tlog"
)
func handleRequest(ctx context.Context, requestID string, userID int, err error) {
tlog.I(ctx).Msg("service startup completed successfully")
tlog.I(ctx).Detailf("user_id=%d", userID).Msgf("request %s has been accepted for processing", requestID)
if err != nil {
tlog.E(ctx).Err(err).Msg("request processing failed")
}
}tlog reads configuration during package initialization through tcfg. Exported constants such as AppName, LogLevel, LogFileEnable, LogFilePath, and SentryDsn define the supported keys. Use tcfg.LocalKey when environment-specific scoping is required.
Common configuration keys include the following:
AppNameLogLevelLogFileEnableLogFilePathLogFileSizeLogFileRotateLogFileExpiredLogFileCountLogFileCompressSentryDsn
See doc.go for the package overview and rendered API references. To inspect the package locally, run:
go doc -all github.com/choveylee/tlog