12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/betterlog/log_event_formatter.rb', line 12
def call(severity, timestamp, program, message)
if cc.log.legacy_supported
if message.blank?
message = ''
elsif !Log::Event.is?(message)
m = message.to_s
m = Term::ANSIColor.uncolor(m)
m = m.sub(/\s+$/, '')
timestamp = timestamp.utc.iso8601(3)
event = Log::Event.new(
emitter: emitter,
timestamp: timestamp,
message: m,
severity: severity.to_s.downcase,
)
backtrace = m.scan(/^\s*(?:[^:]+):(?:\d+).*$/)
if backtrace.size > 1
event[:backtrace] = backtrace.map { |b| b.sub(/\s+$/, '') }
event[:message] = "#{backtrace.first}\n"
end
if l = caller_locations.reverse_each.each_cons(2).find { |c, n|
n.absolute_path =~ /\/lib\/ruby\/.*?\/logger\.rb/ and break c
}
then
event[:location] = [ l.absolute_path, l.lineno ] * ?:
end
program and event[:program] = program
message = JSON.generate(event)
end
end
rescue => e
Betterlog::Log.logger.error(e)
ensure
message.end_with?(?\n) or message = "#{message}\n"
return message
end
|