Module: Lumberjack::Rails::BroadcastLoggerExtension
- Defined in:
- lib/lumberjack/rails/broadcast_logger_extension.rb
Overview
Extension for ActiveSupport::BroadcastLogger to provide Lumberjack compatibility.
This module extends ActiveSupport::BroadcastLogger to ensure proper handling of Lumberjack loggers when broadcasting to multiple loggers, including support for Lumberjack-specific features like attributes and contexts.
Instance Method Summary collapse
-
#add(severity, message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
(also: #log)
Add a log entry with the specified severity and optional attributes support.
-
#append_to(attribute_name, *tag) { ... } ⇒ Object
Append values to an existing attribute.
-
#clear_attributes { ... } ⇒ Object
Clear all current attributes.
-
#context { ... } ⇒ Object
Execute a block within a logger context.
-
#debug(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
Log a debug message with optional attributes support.
-
#ensure_context { ... } ⇒ Object
Ensure a Lumberjack context is present for the duration of the block.
-
#error(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
Log an error message with optional attributes support.
-
#fatal(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
Log a fatal message with optional attributes support.
-
#fork(level: nil, progname: nil, attributes: nil) ⇒ Lumberjack::ForkedLogger
Create a forked logger from this broadcast logger.
-
#info(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
Log an info message with optional attributes support.
-
#initialize(*loggers) ⇒ Object
Initialize the broadcast logger with validation for Lumberjack loggers.
-
#set_progname(value) { ... } ⇒ Object
Alias for with_progname for backward compatibility.
-
#tag(attributes) { ... } ⇒ Object
Tag log entries with the specified attributes.
-
#unknown(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
Log an unknown severity message with optional attributes support.
-
#untagged { ... } ⇒ Object
Execute a block without any tags.
-
#warn(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
Log a warning message with optional attributes support.
-
#with_level(level) { ... } ⇒ Object
Override the with_level method defined on the logger gem to use Rails’ log_at method instead.
-
#with_progname(value) { ... } ⇒ Object
Set the progname temporarily for a block.
Instance Method Details
#add(severity, message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void Also known as: log
This method returns an undefined value.
Add a log entry with the specified severity and optional attributes support.
102 103 104 105 106 107 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 102 def add(severity, = nil, progname_or_attributes = nil, &block) severity = Logger::Severity.coerce(severity) dispatch_to_each(block) do |logger, one_time_block| call_add_with_attributes_arg(logger, severity, , progname_or_attributes, &one_time_block) end end |
#append_to(attribute_name, *tag) { ... } ⇒ Object
Append values to an existing attribute.
151 152 153 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 151 def append_to(attribute_name, *tag, &block) dispatch_block_method(:append_to, attribute_name, *tag, &block) end |
#clear_attributes { ... } ⇒ Object
Clear all current attributes.
159 160 161 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 159 def clear_attributes(&block) dispatch_block_method(:clear_attributes, &block) end |
#context { ... } ⇒ Object
Execute a block within a logger context.
133 134 135 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 133 def context(&block) dispatch_block_method(:context, &block) end |
#debug(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
This method returns an undefined value.
Log a debug message with optional attributes support.
29 30 31 32 33 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 29 def debug( = nil, progname_or_attributes = nil, &block) dispatch_to_each(block) do |logger, one_time_block| call_with_attributes_arg(logger, :debug, , progname_or_attributes, &one_time_block) end end |
#ensure_context { ... } ⇒ Object
Ensure a Lumberjack context is present for the duration of the block.
141 142 143 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 141 def ensure_context(&block) dispatch_block_method(:ensure_context, &block) end |
#error(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
This method returns an undefined value.
Log an error message with optional attributes support.
65 66 67 68 69 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 65 def error( = nil, progname_or_attributes = nil, &block) dispatch_to_each(block) do |logger, one_time_block| call_with_attributes_arg(logger, :error, , progname_or_attributes, &one_time_block) end end |
#fatal(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
This method returns an undefined value.
Log a fatal message with optional attributes support.
77 78 79 80 81 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 77 def fatal( = nil, progname_or_attributes = nil, &block) dispatch_to_each(block) do |logger, one_time_block| call_with_attributes_arg(logger, :fatal, , progname_or_attributes, &one_time_block) end end |
#fork(level: nil, progname: nil, attributes: nil) ⇒ Lumberjack::ForkedLogger
Create a forked logger from this broadcast logger.
195 196 197 198 199 200 201 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 195 def fork(level: nil, progname: nil, attributes: nil) logger = Lumberjack::ForkedLogger.new(self) logger.level = level if level logger.progname = progname if progname logger.tag!(attributes) if attributes && !attributes.empty? logger end |
#info(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
This method returns an undefined value.
Log an info message with optional attributes support.
41 42 43 44 45 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 41 def info( = nil, progname_or_attributes = nil, &block) dispatch_to_each(block) do |logger, one_time_block| call_with_attributes_arg(logger, :info, , progname_or_attributes, &one_time_block) end end |
#initialize(*loggers) ⇒ Object
Initialize the broadcast logger with validation for Lumberjack loggers.
15 16 17 18 19 20 21 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 15 def initialize(*loggers) if loggers.count { |logger| logger.is_a?(Lumberjack::ContextLogger) } > 1 raise ArgumentError, "Only one Lumberjack logger is allowed" end super end |
#set_progname(value) { ... } ⇒ Object
Alias for with_progname for backward compatibility.
185 186 187 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 185 def set_progname(value, &block) dispatch_block_method(:with_progname, value, &block) end |
#tag(attributes) { ... } ⇒ Object
Tag log entries with the specified attributes.
125 126 127 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 125 def tag(attributes, &block) dispatch_block_method(:tag, attributes, &block) end |
#unknown(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
This method returns an undefined value.
Log an unknown severity message with optional attributes support.
89 90 91 92 93 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 89 def unknown( = nil, progname_or_attributes = nil, &block) dispatch_to_each(block) do |logger, one_time_block| call_with_attributes_arg(logger, :unknown, , progname_or_attributes, &one_time_block) end end |
#untagged { ... } ⇒ Object
Execute a block without any tags.
167 168 169 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 167 def untagged(&block) dispatch_block_method(:untagged, &block) end |
#warn(message_or_progname_or_attributes = nil, progname_or_attributes = nil) { ... } ⇒ void
This method returns an undefined value.
Log a warning message with optional attributes support.
53 54 55 56 57 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 53 def warn( = nil, progname_or_attributes = nil, &block) dispatch_to_each(block) do |logger, one_time_block| call_with_attributes_arg(logger, :warn, , progname_or_attributes, &one_time_block) end end |
#with_level(level) { ... } ⇒ Object
Override the with_level method defined on the logger gem to use Rails’ log_at method instead.
116 117 118 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 116 def with_level(level, &block) log_at(level, &block) end |
#with_progname(value) { ... } ⇒ Object
Set the progname temporarily for a block.
176 177 178 |
# File 'lib/lumberjack/rails/broadcast_logger_extension.rb', line 176 def with_progname(value, &block) dispatch_block_method(:with_progname, value, &block) end |