From: Brian Candler Date: 2007-05-10T18:02:23+09:00 Subject: Logger::Application accessor for logger http://svn.ruby-lang.org/repos/ruby/trunk/lib/logger.rb I have come across some strangeness in Logger::Application. (1) attr_reader :logdev is declared - but @logdev is never initialised. (2) the actual logger is @log, but is not exposed via an accessor. This means that: (a) if you wish to change the format of logging from outside the app, it gets messy: worker = MyApp.new # subclass of Logger::Application worker.log = "/tmp/worker.log" # this is fine worker.level = Logger::INFO # so is this worker.instance_variable_get(:@log).formatter = Logger::Formatter.new # Ugh! This is a useful pattern when using dependency injection to prepare the application. (b) if you wish to use the "logger.info" syntax within your application, then you have to refer to the instance variable, i.e. @log.info "hello" or else define your own accessor, e.g. def logger; @log; end ... logger.info "hello" (c) if a Logger::Application wishes to pass its logger to another object, it has to refer to @log explicitly rather than using an accessor (which seems a little fragile) I expect this is unintentional, and perhaps the attr_reader :logdev was intended to expose the underlying logger object - or maybe the LogDevice object it contains. But either way, it always returns nil at present. I'm not sure of the best way to improve this. At minimum, the useless attr_reader :logdev can be removed. Maybe def logger @log end is the easiest solution (unfortunately you can't make attr_reader :log because method 'log' has been used to call @log.add). Regards, Brian.