Class: Timber::Contexts::System
- Inherits:
-
Timber::Context
- Object
- Timber::Context
- Timber::Contexts::System
- 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
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(attributes) ⇒ System
constructor
A new instance of System.
-
#to_hash ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
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
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
15 16 17 |
# File 'lib/timber/contexts/system.rb', line 15 def hostname @hostname end |
#pid ⇒ Object (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( = {}) to_hash end |
#to_hash ⇒ Object
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 |