Module: Lumberjack::Rails::TaggedForkedLogger

Defined in:
lib/lumberjack/rails/tagged_forked_logger.rb

Overview

Extension for Lumberjack::ForkedLogger to support ActiveSupport tagged logging.

This module adds tagged logging capabilities to forked loggers by delegating tagged calls to the parent logger when available. It also shares the ActiveSupport local log level (used by silence and log_at) with the parent logger so that silencing the parent silences the fork.

Instance Method Summary collapse

Instance Method Details

#local_levelInteger?

Get the local log level from the parent logger so that silence and log_at on the parent apply to log entries written through the forked logger.

Returns:

  • (Integer, nil)

    the local log level



33
34
35
# File 'lib/lumberjack/rails/tagged_forked_logger.rb', line 33

def local_level
  parent_logger.respond_to?(:local_level) ? parent_logger.local_level : super
end

#local_level=(value) ⇒ void

This method returns an undefined value.

Set the local log level on the parent logger.

Parameters:

  • value (Integer, Symbol, nil)

    the local log level



41
42
43
44
45
46
47
# File 'lib/lumberjack/rails/tagged_forked_logger.rb', line 41

def local_level=(value)
  if parent_logger.respond_to?(:local_level=)
    parent_logger.local_level = value
  else
    super
  end
end

#tagged(*tags) { ... } ⇒ Object

Execute a block with the specified tags if the parent logger supports tagging. If the parent logger does not support tagging, the block is still executed without any tags applied.

Parameters:

  • tags (Array)

    the tags to apply during block execution

Yields:

  • the block to execute with the specified tags

Returns:

  • (Object)

    the result of the block execution



19
20
21
22
23
24
25
26
27
# File 'lib/lumberjack/rails/tagged_forked_logger.rb', line 19

def tagged(*tags, &block)
  if parent_logger.respond_to?(:tagged)
    parent_logger.tagged(*tags, &block)
  elsif block
    block.call
  else
    self
  end
end