Class: SemanticLogger::Logger
- 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
Constant Summary collapse
- @@lag_check_interval =
5000- @@lag_threshold_s =
30
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.appenders ⇒ Object
DEPRECATED See SemanticLogger.add_appender.
-
.cache_count ⇒ Object
DEPRECATED: Please use queue_size instead.
-
.flush ⇒ Object
Flush all queued log entries disk, database, etc.
-
.lag_check_interval ⇒ Object
Returns the check_interval which is the number of messages between checks to determine if the appender thread is falling behind.
-
.lag_check_interval=(lag_check_interval) ⇒ Object
Set the check_interval which is the number of messages between checks to determine if the appender thread is falling behind.
-
.lag_threshold_s ⇒ Object
Returns the amount of time in seconds to determine if the appender thread is falling behind.
-
.logger=(logger) ⇒ Object
Allow the internal logger to be overridden from its default to STDERR Can be replaced with another Ruby logger or Rails logger, but never to SemanticLogger::Logger itself since it is for reporting problems while trying to log to the various appenders.
-
.on_metric(&block) ⇒ Object
Supply a block to be called whenever a metric is seen during benchmark logging.
-
.queue_size ⇒ Object
Returns [Integer] the number of log entries that have not been written to the appenders.
- .time_threshold_s=(time_threshold_s) ⇒ Object
Instance Method Summary collapse
-
#initialize(klass, level = nil, filter = nil) ⇒ Logger
constructor
Returns a Logger instance.
Methods inherited from Base
#benchmark, default_level, default_level=, #fast_tag, #level, #level=, #payload, #pop_tags, #push_tags, #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:
application
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
27 28 29 |
# File 'lib/semantic_logger/logger.rb', line 27 def initialize(klass, level=nil, filter=nil) super end |
Class Method Details
.appenders ⇒ Object
DEPRECATED See SemanticLogger.add_appender
87 88 89 90 |
# File 'lib/semantic_logger/logger.rb', line 87 def self.appenders warn '[DEPRECATION] SemanticLogger::Logger.appenders is deprecated. Please use SemanticLogger.add_appender instead.' SemanticLogger.appenders end |
.cache_count ⇒ Object
DEPRECATED: Please use queue_size instead.
93 94 95 96 |
# File 'lib/semantic_logger/logger.rb', line 93 def self.cache_count warn '[DEPRECATION] SemanticLogger::Logger.cache_count is deprecated. Please use SemanticLogger::Logger.queue_size instead.' queue_size end |
.flush ⇒ Object
Flush all queued log entries disk, database, etc.
All queued log messages are written and then each appender is flushed in turn
44 45 46 47 48 49 50 51 |
# File 'lib/semantic_logger/logger.rb', line 44 def self.flush return false unless appender_thread_active? logger.trace "Flushing appenders with #{queue_size} log messages on the queue" reply_queue = Queue.new queue << {command: :flush, reply_queue: reply_queue} reply_queue.pop end |
.lag_check_interval ⇒ Object
Returns the check_interval which is the number of messages between checks to determine if the appender thread is falling behind
58 59 60 |
# File 'lib/semantic_logger/logger.rb', line 58 def self.lag_check_interval @@lag_check_interval end |
.lag_check_interval=(lag_check_interval) ⇒ Object
Set the check_interval which is the number of messages between checks to determine if the appender thread is falling behind
64 65 66 |
# File 'lib/semantic_logger/logger.rb', line 64 def self.lag_check_interval=(lag_check_interval) @@lag_check_interval = lag_check_interval end |
.lag_threshold_s ⇒ Object
Returns the amount of time in seconds to determine if the appender thread is falling behind
70 71 72 |
# File 'lib/semantic_logger/logger.rb', line 70 def self.lag_threshold_s @@lag_threshold_s end |
.logger=(logger) ⇒ Object
Allow the internal logger to be overridden from its default to STDERR
Can be replaced with another Ruby logger or Rails logger, but never to
SemanticLogger::Logger itself since it is for reporting problems
while trying to log to the various appenders
82 83 84 |
# File 'lib/semantic_logger/logger.rb', line 82 def self.logger=(logger) @@logger = logger end |
.on_metric(&block) ⇒ Object
Supply a block to be called whenever a metric is seen during benchmark logging
Parameters
block
The block to be called
Example:
SemanticLogger.on_metric do |log_struct|
puts "#{log_struct.metric} was received. Log Struct: #{log_struct.inspect}"
end
108 109 110 |
# File 'lib/semantic_logger/logger.rb', line 108 def self.on_metric(&block) (@@metric_subscribers ||= Concurrent::Array.new) << block end |
.queue_size ⇒ Object
Returns [Integer] the number of log entries that have not been written to the appenders
When this number grows it is because the logging appender thread is not able to write to the appenders fast enough. Either reduce the amount of logging, increase the log level, reduce the number of appenders, or look into speeding up the appenders themselves
38 39 40 |
# File 'lib/semantic_logger/logger.rb', line 38 def self.queue_size queue.size end |
.time_threshold_s=(time_threshold_s) ⇒ Object
74 75 76 |
# File 'lib/semantic_logger/logger.rb', line 74 def self.time_threshold_s=(time_threshold_s) @@lag_threshold_s = time_threshold_s end |