Class: Logtail::Contexts::System

Inherits:
Logtail::Context show all
Defined in:
lib/logtail/contexts/system.rb

Overview

Note:

This is tracked automatically in Logtail::CurrentContext. When the current context is initialized, the system context gets added automatically.

The system context tracks OS level process information, such as the process ID.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ System

Returns a new instance of System.



13
14
15
16
# File 'lib/logtail/contexts/system.rb', line 13

def initialize(attributes)
  @hostname = attributes[:hostname]
  @pid = attributes[:pid]
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



11
12
13
# File 'lib/logtail/contexts/system.rb', line 11

def hostname
  @hostname
end

#pidObject (readonly)

Returns the value of attribute pid.



11
12
13
# File 'lib/logtail/contexts/system.rb', line 11

def pid
  @pid
end

Instance Method Details

#to_hashObject

Builds a hash representation containing simple objects, suitable for serialization (JSON).



19
20
21
22
23
24
25
26
# File 'lib/logtail/contexts/system.rb', line 19

def to_hash
  @to_hash ||= {
    system: Util::NonNilHashBuilder.build do |h|
      h.add(:hostname, hostname)
      h.add(:pid, pid)
    end
  }
end