<img src=“https://secure.travis-ci.org/fredemmott/my_stuff-logger.png” /> <img src=“https://gemnasium.com/fredemmott/my_stuff-logger.png” />
A drop-in replacement for Ruby’s standard Logger class, if you’re just using the basic features.
gem install my_stuff-logger
Create an instance, then just like the standard Logger class; take a look at example.rb.
-
The filename, line number, and method are always included
-
By default, a backtrace is included for errors and fatals. This can be tuned to any level, including even for debug, or for none at all.
File names are shown relative to a choosable root (which defaults to File.dirname(File.expand_path($0))) — if a file isn’t in that root, you get the full path, not ‘../../../../../../foo/bar/baz’ :p
There’s per-app settings for where output goes, what levels are logged, and what levels get backtraces — but you can also change this per-instance, and it’ll stick that way even if the global is changed later.
You can also change the defaults via environment variables:
-
MYSTUFF_LOGLEVEL
-
MYSTUFF_BTLEVEL
A couple of examples:
-
The priority colorization is a filter
-
There’s also a filter shipped (but not enabled by default) for use with MyStuff::MultiDB, which turns ‘Foo::MYSTUFF_MULTIDB_DB_aloadofhex::Bar’ into ‘Foo::<localhost:3307/test>::Bar’
These filters are only enabled for log viewing; they don’t affect what’s written to disk.
By default, colors are enabled if the output device (STDOUT usually) is a TTY, but disabled otherwised — of course, this can be overidden.
-
The number in the second field is a unix timestamp
-
The filename is always in the same place, in the same format, making it easier to use with grep, or something more in-depth.
-
a ‘msl-cat’ command, applying the filters
-
a ‘msl-tail’ command, emulating/wrapping ‘tail -F’