Skip to content
forked from wr0ngway/lumber

Lumber tries to make it easy to use the more robust log4r logging system within your rails application

License

Notifications You must be signed in to change notification settings

backupify/lumber

 
 

Repository files navigation

lumber

Lumber tries to make it easy to use the more robust log4r logging system within your rails application. To do this it sets up log4r configuration from a yml file, and provides utility methods for adding a :logger accessor to classes dynamically as they get created. In the default setup shown below, calls to logger from a model/controller/mailer, will include that classes name in the log output.

To use it, first “gem install lumber”, run the lumber generator (./script generate lumber) to get the log4r.yml config file, then make the following edits to config/environment.rb:

# before Rails::Initializer.run
#
require 'lumber'
Lumber.init()

# Setup parent loggers for some known rails Base classes.  Classes that inherit
# from these will have their logger as a parent so you can configure logging for
# subtrees of classes in log4r.yml
Lumber.setup_logger_hierarchy("ActiveRecord::Base", "rails::models")
Lumber.setup_logger_hierarchy("ActionController::Base", "rails::controllers")
Lumber.setup_logger_hierarchy("ActionMailer::Base", "rails::mailers")

# If you really want, you can make all classes have a logger
# Lumber.setup_logger_hierarchy("Object", "root::object")

Additionally, you can also add loggers to individual classes by including the LumberLoggerSupport module

class Foo
  include Lumber::LoggerSupport
end

and Foo.logger/Foo.new.logger will log to a logger named “rails::Foo”. This creates a heirarchy of loggers for classes nested within modules, so you can use the namespace to enable/disable loggers

If you want to change the log level for a different environment, add a line like below to the config/environments/<env>.rb

# Set info as the default log level for production
Log4r::Logger.root.level = Log4r::INFO

You should be able to use lumber in a non-rails project too, but your call to Lumber.init will need to be different. I don’t currently need to do this, so let me know if you have any problems.

Copyright © 2009 Matt Conway. See LICENSE for details.

About

Lumber tries to make it easy to use the more robust log4r logging system within your rails application

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%