Active Support Proxy Logger¶ ↑
The proxy logger, is a logger that forwards all received logs to another logger, but has its own independent severity level.
This is useful when you want some library you have no control over to use the same logger as the rest of your application, but to have a different severity level because it is logging too much:
SomeLibrary.logger = ActiveSupport::ProxyLogger.new(Rails.logger, :error)
Almost all of the standard Logger interface is supported.
Note that the proxy logger can only surpress some logs, if the proxy severity is lower than the severity of the proxied logger, the logs won’t be emitted.
- #
- A
- C
- D
- E
- F
- I
- L
- N
- R
- U
- W
- ActiveSupport::LoggerSilence
- ::Logger::Severity
Class Public methods
new(logger, level = ::Logger::DEBUG) Link
Instance Public methods
<<(msg) Link
Forward the given msg to the underlying logger with no formatting returns the number of characters written, or nil if the underlying logger is nil:
logger = ProxyLogger.new(Logger.new($stderr)) logger << 'My message.' # => 10
Output:
My message.
add(severity, ...) Link
Creates a log entry, which may or may not be written to the log, depending on the entry’s severity and on the log level.
Examples:
logger = ActiveSupport::ProxyLogger.new(Logger.new($stderr), :error) logger.add(Logger::INFO, 'Will not show') logger.add(Logger::ERROR, 'No good') logger.add(Logger::ERROR, 'No good', 'gnum')
Output:
E, [2022-05-12T16:25:55.349414 #36328] ERROR -- mung: No good E, [2022-05-12T16:26:35.841134 #36328] ERROR -- gnum: No good
These convenience methods have implicit severity:
close() Link
Closes the logger; returns nil: Further logs won’t be emitted.
debug!() Link
Sets the log level to Logger::DEBUG.
debug?() Link
Returns true if the log level allows entries with severity Logger::DEBUG to be written, false otherwise.
error!() Link
Sets the log level to Logger::ERROR.
error?() Link
Returns true if the log level allows entries with severity Logger::ERROR to be written, false otherwise.
fatal!() Link
Sets the log level to Logger::FATAL.
fatal?() Link
Returns true if the log level allows entries with severity Logger::FATAL to be written, false otherwise.
info!() Link
Sets the log level to Logger::INFO.
info?() Link
Returns true if the log level allows entries with severity Logger::INFO to be written, false otherwise.
level() Link
Logging severity threshold (e.g. Logger::INFO).
level=(severity) Link
Sets the log level; returns severity.
Argument severity may be an integer, a string, or a symbol:
logger.level = Logger::ERROR # => 3 logger.level = 3 # => 3 logger.level = 'error' # => "error" logger.level = :error # => :error
reopen(logger) Link
Change the underlying logger.
warn!() Link
Sets the log level to Logger::WARN.