pkg/logger¶
A structured logging handler built on top of log/slog. It fans each record out to CLI, rotating files (via lumberjack), and syslog simultaneously, while enforcing context contracts such as type, application, and operation.
Quick Start¶
Configuration¶
LogConfig is split into:
MangoConfig: strict mode + correlation-id behaviour.Out: toggles forFile,Cli, andSyslog.
Friendly/verbose formats consume jq strings (gojq) and default to built-in templates when left empty.
Context Requirements¶
Strict mode enforces presence (and validity) of:
mangolog.TYPE– must be one ofBusiness,Security,Performance.mangolog.APPLICATIONmangolog.OPERATIONmangolog.CORRELATION_ID(whencorrelation-id.strictis true; auto-generated ifauto-generateis true).
On missing or invalid fields, Handle logs an error and returns it to the slog caller.
Outputs¶
CLI¶
- When
friendlyis true, Mango Logger runs the log through the jq template (e.g.,"[INFO] create - success"). - Otherwise, it prints raw JSON to stdout/stderr.
verbosegates debug logs on stdout and includes correlation IDs for INFO-level messages.
File¶
- Writes newline-delimited JSON (
StructuredLog) using lumberjack rotation. debugcontrols whetherLevelDebugentries reach the file.
Syslog¶
- Enabled by setting
out.syslog.facilityor the corresponding constant (e.g.,mangolog.SyslogFacilityLocal0). - Severity is derived from the slog level.
- Not available on Windows (build tags guard the implementation).
Structured Output¶
Tips¶
- Use middleware to stamp context keys (
TYPE,APPLICATION,OPERATION,CORRELATION_ID) once per request. - Toggle
Cli.Verbosevia CLI flags (--verbose) to expose debug logs during troubleshooting. - When
Strictis enabled, avoid mutating the globalREQUIRED_FIELDS; create fresh contexts per request to prevent leaking values across goroutines.