class SemanticLogger::Logger
log message written by this instance will include the class name
Logger stores the class name to be used for all log messages so that every
def self.call_subscribers(log)
def self.call_subscribers(log) return unless @subscribers @subscribers.each do |subscriber| subscriber.call(log) rescue Exception => e processor.logger.error("Exception calling :on_log subscriber", e) end end
def self.processor
def self.processor @processor ||= Processor.new end
def self.subscribe(object = nil, &block)
def self.subscribe(object = nil, &block) subscriber = block || object unless subscriber.is_a?(Proc) || subscriber.respond_to?(:call) raise("When supplying an on_log subscriber, it must support the #call method") end subscribers = (@subscribers ||= Concurrent::Array.new) subscribers << subscriber unless subscribers.include?(subscriber) end
def self.sync!
def self.sync! return if @processor.is_a?(SyncProcessor) @processor = SyncProcessor.new(@processor&.appenders) end
def self.sync?
def self.sync? processor.is_a?(SyncProcessor) end
def initialize(klass, level = nil, filter = nil)
Proc: Only include log messages where the supplied Proc returns true
regular expression. All other messages will be ignored
RegExp: Only include log messages where the class name matches the supplied
filter [Regexp|Proc]
Default: SemanticLogger.default_level
The initial log level to start with for this logger instance
level
to be used in the logger
A class, module or a string with the application/class name
klass
Parameters:
logger = SemanticLogger::Logger.new('MyClass')
OR
logger = SemanticLogger::Logger.new(self)
Return the logger for a specific class, supports class specific log levels
Returns a Logger instance
def initialize(klass, level = nil, filter = nil) super end
def log(log, message = nil, progname = nil, &block)
Subscribers are called inline before handing off to the queue so that
appender in the order that they were registered
Place log request on the queue for the Appender thread to write to each
def log(log, message = nil, progname = nil, &block) # Compatibility with ::Logger return add(log, message, progname, &block) unless log.is_a?(SemanticLogger::Log) Logger.call_subscribers(log) Logger.processor.log(log) end