Class: QB::Ansible::Module::Formatters::JSON

Inherits:
SemanticLogger::Formatters::Raw
  • Object
show all
Defined in:
lib/qb/ansible/module.rb

Instance Method Summary collapse

Constructor Details

#initialize(time_format: :iso_8601, log_host: true, log_application: true, time_key: :timestamp) ⇒ JSON

Default JSON time format is ISO8601



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/qb/ansible/module.rb', line 87

def initialize  time_format: :iso_8601,
                log_host: true,
                log_application: true,
                time_key: :timestamp
  super(
    time_format: time_format,
    log_host: log_host,
    log_application: log_application,
    time_key: time_key,
  )
end

Instance Method Details

#call(log, logger) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/qb/ansible/module.rb', line 99

def call log, logger
  raw = super( log, logger )
  
  begin
    raw.to_json
  rescue Exception => error
    # SemanticLogger::Processor.instance.appender.logger.warn \
    #   "Unable to JSON encode for logging", raw: raw
    
    $stderr.puts "Unable to JSON encode log"
    $stderr.puts raw.pretty_inspect
    
    raise
  end
end