Class: Timber::Contexts::Runtime

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

Overview

The runtime context adds current runtime data to your logs, such as the file, line number, class or module name, etc. This makes it easy to tail and search your logs by their origin in your code. For example, if you are debugging a specific class, you can narrow by that class and see only it’s logs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Runtime

Returns a new instance of Runtime.



14
15
16
17
18
19
20
21
22
# File 'lib/timber/contexts/runtime.rb', line 14

def initialize(attributes)
  @application = attributes[:application]
  @class_name = attributes[:class_name]
  @file = attributes[:file]
  @function = attributes[:function]
  @line = attributes[:line]
  @module_name = attributes[:module_name]
  @vm_pid = Timber::Util::Object.try(attributes[:vm_pid], :to_s)
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



12
13
14
# File 'lib/timber/contexts/runtime.rb', line 12

def application
  @application
end

#class_nameObject (readonly)

Returns the value of attribute class_name.



12
13
14
# File 'lib/timber/contexts/runtime.rb', line 12

def class_name
  @class_name
end

#fileObject (readonly)

Returns the value of attribute file.



12
13
14
# File 'lib/timber/contexts/runtime.rb', line 12

def file
  @file
end

#functionObject (readonly)

Returns the value of attribute function.



12
13
14
# File 'lib/timber/contexts/runtime.rb', line 12

def function
  @function
end

#lineObject (readonly)

Returns the value of attribute line.



12
13
14
# File 'lib/timber/contexts/runtime.rb', line 12

def line
  @line
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



12
13
14
# File 'lib/timber/contexts/runtime.rb', line 12

def module_name
  @module_name
end

#vm_pidObject (readonly)

Returns the value of attribute vm_pid.



12
13
14
# File 'lib/timber/contexts/runtime.rb', line 12

def vm_pid
  @vm_pid
end

Instance Method Details

#as_json(_options = {}) ⇒ Object

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



25
26
27
28
# File 'lib/timber/contexts/runtime.rb', line 25

def as_json(_options = {})
  {application: application, class_name: class_name, file: file, function: function,
    line: line, module_name: module_name, vm_pid: vm_pid}
end