If a tree falls in a forest and no one is around to hear it, does it make a sound?
Treefell is a minimalist debug-logging library for ruby. It uses the DEBUG environment variable to determine which debug messages are logged and which are suppressed.
This project was inspired by visionmedia's debug library for nodejs.
Installation
Add this line to your application's Gemfile:
gem 'treefell'
And then execute:
$ bundle
Or install it yourself as:
$ gem install treefell
Usage
Take the ruby program:
#!/usr/bin/env ruby
require 'treefell'
foo_debug = Treefell['foo']
foo_debug.puts 'too funky in here'
bar_debug = Treefell['bar']
bar_debug.puts 'you got that right'
baz_debug = Treefell['baz']
baz_debug.puts 'say it again'
Each call to Treefell['...']
instantiates a DebugLogger
for the provided
namespace (e.g. foo, bar, baz).
By default no debug log statements are displayed:
> ruby program.rb
Displaying all messages
You can tell it to display all messages with the wildcard *
:
Displaying messages from a particular namespace
Here's how to display messages for one specific debugging namespace:
Displaying messages for multiple namespaces
To display messages from multiple namespaces use a comma-separated list of namespaces:
Colored output
Every namespace gets a color associated with it to aide in the visual parsing
of the output. Also DebugLogger
(s) are cached per namespace so regardless
of when you refer to the namespace it will always have the same color
associated with it.
E.g.
foo_debug = Treefell['foo']
other_foo_debug = Treefell['foo']
foo_debug.eql?(other_foo_debug) # => true
Sending to IO other than STDOUT
By default all messages are written to STDOUT
. You can change this by
instantiating a debug logger using the debug
method, e.g.:
foo_debug = Treefell.debug('foo', io: some_io)
foo_debug.puts 'Get up offa that thing, and dance till you feel better'
Contributing
- Fork it ( https://github.com/zdennis/treefell/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request