Sha256: fc0e1f91903599ee890c29249ae8dc5ffed252ea98066bf0022be8287723fd40

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 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

      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]
      end

      # Builds a hash representation of containing simply objects, suitable for serialization.
      def as_json(_options = {})
        {application: application, class_name: class_name, file: file, function: function,
          line: line, module_name: module_name}
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
timber-2.1.0.rc5 lib/timber/contexts/runtime.rb
timber-2.1.0.rc4 lib/timber/contexts/runtime.rb
timber-2.1.0.rc3 lib/timber/contexts/runtime.rb
timber-2.1.0.rc2 lib/timber/contexts/runtime.rb
timber-2.1.0.rc1 lib/timber/contexts/runtime.rb