Class: SemanticLogger::Logger

Inherits:
Base
  • Object
show all
Includes:
Concerns::Compatibility
Defined in:
lib/semantic_logger/logger.rb

Overview

Logger stores the class name to be used for all log messages so that every log message written by this instance will include the class name

Direct Known Subclasses

DebugAsTraceLogger

Instance Attribute Summary

Attributes inherited from Base

#filter, #name

Instance Method Summary collapse

Methods included from Concerns::Compatibility

#add, #close, included, #reopen

Methods inherited from Base

#backtrace, #fast_tag, #level, #level=, #measure, #payload, #pop_tags, #push_tags, #should_log?, #silence, #tagged, #tags, #with_payload

Constructor Details

#initialize(klass, level = nil, filter = nil) ⇒ Logger

Returns a Logger instance

Return the logger for a specific class, supports class specific log levels

logger = SemanticLogger::Logger.new(self)

OR

logger = SemanticLogger::Logger.new('MyClass')

Parameters:

klass
  A class, module or a string with the application/class name
  to be used in the logger

level
  The initial log level to start with for this logger instance
  Default: SemanticLogger.default_level

filter [Regexp|Proc]
  RegExp: Only include log messages where the class name matches the supplied
  regular expression. All other messages will be ignored
  Proc: Only include log messages where the supplied Proc returns true
        The Proc must return true or false


29
30
31
# File 'lib/semantic_logger/logger.rb', line 29

def initialize(klass, level = nil, filter = nil)
  super(klass, level, filter)
end

Instance Method Details

#log(log, message = nil, progname = nil, &block) ⇒ Object

Place log request on the queue for the Appender thread to write to each appender in the order that they were registered



35
36
37
38
39
# File 'lib/semantic_logger/logger.rb', line 35

def log(log, message = nil, progname = nil, &block)
  # Compatibility with ::Logger
  return add(log, message, progname, &block) unless log.is_a?(SemanticLogger::Log)
  Processor << log
end