Class: GoodData::SplunkLoggerDecorator
- Defined in:
- lib/gooddata/core/splunk_logger_decorator.rb
Overview
Logger that process given message to format readable by splunk
Instance Method Summary collapse
-
#add(severity, message = nil, progname = nil) ⇒ Object
If the given message or progname is an instance of Hash, it's reformatted to splunk readable format.
- #hash_to_string(hash) ⇒ Object
-
#initialize(logger = Logger) ⇒ SplunkLoggerDecorator
constructor
A new instance of SplunkLoggerDecorator.
Constructor Details
#initialize(logger = Logger) ⇒ SplunkLoggerDecorator
Returns a new instance of SplunkLoggerDecorator.
10 11 12 |
# File 'lib/gooddata/core/splunk_logger_decorator.rb', line 10 def initialize(logger = Logger) @logger = logger end |
Instance Method Details
#add(severity, message = nil, progname = nil) ⇒ Object
If the given message or progname is an instance of Hash, it's reformatted to splunk readable format. In case that the message or the progname contain new line character log won't be printed out. Otherwise splunk worker wouldn't process it correctly.
21 22 23 24 25 |
# File 'lib/gooddata/core/splunk_logger_decorator.rb', line 21 def add(severity, = nil, progname = nil) = hash_to_string() if .is_a? Hash progname = hash_to_string(progname) if progname.is_a? Hash @logger.add(severity, , progname) unless (progname && progname.chomp == '') || ( && .chomp == '') end |
#hash_to_string(hash) ⇒ Object
14 15 16 |
# File 'lib/gooddata/core/splunk_logger_decorator.rb', line 14 def hash_to_string(hash) hash.map { |pair| " #{pair[0]}=#{pair[1]}" }.join "" end |