Sha256: 70b7611f1c2ee2aa95dbb8fb5ffefc38a8b00f6d2460d92153a2d3d93457d4f2

Contents?: true

Size: 1.63 KB

Versions: 8

Compression:

Stored size: 1.63 KB

Contents

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

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

  require File.expand_path("../lumberjack/severity.rb", __FILE__)
  require File.expand_path("../lumberjack/log_entry.rb", __FILE__)
  require File.expand_path("../lumberjack/formatter.rb", __FILE__)
  require File.expand_path("../lumberjack/device.rb", __FILE__)
  require File.expand_path("../lumberjack/logger.rb", __FILE__)
  require File.expand_path("../lumberjack/template.rb", __FILE__)
  require 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 ||= SecureRandom.hex(6)
      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

8 entries across 8 versions & 4 rubygems

Version Path
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.12/lib/lumberjack.rb
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.12/lib/lumberjack.rb
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.12/lib/lumberjack.rb
lumberjack-1.0.12 lib/lumberjack.rb
lumberjack-1.0.11 lib/lumberjack.rb
gameboard-3.1.0 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.10/lib/lumberjack.rb
gameboard-3.0.0 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.10/lib/lumberjack.rb
lumberjack-1.0.10 lib/lumberjack.rb