lib/semantic_logger/logger.rb in semantic_logger-0.4.2 vs lib/semantic_logger/logger.rb in semantic_logger-0.5.0

- old
+ new

@@ -27,10 +27,11 @@ # ) # ... # # This will be logged to both the Ruby Logger and MongoDB # logger.debug("Login time", :user => 'Mary', :duration => 230, :ip_address=>'192.168.0.1') # +require 'logger' module SemanticLogger class Logger include SyncAttr # Logging levels in order of precedence @@ -45,22 +46,25 @@ # Thread safe Class Attribute accessor for appenders array sync_cattr_accessor :appenders do [] end - # Allow for setting the default log level - def self.default_level=(default_level) - @@default_level = default_level + # Allow for setting the global default log level + # This change only applies to _new_ loggers, existing logger levels + # will not be changed in any way + def self.level=(level) + @@level = level end - def self.default_level - @@default_level + # Returns the global default log level for new Logger instances + def self.level + @@level end attr_reader :name, :level - @@default_level = :info + @@level = :info # Returns a Logger instance # # Return the logger for a specific class, supports class specific log levels # logger = SemanticLogger::Logger.new(self) @@ -72,11 +76,11 @@ # to be used in the logger # options: # :level The initial log level to start with for this logger instance def initialize(klass, options={}) @name = klass.is_a?(String) ? klass : klass.name - set_level(options[:level] || self.class.default_level) + set_level(options[:level] || self.class.level) end # Set the logging level # Must be one of the values in #LEVELS def level=(level) @@ -237,11 +241,10 @@ # logger, but never to SemanticLogger itself # # Warning: Do not use this logger directly it is intended for internal logging # within Semantic Logger itself sync_cattr_accessor :logger do - require 'logger' - l = ::Logger.new(STDOUT) + l = ::Logger.new(STDERR) l.level = ::Logger::INFO l end ############################################################################