lib/logging/logger.rb in logging-0.1.0 vs lib/logging/logger.rb in logging-0.2.0
- old
+ new
@@ -1,8 +1,8 @@
-# $Id: logger.rb 15 2007-01-15 19:03:45Z tim_pease $
+# $Id: logger.rb 22 2007-01-29 16:20:54Z tim_pease $
-require 'sync'
+require 'thread'
require 'logging'
require 'logging/appender'
require 'logging/log_event'
require 'logging/repository'
@@ -31,14 +31,13 @@
# ...
# log.fatal 'unknown exception', exception
#
class Logger
- @mutex = Sync.new # :nodoc:
+ @mutex = Mutex.new # :nodoc:
class << self
-
#
# call-seq:
# Logger.root
#
# Returns the root logger.
@@ -57,11 +56,11 @@
return super if args.empty?
repo = ::Logging::Repository.instance
name = repo.to_key(args.shift)
- @mutex.synchronize(:EX) do
+ @mutex.synchronize do
logger = repo[name]
if logger.nil?
logger = super(name, *args)
repo[name] = logger
end
@@ -119,12 +118,11 @@
end
# :startdoc:
end # class << self
- attr_reader :level, :name, :parent
- attr_accessor :additive, :trace
+ attr_reader :level, :name, :parent, :additive, :trace
#
# call-seq:
# Logger.new( name )
# Logger[name]
@@ -188,9 +186,41 @@
# passed up the logger tree if this logger's additivity is +true+.
#
def <<( msg )
@appenders.each {|a| a << msg}
@parent << msg if @additive
+ end
+
+ #
+ # call-seq:
+ # additive = true
+ #
+ # Sets the additivity of the logger. Acceptable values are +true+,
+ # 'true', +false+, 'false', or +nil+. In this case +nil+ does not
+ # change the additivity
+ #
+ def additive=( val )
+ @additive = case val
+ when true, 'true': true
+ when false, 'false': false
+ when nil: @additive
+ else raise ArgumentError, 'expecting a boolean' end
+ end
+
+ #
+ # call-seq:
+ # trace = true
+ #
+ # Sets the tracing of the logger. Acceptable values are +true+,
+ # 'true', +false+, 'false', or +nil+. In this case +nil+ does not
+ # change the tracing.
+ #
+ def trace=( val )
+ @trace = case val
+ when true, 'true': true
+ when false, 'false': false
+ when nil: @trace
+ else raise ArgumentError, 'expecting a boolean' end
end
#
# call-seq:
# level = :all