Class: LtsvLogger
- Inherits:
-
Object
- Object
- LtsvLogger
- Extended by:
- Forwardable
- Includes:
- Logger::Severity
- Defined in:
- lib/ltsv_logger.rb
Constant Summary collapse
- VERSION =
"0.0.0"
Instance Method Summary collapse
- #add(severity, message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
- #debug(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
- #error(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
- #fatal(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
- #info(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
-
#initialize(*args) ⇒ LtsvLogger
constructor
A new instance of LtsvLogger.
- #warn(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ LtsvLogger
Returns a new instance of LtsvLogger.
12 13 14 |
# File 'lib/ltsv_logger.rb', line 12 def initialize(*args) @logger = Logger.new(*args) end |
Instance Method Details
#add(severity, message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ltsv_logger.rb', line 40 def add(severity, = nil, log_hash = nil, &block) if block_given? array_or_hash = yield if array_or_hash.respond_to?(:to_h) = array_or_hash else # as an Array , log_hash = *array_or_hash end end if .respond_to?(:to_h) output_data = .to_h else output_data = log_hash.to_h.merge(message: ) end severity_string = @logger.send(:format_severity, severity) # call private method! output_data = output_data.merge(time: Time.now.iso8601(6), pid: Process.pid, severity: severity_string) @logger << LTSV.dump(output_data) end |
#debug(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
20 21 22 |
# File 'lib/ltsv_logger.rb', line 20 def debug( = nil, log_hash = nil, &block) add(DEBUG, , log_hash, &block) end |
#error(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
32 33 34 |
# File 'lib/ltsv_logger.rb', line 32 def error( = nil, log_hash = nil, &block) add(ERROR, , log_hash, &block) end |
#fatal(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
36 37 38 |
# File 'lib/ltsv_logger.rb', line 36 def fatal( = nil, log_hash = nil, &block) add(FATAL, , log_hash, &block) end |
#info(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
24 25 26 |
# File 'lib/ltsv_logger.rb', line 24 def info( = nil, log_hash = nil, &block) add(INFO, , log_hash, &block) end |
#warn(message_or_log_hash = nil, log_hash = nil, &block) ⇒ Object
28 29 30 |
# File 'lib/ltsv_logger.rb', line 28 def warn( = nil, log_hash = nil, &block) add(WARN, , log_hash, &block) end |