charmbracelet / log

A minimal, colorful Go logging library 🪵
MIT License
2.4k stars 67 forks source link

Support slog.Leveler #98

Closed jaredallard closed 8 months ago

jaredallard commented 11 months ago

It'd be nice if one could use slog.Leveler to control the log level of the logger!

aymanbagabas commented 8 months ago

Since Log is just a handler to log/slog, you can dynamically change the Log instance level using SetLevel(level)

Amejonah1200 commented 2 months ago

There is one feature I like with Leveler it is because when it is cloned with .With(...), only the reference gets cloned and so, using LevelVar, it is possible to change the level of all loggers at once.

Basically, sub-loggers are following the super one in terms of log level.

To give more context, I create loggers using a global var instance which is apparently loaded before the config is. Might be a skill issue on my part and I should make my config also be loaded as a global var, however, being able to change the log level dynamically at once everywhere might be a good idea too.