Sha256: 1429d1b3df2fa2fc5945257b0285486e1e5a30da8ca794144d95d85ee5834863

Contents?: true

Size: 1.63 KB

Versions: 13

Compression:

Stored size: 1.63 KB

Contents

require 'rbconfig'
require 'time'
require 'thread'

module Lumberjack
  LINE_SEPARATOR = (RbConfig::CONFIG['host_os'].match(/mswin/i) ? "\r\n" : "\n")

  load File.expand_path("../lumberjack/severity.rb", __FILE__)
  load File.expand_path("../lumberjack/log_entry.rb", __FILE__)
  load File.expand_path("../lumberjack/formatter.rb", __FILE__)
  load File.expand_path("../lumberjack/device.rb", __FILE__)
  load File.expand_path("../lumberjack/logger.rb", __FILE__)
  load File.expand_path("../lumberjack/template.rb", __FILE__)

  autoload :Rack, File.expand_path("../lumberjack/rack.rb", __FILE__)
  
  class << self
    # Define a unit of work within a block. Within the block supplied to this
    # method, calling +unit_of_work_id+ will return the same value that can
    # This can then be used for tying together log entries.
    #
    # You can specify the id for the unit of work if desired. If you don't supply
    # it, a 12 digit hexidecimal number will be automatically generated for you.
    #
    # For the common use case of treating a single web request as a unit of work, see the
    # Lumberjack::Rack::UnitOfWork class.
    def unit_of_work(id = nil)
      save_val = Thread.current[:lumberjack_logger_unit_of_work_id]
      id ||= rand(0xFFFFFFFFFFFF).to_s(16).rjust(12, '0').upcase
      Thread.current[:lumberjack_logger_unit_of_work_id] = id
      begin
        return yield
      ensure
        Thread.current[:lumberjack_logger_unit_of_work_id] = save_val
      end
    end
    
    # Get the UniqueIdentifier for the current unit of work.
    def unit_of_work_id
      Thread.current[:lumberjack_logger_unit_of_work_id] 
    end
  end
end

Version data entries

13 entries across 11 versions & 4 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/lumberjack-1.0.9/lib/lumberjack.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/lumberjack-1.0.9/lib/lumberjack.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/lumberjack-1.0.9/lib/lumberjack.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/lumberjack-1.0.9/lib/lumberjack.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/lumberjack-1.0.9/lib/lumberjack.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/lumberjack-1.0.9/lib/lumberjack.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/lumberjack-1.0.9/lib/lumberjack.rb
geminfo-0.1.0 path/gems/lumberjack-1.0.9/lib/lumberjack.rb
lumberjack-1.0.9 lib/lumberjack.rb
lumberjack-1.0.8 lib/lumberjack.rb
lumberjack-1.0.7 lib/lumberjack.rb
lumberjack-1.0.6 lib/lumberjack.rb
lumberjack-1.0.5 lib/lumberjack.rb