class SemanticLogger::Subscriber
Attributes
Every appender has its own formatter
Public Class Methods
Initializer for Abstract Class SemanticLogger::Subscriber
Parameters
level: [:trace | :debug | :info | :warn | :error | :fatal] Override the log level for this subscriber. formatter: [Object|Proc] An instance of a class that implements #call, or a Proc to be used to format the output from this subscriber Default: Use the built-in formatter (See: #call) 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. application: [String] Name of this application to appear in log messages. Default: SemanticLogger.application host: [String] Name of this host to appear in log messages. Default: SemanticLogger.host metrics: [Boolean] Whether to log metric only entries with this subscriber. Default: false
# File lib/semantic_logger/subscriber.rb, line 101 def initialize(level: nil, formatter: nil, filter: nil, application: nil, environment: nil, host: nil, metrics: false, &block) self.formatter = block || formatter @application = application @environment = environment @host = host @metrics = metrics # Subscribers don't take a class name, so use this class name if a subscriber # is logged to directly. super(self.class, level, filter) end
Public Instance Methods
Allow application name to be set globally or on a per subscriber basis.
# File lib/semantic_logger/subscriber.rb, line 31 def application @application || SemanticLogger.application end
A subscriber should implement close if it can.
# File lib/semantic_logger/subscriber.rb, line 21 def close # NOOP end
Returns [SemanticLogger::Formatters::Default] default formatter for this subscriber.
# File lib/semantic_logger/subscriber.rb, line 26 def default_formatter SemanticLogger::Formatters::Default.new end
Allow environment name to be set globally or on a per subscriber basis.
# File lib/semantic_logger/subscriber.rb, line 36 def environment @environment || SemanticLogger.environment end
A subscriber should implement flush if it can.
# File lib/semantic_logger/subscriber.rb, line 16 def flush # NOOP end
Set the formatter from Symbol|Hash|Block
# File lib/semantic_logger/subscriber.rb, line 57 def formatter=(formatter) @formatter = if formatter.nil? respond_to?(:call) ? self : default_formatter else Formatters.factory(formatter) end end
Allow host name to be set globally or on a per subscriber basis.
# File lib/semantic_logger/subscriber.rb, line 41 def host @host || SemanticLogger.host end
Returns the current log level if set, otherwise it logs everything it receives.
# File lib/semantic_logger/subscriber.rb, line 11 def level @level || :trace end
Give each appender its own logger for logging. For example trace messages sent to services or errors when something fails.
# File lib/semantic_logger/subscriber.rb, line 47 def logger @logger ||= begin logger = SemanticLogger::Processor.logger.clone logger.name = self.class.name logger end end
Whether this log entry meets the criteria to be logged by this appender.
# File lib/semantic_logger/subscriber.rb, line 67 def should_log?(log) super(log) && (log.metric_only? ? metrics? : true) end
Private Instance Methods
Return the level index for fast comparisons. Returns the lowest level index if the level has not been explicitly set for this instance.
# File lib/semantic_logger/subscriber.rb, line 116 def level_index @level_index || 0 end
Whether to log metric only entries with this subscriber
# File lib/semantic_logger/subscriber.rb, line 121 def metrics? @metrics end