From: Tim Pease Date: 2011-10-26T01:28:12+09:00 Subject: Re: Add logger to module/class On Oct 25, 2011, at 9:34 AM, Kassym Dorsel wrote: > I want a dual logger so I have sub-classed Logger with this : > class Logging < Logger > def initialize(file, stdout=false) > @log_file = Logger(file) > @log_out = Logger(stdout) if stdout > end > #Override the logger's methods to write to both stdout and file if > needed > end > Take a look at the "Logging" gem as it already support logging to multiple destinations. The interface for logger objects is the same as the core Ruby logger class. docos => http://rubydoc.info/gems/logging/frames source => https://github.com/TwP/logging > How would I implement a global logger for the module and the main. The > logger would be initiated within the main and I'd want to pass it to the > module with the same parameters, given a module like this : > One trick you can use with the Logging framework is this require 'logging' include Logging.globally This will add a "logger" method to Object which will be inherited by every object in your application. This will allow you to do call "logger.info" within your module or any other class. Blessings, TwP