Class: RightSupport::Log::FilterLogger
- Defined in:
- lib/right_support/log/filter_logger.rb
Overview
A logger than encapsulates an underlying Logger object and filters log entries before they are passed to the underlying Logger. Can be used to for various log- processing tasks such as filtering sensitive data or tagging log lines with a context marker.
Direct Known Subclasses
Instance Method Summary collapse
-
#<<(msg) ⇒ Object
Proxies to the encapsulated Logger object.
-
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Add a log line, filtering the severity and message before calling through to the underlying logger’s #add method.
-
#close ⇒ Object
Proxies to the encapsulated Logger object.
-
#debug? ⇒ Boolean
Proxies to the encapsulated Logger object.
-
#error? ⇒ Boolean
Proxies to the encapsulated Logger object.
-
#fatal? ⇒ Boolean
Proxies to the encapsulated Logger object.
-
#info? ⇒ Boolean
Proxies to the encapsulated Logger object.
-
#initialize(actual_logger) ⇒ FilterLogger
constructor
Initialize a new instance of this class.
-
#level ⇒ Object
Proxies to the encapsulated Logger object.
-
#level=(new_level) ⇒ Object
Proxies to the encapsulated Logger object.
-
#warn? ⇒ Boolean
Proxies to the encapsulated Logger object.
Constructor Details
#initialize(actual_logger) ⇒ FilterLogger
Initialize a new instance of this class.
Parameters
- actual_logger(Logger)
-
The actual, underlying Logger object
36 37 38 39 |
# File 'lib/right_support/log/filter_logger.rb', line 36 def initialize(actual_logger) @actual_logger = actual_logger end |
Instance Method Details
#<<(msg) ⇒ Object
Proxies to the encapsulated Logger object. See Logger#<< for info.
73 74 75 |
# File 'lib/right_support/log/filter_logger.rb', line 73 def <<(msg) @actual_logger << msg end |
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Add a log line, filtering the severity and message before calling through to the underlying logger’s #add method.
Parameters
- severity(Integer)
-
one of the Logger severity constants
- message(String)
-
the message to log, or nil
- progname(String)
-
the program name, or nil
Block
If message == nil and a block is given, yields to the block in order to capture the log message. This matches the behavior of Logger, but ensures the severity and message are still filtered.
Return
the result of the underlying logger’s #add
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/right_support/log/filter_logger.rb', line 56 def add(severity, = nil, progname = nil, &block) severity ||= UNKNOWN return true if severity < level if .nil? if block_given? = yield else = progname end end severity, = filter(severity, ) return @actual_logger.add(severity, ) if end |
#close ⇒ Object
Proxies to the encapsulated Logger object. See Logger#close for info.
78 79 80 |
# File 'lib/right_support/log/filter_logger.rb', line 78 def close @actual_logger.close end |
#debug? ⇒ Boolean
Proxies to the encapsulated Logger object. See Logger#debug? for info.
93 |
# File 'lib/right_support/log/filter_logger.rb', line 93 def debug?; @actual_logger.debug?; end |
#error? ⇒ Boolean
Proxies to the encapsulated Logger object. See Logger#error? for info.
102 |
# File 'lib/right_support/log/filter_logger.rb', line 102 def error?; @actual_logger.error?; end |
#fatal? ⇒ Boolean
Proxies to the encapsulated Logger object. See Logger#fatal? for info.
105 |
# File 'lib/right_support/log/filter_logger.rb', line 105 def fatal?; @actual_logger.fatal?; end |
#info? ⇒ Boolean
Proxies to the encapsulated Logger object. See Logger#info? for info.
96 |
# File 'lib/right_support/log/filter_logger.rb', line 96 def info?; @actual_logger.info?; end |
#level ⇒ Object
Proxies to the encapsulated Logger object. See Logger#level for info.
83 84 85 |
# File 'lib/right_support/log/filter_logger.rb', line 83 def level @actual_logger.level end |
#level=(new_level) ⇒ Object
Proxies to the encapsulated Logger object. See Logger#level= for info.
88 89 90 |
# File 'lib/right_support/log/filter_logger.rb', line 88 def level=(new_level) @actual_logger.level = new_level end |
#warn? ⇒ Boolean
Proxies to the encapsulated Logger object. See Logger#warn? for info.
99 |
# File 'lib/right_support/log/filter_logger.rb', line 99 def warn?; @actual_logger.warn?; end |