class SemanticLogger::Logger
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
Attributes
subscribers[R]
Public Class Methods
call_subscribers(log)
click to toggle source
# File lib/semantic_logger/logger.rb, line 81 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
new(klass, level = nil, filter = nil)
click to toggle source
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
Calls superclass method
# File lib/semantic_logger/logger.rb, line 60 def initialize(klass, level = nil, filter = nil) super(klass, level, filter) end
processor()
click to toggle source
# File lib/semantic_logger/logger.rb, line 23 def self.processor @processor ||= Processor.new end
subscribe(object = nil, &block)
click to toggle source
# File lib/semantic_logger/logger.rb, line 8 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
sync!()
click to toggle source
Switch to the synchronous processor
# File lib/semantic_logger/logger.rb, line 28 def self.sync! return if @processor.is_a?(SyncProcessor) @processor = SyncProcessor.new(@processor&.appenders) end
sync?()
click to toggle source
Running without the background logging thread?
# File lib/semantic_logger/logger.rb, line 35 def self.sync? processor.is_a?(SyncProcessor) end
Public Instance Methods
log(log, message = nil, progname = nil, &block)
click to toggle source
Place log request on the queue for the Appender
thread to write to each appender in the order that they were registered
Subscribers are called inline before handing off to the queue so that they can capture additional context information as needed.
# File lib/semantic_logger/logger.rb, line 69 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