Sha256: 3028dce5e76b1a2997d9627b98e3e29acfc7e87b01a50f868a663fa40f0e9e85

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 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 = attributes[:vm_pid]
      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

8 entries across 8 versions & 1 rubygems

Version Path
timber-2.1.9 lib/timber/contexts/runtime.rb
timber-2.1.8 lib/timber/contexts/runtime.rb
timber-2.1.7 lib/timber/contexts/runtime.rb
timber-2.1.6 lib/timber/contexts/runtime.rb
timber-2.1.5 lib/timber/contexts/runtime.rb
timber-2.1.4 lib/timber/contexts/runtime.rb
timber-2.1.3 lib/timber/contexts/runtime.rb
timber-2.1.2 lib/timber/contexts/runtime.rb