...in which I attempt to convince you that log tagging is better than log levels
log tagging : log levels :: Gmail labels : Outlook folders
A longer explanation (for the unconvinced, the insatiably curious, and the androids among us)
In traditional logging and in today's standard logging libraries like Ruby's Logger class and Python's Logging module, each log entry is assigned a log level (
debug). In production, the first four are often left on, and the last one,
debug, is often turned off.
life with log levels
- Each log entry is in one and only one of the log levels (e.g.
- Each log level is on or off in your environment settings.
- This means that if, in order to work on Feature C, you turn
debugon, your log will suddenly be flooded with irrelevant
debuglog entries from long-completed Features A and B. This forces you to revisit your A and B code, commenting or deleting logging calls - but some of these calls could come in handy in the future, at which point you'll have to re revisit your code again.
- Puppies don't play and it's always winter :(
life with log tagging, thanks to Tagalog!
- Each log entry has zero or more tags. These tags can be any strings (or in Ruby, symbols) you like -- even
- Each tag is on or off in Tagalog's code (which you can hook to your environment's settings if you like).
- Tagalog will log an entry once for each associated tag that's set to on.
- You develop faster, with less work, and most importantly, with less code.
- All dogs remain playful, housebroken puppies for eternity, and together we obtain immortality.
Tagalog is easy to implement
You only need to know one function:
...where 'message' is a string or a stringable type(?), and 'tagging' is either a string tag or an array of string tags.
Tagalog is extensible
If you want to have two subclasses for Tagalog, like "DebugLogger"" and "ErrorLogger", you can do so quite easily. Just extend Tagalog and override what you want to override, such as the path to the output file (ErrorLogger could write to your webserver's error logs, for instance).
Tagalog is minimal
Tagalog is one drop-in file and is expressed in so little code that you can learn your way around it in just a few minutes.
- Ruby version has moved here. For the time being, the Python and PHP versions still lounge hereabouts in a cuddle puddle.