Skip to content

[Draft] Feature/zap logger#18

Draft
whitespire wants to merge 2 commits into
Neon-Genesis-Linux:mainfrom
whitespire:feature/zap-logger
Draft

[Draft] Feature/zap logger#18
whitespire wants to merge 2 commits into
Neon-Genesis-Linux:mainfrom
whitespire:feature/zap-logger

Conversation

@whitespire
Copy link
Copy Markdown
Contributor

@whitespire whitespire commented May 12, 2026

This PR brings in an opinionated implementation of Zap logger as a singleton module.
It was written for maximum compatibility with slog (a drop in module replacement) through creating module-level aliases for zap's field functions (so, zap.String is available as logger.String, zap.Int as logger.Int, etc).

Usage:

  1. import logger package.
  2. add defer logger.Sync() to main()
  3. call logger.Info/Debug/Warn/Fatal just as you would with slog
  4. Extra: the module assumes that the environment variable "ENV" is used to differentiate dev from production, and will create zap's Production logger if ENV=production. Most notably, prodution logger works at level Info and above and got ratelimit / sampling set up for over 100 lines / sec.

Footguns involved:

  • unit tests might not play nice with a singleton like that. Might need to do logger injection down the line for that.
  • not all zap's field functions are aliased yet (for example, Uint8, Stringp, Strings, etc.) Will need to add them to aliaces in current implementation.
  • zap.Logger.Error() is aliased to logger.Error(), zap.Error() is unavailable. Use logger.NamedError() (alias of zap.NamedError()) for the error field type instead.

@Simon-Weij
Copy link
Copy Markdown
Contributor

Why zap over just using slog? Zap seems very speed oriented, while this is a simple discord bot which probably doesn't need zap at all. IMO the standard library is more than capable for our needs

@whitespire whitespire changed the title Feature/zap logger [Draft] Feature/zap logger May 12, 2026
@whitespire whitespire marked this pull request as draft May 12, 2026 09:30
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.

2 participants