Created
August 15, 2011 09:28
-
-
Save mindscratch/1145954 to your computer and use it in GitHub Desktop.
log4r mixin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Logging | |
# Get an instance to a logger configured for the class that includes it. | |
# This allows log messages to include the class name | |
def logger | |
return @logger if @logger | |
formatter = Log4r::PatternFormatter.new(:pattern => '[%d] %l %C: %M') | |
@logger = Log4r::Logger.new(self.class.name) | |
@logger.outputters << Log4r::StdoutOutputter.new("console", {:formatter => formatter}) | |
@logger.outputters << Log4r::FileOutputter.new("file", {:filename => 'myapp.log', :formatter => formatter}) | |
@logger | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment