Class: Loggerman::Formatters::JsonFormatter
- Inherits:
-
Formatter
- Object
- Formatter
- Loggerman::Formatters::JsonFormatter
show all
- Defined in:
- lib/loggerman/formatters/json_formatter.rb
Instance Method Summary
collapse
Methods inherited from Formatter
#clean_message, #format_message
Instance Method Details
#convert_exception(exception) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/loggerman/formatters/json_formatter.rb', line 20
def convert_exception(exception)
result = { exception: { class: exception.class.to_s, message: exception.message, location: exception.backtrace_locations.try(:first) } }
result[:exception].merge!( { location: exception.backtrace_locations.first } ) unless exception.backtrace_locations.blank?
result[:exception].merge!( format_message(exception.more_attributes) ) if exception.respond_to?(:more_attributes) && !exception.more_attributes.blank?
result[:exception].merge!( { backtrace: exception.backtrace } ) unless exception.backtrace.blank?
result
end
|
#convert_hash(args) ⇒ Object
16
17
18
|
# File 'lib/loggerman/formatters/json_formatter.rb', line 16
def convert_hash(args)
args
end
|
#convert_other(message) ⇒ Object
28
29
30
|
# File 'lib/loggerman/formatters/json_formatter.rb', line 28
def convert_other(message)
{ details: message.inspect }
end
|
#convert_string(message) ⇒ Object
12
13
14
|
# File 'lib/loggerman/formatters/json_formatter.rb', line 12
def convert_string(message)
{ details: message }
end
|
5
6
7
8
9
10
|
# File 'lib/loggerman/formatters/json_formatter.rb', line 5
def format_log(severity, timestamp, progname, message)
log_result = { severity => { time: timestamp.strftime("%Y-%m-%d %H:%M:%S"), src: Socket.ip_address_list[0].ip_address, host: Socket.gethostname } }
log_result[severity].merge!( {system: progname.to_s} ) unless progname.blank?
log_result[severity].merge!( format_message(message) ) unless message.blank?
log_result.to_json
end
|