Class: Niboshi::JsonFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Niboshi::JsonFormatter
- Defined in:
- lib/niboshi/json_formatter.rb,
lib/niboshi_json_formatter.rb
Constant Summary collapse
- Version =
VERSION = "0.1.1"
Instance Method Summary collapse
Instance Method Details
#call(severity, time, program_name, message) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/niboshi/json_formatter.rb', line 16 def call(severity, time, program_name, ) data = { time: time.to_f, formatted_time: time, hostname: hostname, pid: $$, tid: tid, level: severity, program_name: program_name, message: } data.to_json + "\n" rescue JSON::GeneratorError (data.each_pair {|k,v| data[k] = v.scrub("?") if v.is_a?(String) }).to_json + "\n" end |
#hostname ⇒ Object
8 9 10 |
# File 'lib/niboshi/json_formatter.rb', line 8 def hostname @hostname ||= Socket.gethostname end |
#tid ⇒ Object
12 13 14 |
# File 'lib/niboshi/json_formatter.rb', line 12 def tid Thread.current.object_id end |