Class: Logson::Logger
- Inherits:
-
Logger
- Object
- Logger
- Logson::Logger
- Defined in:
- lib/logson/logger.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Logger
constructor
A new instance of Logger.
- #source ⇒ Object
- #source=(value) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Logger
Returns a new instance of Logger.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/logson/logger.rb', line 5 def initialize(*args) super(*args) self.hostname = Socket.gethostname self.formatter = proc do |severity, date, progname, msg| date = date.utc.iso8601 if date.is_a?(Time) data = { '_severity' => severity, '_date' => date, '_source' => progname, '_host' => hostname } if msg.is_a?(Hash) data = data.merge(msg) else data['message'] = msg end date.to_s + ' ' + JSON.dump(data) + "\n" end end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
3 4 5 |
# File 'lib/logson/logger.rb', line 3 def hostname @hostname end |
Instance Method Details
#source ⇒ Object
27 28 29 |
# File 'lib/logson/logger.rb', line 27 def source self.progname end |
#source=(value) ⇒ Object
23 24 25 |
# File 'lib/logson/logger.rb', line 23 def source=(value) self.progname = value end |