jcelliott / lumber

A simple logger for Go
MIT License
63 stars 16 forks source link

Move log levels up one #2

Open beatgammit opened 11 years ago

beatgammit commented 11 years ago

It would be nice to have log levels start at 1 and have the default log level be 0. The meaning of the default log level could be user-configurable (e.g. Info or 3).

The reason here is that when parsing options with the default "flag" package, it's hard to know when a user wants 0 (trace) or the default (3). Currently, I have to do this:

flag.IntVar(&loglevel, "loglevel", lumber.Info, "some helpful text")

When there are multiple layers (e.g. config file and cmd options), it's more difficult to write fallback code (if not specified on the command-line, use config file}. The only way I could think of is to use an invalid default value (e.g. -1; ugly...) with flag or parse the config file first (not possible if a command-line option can specify where the config file is). This is a solvable problem, but not KISS IMHO.

Everything would be 1e6x easier if log levels started at 1, and 0 meant the default level.