Class: SemanticLogger::Logger
- Defined in:
- lib/semantic_logger/logger.rb
Constant Summary collapse
- @@lag_check_interval =
5000
- @@lag_threshold_s =
30
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.appenders ⇒ Object
Add or remove logging appenders to the thread-safe appenders Array Appenders will be written to in the order that they appear in this list.
-
.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.
-
.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) ⇒ Logger
constructor
Returns a Logger instance.
Methods inherited from Base
default_level, default_level=, #payload, #tags, #with_payload, #with_tags
Constructor Details
#initialize(klass, level = 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::Logger.default_level
58 59 60 61 |
# File 'lib/semantic_logger/logger.rb', line 58 def initialize(klass, level=nil) @name = klass.is_a?(String) ? klass : klass.name self.level = level || self.class.default_level end |
Class Method Details
.appenders ⇒ Object
Add or remove logging appenders to the thread-safe appenders Array Appenders will be written to in the order that they appear in this list
38 39 40 |
# File 'lib/semantic_logger/logger.rb', line 38 def self.appenders @@appenders end |
.cache_count ⇒ Object
DEPRECATED: Please use queue_size instead.
75 76 77 78 |
# File 'lib/semantic_logger/logger.rb', line 75 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
82 83 84 85 86 87 88 89 |
# File 'lib/semantic_logger/logger.rb', line 82 def self.flush return false unless appender_thread_active? logger.debug "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
96 97 98 |
# File 'lib/semantic_logger/logger.rb', line 96 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
102 103 104 |
# File 'lib/semantic_logger/logger.rb', line 102 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
108 109 110 |
# File 'lib/semantic_logger/logger.rb', line 108 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
120 121 122 |
# File 'lib/semantic_logger/logger.rb', line 120 def self.logger=(logger) @@logger = logger 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
70 71 72 |
# File 'lib/semantic_logger/logger.rb', line 70 def self.queue_size queue.size end |
.time_threshold_s=(time_threshold_s) ⇒ Object
112 113 114 |
# File 'lib/semantic_logger/logger.rb', line 112 def self.time_threshold_s=(time_threshold_s) @@lag_threshold_s = time_threshold_s end |