[#11073] segfault printing instruction sequence for iterator — <noreply@...>

Bugs item #10527, was opened at 2007-05-02 14:42

14 messages 2007/05/02
[#11142] Re: [ ruby-Bugs-10527 ] segfault printing instruction sequence for iterator — Nobuyoshi Nakada <nobu@...> 2007/05/10

Hi,

[#11188] Re: [ ruby-Bugs-10527 ] segfault printing instruction sequence for iterator — Paul Brannan <pbrannan@...> 2007/05/16

On Thu, May 10, 2007 at 04:51:18PM +0900, Nobuyoshi Nakada wrote:

[#11234] Planning to release 1.8.6 errata — Urabe Shyouhei <shyouhei@...>

Hi all.

17 messages 2007/05/25

Logger::Application accessor for logger

From: Brian Candler <B.Candler@...>
Date: 2007-05-10 09:02:23 UTC
List: ruby-core #11143
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.

In This Thread

Prev Next