Class: GrayLogger::Logger
- Inherits:
-
GELF::Logger
- Object
- GELF::Logger
- GrayLogger::Logger
- Includes:
- Support
- Defined in:
- lib/gray_logger/logger.rb
Instance Attribute Summary collapse
-
#buckets ⇒ Object
readonly
Returns the value of attribute buckets.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#after_request_log ⇒ Object
logger.after_request_log << => ‘field content’ logger.after_request_log.my_field = ‘field content’.
- #automatic_logging? ⇒ Boolean
-
#bucket(name) ⇒ Object
logger.bucket(:my_bucket) << => ‘field content’ logger.bucket(:my_bucket).my_field = ‘field content’.
-
#flush ⇒ Object
flush all buckets.
-
#flush_bucket(name) ⇒ Object
flush a specific bucket.
-
#initialize(configuration) ⇒ Logger
constructor
A new instance of Logger.
- #log_exception(exception) ⇒ Object
- #reset! ⇒ Object
Methods included from Support
Constructor Details
#initialize(configuration) ⇒ Logger
Returns a new instance of Logger.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gray_logger/logger.rb', line 10 def initialize(configuration) if configuration.valid? super(configuration.host, configuration.port, configuration.size, configuration.) @configuration = configuration else self.disable # from GELF end @buckets = {} end |
Instance Attribute Details
#buckets ⇒ Object (readonly)
Returns the value of attribute buckets.
8 9 10 |
# File 'lib/gray_logger/logger.rb', line 8 def buckets @buckets end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
8 9 10 |
# File 'lib/gray_logger/logger.rb', line 8 def configuration @configuration end |
Instance Method Details
#after_request_log ⇒ Object
logger.after_request_log << => ‘field content’ logger.after_request_log.my_field = ‘field content’
32 33 34 |
# File 'lib/gray_logger/logger.rb', line 32 def after_request_log bucket(:_request) end |
#automatic_logging? ⇒ Boolean
26 27 28 |
# File 'lib/gray_logger/logger.rb', line 26 def automatic_logging? configuration.automatic_logging? end |
#bucket(name) ⇒ Object
logger.bucket(:my_bucket) << => ‘field content’ logger.bucket(:my_bucket).my_field = ‘field content’
38 39 40 |
# File 'lib/gray_logger/logger.rb', line 38 def bucket(name) @buckets[name.to_sym] ||= GrayLogger::Bucket.new end |
#flush ⇒ Object
flush all buckets
43 44 45 46 47 48 |
# File 'lib/gray_logger/logger.rb', line 43 def flush @buckets.keys.each do |bucket_name| flush_bucket(bucket_name) end reset! end |
#flush_bucket(name) ⇒ Object
flush a specific bucket
51 52 53 54 55 56 |
# File 'lib/gray_logger/logger.rb', line 51 def flush_bucket(name) return false if get_bucket(name).nil? = get_bucket(name).(name) self.notify!() @buckets.delete(name.to_sym) end |
#log_exception(exception) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/gray_logger/logger.rb', line 58 def log_exception(exception) if exception after_request_log. = "Error: #{exception}" after_request_log.exception_backtrace = exception.backtrace.join("\n") end end |
#reset! ⇒ Object
21 22 23 24 |
# File 'lib/gray_logger/logger.rb', line 21 def reset! @buckets = {} self end |