Class: SemanticLogger::Logger
- Includes:
- SyncAttr
- 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
-
.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.
-
.queue_size ⇒ Object
Returns [Integer] the number of log entries that have not been written to the appenders.
-
.started? ⇒ Boolean
Returns whether the logging thread has been started.
- .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
62 63 64 65 |
# File 'lib/semantic_logger/logger.rb', line 62 def initialize(klass, level=nil) @name = klass.is_a?(String) ? klass : klass.name self.level = level || self.class.default_level end |
Class Method Details
.cache_count ⇒ Object
DEPRECATED: Please use queue_size instead.
79 80 81 82 |
# File 'lib/semantic_logger/logger.rb', line 79 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
86 87 88 89 90 91 92 93 |
# File 'lib/semantic_logger/logger.rb', line 86 def self.flush return false unless started? && @@appender_thread && @@appender_thread.alive? logger.debug "SemanticLogger::Logger 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
100 101 102 |
# File 'lib/semantic_logger/logger.rb', line 100 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
106 107 108 |
# File 'lib/semantic_logger/logger.rb', line 106 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
112 113 114 |
# File 'lib/semantic_logger/logger.rb', line 112 def self.lag_threshold_s @@lag_threshold_s 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
74 75 76 |
# File 'lib/semantic_logger/logger.rb', line 74 def self.queue_size queue.size end |
.started? ⇒ Boolean
Returns whether the logging thread has been started
121 122 123 |
# File 'lib/semantic_logger/logger.rb', line 121 def self.started? defined? :@@appenders end |
.time_threshold_s=(time_threshold_s) ⇒ Object
116 117 118 |
# File 'lib/semantic_logger/logger.rb', line 116 def self.time_threshold_s=(time_threshold_s) @@lag_threshold_s = time_threshold_s end |