Skip to content

feat: control log verbosity with LOG_LEVEL - #359

Open
eliasmeireles wants to merge 3 commits into
asternic:mainfrom
eliasmeireles:feat/log-level-control
Open

feat: control log verbosity with LOG_LEVEL#359
eliasmeireles wants to merge 3 commits into
asternic:mainfrom
eliasmeireles:feat/log-level-control

Conversation

@eliasmeireles

@eliasmeireles eliasmeireles commented Aug 16, 2026

Copy link
Copy Markdown

Problem

wuzapi's own logs have no level control. SetGlobalLevel is never called, so zerolog stays at its TraceLevel default and every Debug and Info line is emitted unconditionally. There is no flag and no environment variable to turn it down — -wadebug governs the whatsmeow logger (waLog), not zerolog.

On a busy instance this is most of the log. Measured on a deployment with active sessions, over a 10-minute window: 728 lines — 38% Info, 35% Debug, 19% Warn, the rest being multi-line payload dumps. Operators either keep all of it or grep around it.

Change

LOG_LEVEL sets the minimum severity for wuzapi's own logs, accepting the names zerolog.ParseLevel understands (trace, debug, info, warn, error, fatal, panic).

It is set as the first statement in main() on purpose: the global level is consulted per record rather than baked into the logger, so setting it there also covers the configuration lines emitted before the ConsoleWriter/JSON logger is installed. Placed after the logger, those lines escape the filter.

Compatibility

Unset or unrecognized values keep today's behaviour exactly — zerolog.ParseLevel returns an error, the level is left untouched, and nothing is silenced by a typo. zerolog.NoLevel (which an empty string parses to) is excluded for the same reason. An operator who does not set the variable sees no change at all.

Testing

go build ./..., go vet ./... and go test ./... pass.

Verified on a live deployment with active WhatsApp sessions, same 10-minute window and comparable traffic:

LOG_LEVEL lines / 10 min
unset (current behaviour) 728
warn 96
error 0

At warn the Debug and Info volume disappears while warnings and errors still come through; at error the instance stays silent unless something actually fails. Boot-time configuration lines are filtered too, confirming the placement in main().


The branch has two follow-up commits reverting log-level reclassifications I had included initially; the net diff is the 14 lines in main.go. Happy to squash into a single commit if you prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant