Module: Lumberjack

Defined in:
lib/lumberjack.rb,
lib/lumberjack/rack.rb,
lib/lumberjack/device.rb,
lib/lumberjack/logger.rb,
lib/lumberjack/severity.rb,
lib/lumberjack/template.rb,
lib/lumberjack/formatter.rb,
lib/lumberjack/log_entry.rb,
lib/lumberjack/device/null.rb,
lib/lumberjack/device/writer.rb,
lib/lumberjack/device/log_file.rb,
lib/lumberjack/rack/unit_of_work.rb,
lib/lumberjack/device/rolling_log_file.rb,
lib/lumberjack/formatter/string_formatter.rb,
lib/lumberjack/formatter/inspect_formatter.rb,
lib/lumberjack/device/date_rolling_log_file.rb,
lib/lumberjack/device/size_rolling_log_file.rb,
lib/lumberjack/formatter/exception_formatter.rb,
lib/lumberjack/formatter/pretty_print_formatter.rb

Defined Under Namespace

Modules: Rack, Severity Classes: Device, Formatter, LogEntry, Logger, Template

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.unit_of_work(id = nil) ⇒ Object

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.



27
28
29
30
31
32
33
34
35
36
# File 'lib/lumberjack.rb', line 27

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

.unit_of_work_idObject

Get the UniqueIdentifier for the current unit of work.



39
40
41
# File 'lib/lumberjack.rb', line 39

def unit_of_work_id
  Thread.current[:lumberjack_logger_unit_of_work_id] 
end