Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Loggers every which way #7

wants to merge 3 commits into from

2 participants


Just my take on Yell::Loggable.



I am not so very fond of implicit stuff that gets added to any arbitrary class, actually. Especially not overloading the Kernel class :-S

You can already achieve what you are suggesting by doing the following:

# include loggable into object
class Object
  include Yell::Loggable


# define the logger :stdout, :name => 'Object'

# define any class and log away :-)
class Foo; end :info

I still prefer that the user makes an own choice when adding a logger method to any class. It is, of course, a bit more code, but people understand what happend when reading it - that's my guess ;-)

What do you think?


Yeah, I guess that makes sense :)

@rauchy rauchy closed this

I did not mean to put your idea down. I've been experimenting to have something like this: :stdout, :name => :root

Only thing is: I rather not magically have the Object class get a logger method. Also, doing something like a root logger would, again that's my guess, have some people assuming that there always is one. Yell has many different adapters (stdout, stderr, file-based, graylog2, syslog) and which would the default be? Also, I always like to have a real use-case for this as I do not want features added that people may never use.

If people want things like a root logger, I am of course going to accept a pull :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 5 deletions.
  1. +12 −1
  2. +18 −4 lib/yell/logger.rb
  3. +10 −0 spec/yell/logger_spec.rb
@@ -109,7 +109,18 @@ you global namespace with Yell's subclasses.
### You want any class to have a logger?
-Yell comes with a simple module: +Yell::Loggable+. Simply include this in a class and
+Yell provides a general logger that can be accessed *everywhere*. Just
+use the :everywhere option when initializing it:
+```ruby :stdout, :everywhere => true
+some_instance = "Hello World"
+If you prefer to be more picky and have it only in some objects instead
+of everywhere, Yell comes with a simple module: +Yell::Loggable+. Simply include this in a class and
you are good to go.
22 lib/yell/logger.rb
@@ -51,8 +51,13 @@ def initialize( *args, &block )
# set the log level when given
self.level = @options[:level]
- # set the loggeer's name
- = @options[:name] if @options[:name]
+ # include this logger to any object if 'everywhere' is defined
+ if !!@options[:everywhere]
+ include_everywhere!
+ elsif @options[:name]
+ # set the logger's name
+ = @options[:name]
+ end
# extract adapter
self.adapter args.pop if args.any?
@@ -82,9 +87,9 @@ def initialize( *args, &block )
# adapter( )
# @param [Symbol] type The type of the adapter, may be `:file` or `:datefile` (default `:file`)
- #
# @return [Yell::Adapter] The instance
+ #
# @raise [Yell::NoSuchAdapter] Will be thrown when the adapter is not defined
def adapter( type = :file, *args, &block )
options = [@options, *args].inject( ) do |h, c|
@@ -111,8 +116,8 @@ def level( val = nil )
@level = val )
- end
+ end
# Convenience method for resetting all adapters of the Logger.
def close
@@ -178,6 +183,15 @@ def write( event )
@adapters.each { |a| a.write(event) }
+ def include_everywhere!
+ = 'General'
+ Kernel.module_eval do
+ def logger
+ Yell['General']
+ end
+ end
+ end
10 spec/yell/logger_spec.rb
@@ -57,6 +57,16 @@ def bar
+ context "initialize with :everywhere" do
+ let(:object) { }
+ it "should be available from any object" do
+ logger = :everywhere => true
+ object.should respond_to(:logger)
+ object.logger.should == logger
+ end
+ end
context "initialize with a :filename" do
it "should call adapter with :file" do
mock.proxy( Yell::Adapters::File ).new( :filename => 'test.log' )
Something went wrong with that request. Please try again.