lib/loggability/override.rb in loggability-0.8.0 vs lib/loggability/override.rb in loggability-0.8.1
- old
+ new
@@ -17,25 +17,31 @@
#
class Loggability::Override
include MonitorMixin
- ### Return an Override with its logging level set to +newlevel+.
- def self::with_level( new_level )
- return self.new( level: new_level )
+ ### Set up an Override with its logging level set to +newlevel+. If called with
+ ### a block, call #call immediately on the Override with the block and return
+ ### the result of that instead.
+ def self::with_level( new_level, &block )
+ return self.new( level: new_level, &block )
end
- ### Return an Override with its logging output set to +new_destination+.
- def self::outputting_to( new_destination )
- return self.new( logdev: new_destination )
+ ### Set up an Override with its logging output set to +new_destination+. If called with
+ ### a block, call #call immediately on the Override with the block and return
+ ### the result of that instead.
+ def self::outputting_to( new_destination, &block )
+ return self.new( logdev: new_destination, &block )
end
- ### Return an Override with its logging formatter set to +formatter+.
- def self::formatted_with( new_formatter )
- return self.new( formatter: new_formatter )
+ ### Set up an Override with its logging formatter set to +formatter+. If called with
+ ### a block, call #call immediately on the Override with the block and return
+ ### the result of that instead.
+ def self::formatted_with( new_formatter, &block )
+ return self.new( formatter: new_formatter, &block )
end
### Create a new Override with the specified +settings+ that will be applied
### during a call to #call, and then reverted when #call returns. Valid +settings+
@@ -91,26 +97,26 @@
# Mutator Methods
#
### Return a clone of the receiving Override with its logging level
### set to +newlevel+.
- def with_level( new_level )
- return self.clone_with( level: new_level )
+ def with_level( new_level, &block )
+ return self.clone_with( level: new_level, &block )
end
### Return a clone of the receiving Override with its logging output
### set to +new_destination+.
- def outputting_to( new_destination )
- return self.clone_with( logdev: new_destination )
+ def outputting_to( new_destination, &block )
+ return self.clone_with( logdev: new_destination, &block )
end
### Return a clone of the receiving Override with its logging formatter
### set to +formatter+.
- def formatted_with( new_formatter )
- return self.clone_with( formatter: new_formatter )
+ def formatted_with( new_formatter, &block )
+ return self.clone_with( formatter: new_formatter, &block )
end
### Return the object as a human-readable string suitable for debugging.
def inspect
@@ -127,14 +133,18 @@
#########
protected
#########
### Return a clone that has been modified with the specified +new_settings+.
- def clone_with( new_settings )
+ def clone_with( new_settings, &block )
newobj = self.dup
newobj.settings.merge!( new_settings )
- return newobj
+ if block
+ return newobj.call( &block )
+ else
+ return newobj
+ end
end
### Apply any configured overrides to all loggers.
def apply_overrides
\ No newline at end of file