Class: Timber::Contexts::System

Inherits:
Timber::Context
  • Object
show all
Defined in:
lib/timber/contexts/system.rb

Overview

Note:

This is tracked automatically in Timber::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.

Constant Summary collapse

HOSTNAME_MAX_BYTES =
256.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ System

Returns a new instance of System.



17
18
19
20
21
# File 'lib/timber/contexts/system.rb', line 17

def initialize(attributes)
  normalizer = Util::AttributeNormalizer.new(attributes)
  @hostname = normalizer.fetch(:hostname, :string, :limit => HOSTNAME_MAX_BYTES)
  @pid = normalizer.fetch(:pid, :integer)
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



15
16
17
# File 'lib/timber/contexts/system.rb', line 15

def hostname
  @hostname
end

#pidObject (readonly)

Returns the value of attribute pid.



15
16
17
# File 'lib/timber/contexts/system.rb', line 15

def pid
  @pid
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



31
32
33
# File 'lib/timber/contexts/system.rb', line 31

def as_json(_options = {})
  to_hash
end

#to_hashObject

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



24
25
26
27
28
29
# File 'lib/timber/contexts/system.rb', line 24

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