Global logger #18

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@Maxim-Filimonov

Added ability to register a global logger.
So that shared logger can be used across multiple classes which include Loggeable
Convention based - to register global logger use the same interface as named one but specify :global as name

Coverage Status

Coverage remained the same when pulling e73a68f on zombees:global-logger into 9212b5e on rudionrails:master.

Coverage Status

Coverage remained the same when pulling e73a68f on zombees:global-logger into 9212b5e on rudionrails:master.

Owner

You can already do this without having to implement a :global logger.

# Define logger
Yell.new :stdout, name: Object

# Define new class with loggable module
class Foo
  include Yell::Loggable
end

# Access logger
Foo.logger.info "Hello World"

Since the above only defines Foo to have an accessable logger, you may even do something like this (though I wouldnot recommend it)

Yell.new :stdout, name: Object
Object.send :include, Yell::Loggable

logger.info "Hello from anywhere"

Ah right, maybe it's worth to add a comment to documentation. It's really not obvious.

Owner

Yes I agree. I have some wiki pages about that (me think). We should definitely update those and add some lines to the README.md.

Will do later - tomorrow in Aus :)

Rudolf Schmidt wrote:

Yes I agree. I have some wiki pages about that (me think). We should
definitely update those and add some lines to the README.md.


Reply to this email directly or view it on GitHub
#18 (comment).

Owner

Great thank you!

Owner

I've added some documentation in the README.md about defining a global logger. Would that be an explanation fitting your needs? It would be great to receive feedback since I am looking at the problem from a different angle.

Sorry for dropping it, Rudolf. Too busy at work these days :( Prelaunch period, you know. I checked out the README. For our case it would be more clear if you define logger for object and then include this logger into two different classes Bar and Foo. That way it acts more as global logger on specific classes instead of logger on object which might lead to some conflicts especially in Rails.

Cheers Maxim

On Thu, Jun 20, 2013 at 9:08 PM, Rudolf Schmidt notifications@github.com
wrote:

I've added some documentation in the README.md about defining a global logger. Would that be an explanation fitting your needs? It would be great to receive feedback since I am looking at the problem from a different angle.

Reply to this email directly or view it on GitHub:
#18 (comment)

Owner

Hey no sweat :-) If you could provide me with an example on how a DSL could look for your case, that would be great.

Ok so I mean replace

# Enable logging for the class that (almost) every Ruby class inherits from
Object.send :include, Yell::Loggable in README

With

class Foo
  Include Yell::Loggable
end
class Bar
  include Yell::Loggable
end
Foo.logger.info
Bar.new.logger.info

Sorry for not making a proper pull request it's a bit hard from mobile

@rudionrails rudionrails closed this Feb 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment