Sha256: a2b0260c7e89a61bd5f3b3f1b43d3632cfcbd2e518989c432b87f52449037e65

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

require "timber/context"

module Timber
  module Contexts
    # 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.
    class Runtime < Context
      @keyspace = :runtime

      attr_reader :application, :class_name, :file, :function, :line, :module_name, :vm_pid

      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

      # Builds a hash representation containing simple objects, suitable for serialization (JSON).
      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
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
timber-2.5.1 lib/timber/contexts/runtime.rb
timber-2.5.0 lib/timber/contexts/runtime.rb
timber-2.4.0 lib/timber/contexts/runtime.rb
timber-2.3.4 lib/timber/contexts/runtime.rb
timber-2.3.3 lib/timber/contexts/runtime.rb
timber-2.3.2 lib/timber/contexts/runtime.rb
timber-2.3.1 lib/timber/contexts/runtime.rb
timber-2.3.0 lib/timber/contexts/runtime.rb
timber-2.2.3 lib/timber/contexts/runtime.rb
timber-2.2.2 lib/timber/contexts/runtime.rb
timber-2.2.1 lib/timber/contexts/runtime.rb
timber-2.2.0 lib/timber/contexts/runtime.rb
timber-2.1.10 lib/timber/contexts/runtime.rb