Class: LtsvLogger

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logger::Severity
Defined in:
lib/ltsv_logger.rb

Constant Summary collapse

VERSION =
"0.0.0"

Instance Method Summary collapse

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, message_or_log_hash = nil, log_hash = nil, &block)
  if block_given?
    array_or_hash = yield
    if array_or_hash.respond_to?(:to_h)
      message_or_log_hash = array_or_hash
    else # as an Array
      message_or_log_hash, log_hash = *array_or_hash
    end
  end
  if message_or_log_hash.respond_to?(:to_h)
    output_data = message_or_log_hash.to_h
  else
    output_data = log_hash.to_h.merge(message: message_or_log_hash)
  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(message_or_log_hash = nil, log_hash = nil, &block)
  add(DEBUG, message_or_log_hash, 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(message_or_log_hash = nil, log_hash = nil, &block)
  add(ERROR, message_or_log_hash, 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(message_or_log_hash = nil, log_hash = nil, &block)
  add(FATAL, message_or_log_hash, 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(message_or_log_hash = nil, log_hash = nil, &block)
  add(INFO, message_or_log_hash, 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(message_or_log_hash = nil, log_hash = nil, &block)
  add(WARN, message_or_log_hash, log_hash, &block)
end