Class: Berkshelf::Logger
- Inherits:
-
Logger
- Object
- Logger
- Berkshelf::Logger
- Defined in:
- lib/berkshelf/logger.rb
Instance Method Summary collapse
-
#add(severity, message = nil, progname = nil, &block) ⇒ Boolean
Reimplements Logger#add adding message filtering.
- #clear_filter_params ⇒ Object
- #deprecate(message) ⇒ Object
-
#exception(ex) ⇒ Object
Log an exception and its backtrace to FATAL.
- #filter(message) ⇒ Object
- #filter_param(param) ⇒ Object
- #filter_params ⇒ Object
-
#initialize(device = STDOUT) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Boolean
Reimplements Logger#add adding message filtering. The info, warn, debug, error, and fatal methods all call add.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/berkshelf/logger.rb', line 26 def add(severity, = nil, progname = nil, &block) severity ||= Logger::UNKNOWN if @logdev.nil? || severity < (@level) return true end progname ||= @progname if .nil? if block_given? = yield else = progname progname = @progname end end @logdev.write( (format_severity(severity), Time.now, progname, filter()) ) true end |
#clear_filter_params ⇒ Object
55 56 57 |
# File 'lib/berkshelf/logger.rb', line 55 def clear_filter_params @filter_params.clear end |
#deprecate(message) ⇒ Object
68 69 70 71 |
# File 'lib/berkshelf/logger.rb', line 68 def deprecate() trace = caller.join("\n\t") warn "DEPRECATION WARNING: #{}\n\t#{trace}" end |
#exception(ex) ⇒ Object
Log an exception and its backtrace to FATAL
76 77 78 79 |
# File 'lib/berkshelf/logger.rb', line 76 def exception(ex) fatal("#{ex.class}: #{ex}") fatal(ex.backtrace.join("\n")) unless ex.backtrace.nil? end |
#filter(message) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/berkshelf/logger.rb', line 59 def filter() filter_params.each do |param| .gsub!(param.to_s, "FILTERED") end end |
#filter_param(param) ⇒ Object
51 52 53 |
# File 'lib/berkshelf/logger.rb', line 51 def filter_param(param) @filter_params << param unless filter_params.include?(param) end |
#filter_params ⇒ Object
47 48 49 |
# File 'lib/berkshelf/logger.rb', line 47 def filter_params @filter_params.dup end |