Class: LoggerWithTrace
- Inherits:
-
Logger
- Object
- Logger
- LoggerWithTrace
- Defined in:
- lib/waithook/logger_with_trace.rb
Overview
Just add trace level
Defined Under Namespace
Modules: Severity
Constant Summary collapse
Instance Method Summary collapse
- #level=(severity) ⇒ Object
- #setup(options) ⇒ Object
- #trace(progname = nil, &block) ⇒ Object
- #trace? ⇒ Boolean
Instance Method Details
#level=(severity) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/waithook/logger_with_trace.rb', line 20 def level=(severity) if severity.is_a?(Integer) @level = severity else @level = case severity.to_s.downcase when 'trace'.freeze then TRACE when 'debug'.freeze then DEBUG when 'info'.freeze then INFO when 'warn'.freeze then WARN when 'error'.freeze then ERROR when 'fatal'.freeze then FATAL when 'unknown'.freeze then UNKNOWN else raise ArgumentError, "invalid log level: #{severity}" end end end |
#setup(options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/waithook/logger_with_trace.rb', line 38 def setup() self.progname = [:progname] self.formatter = proc do |serverity, time, progname, msg| msg.lines.map do |line| "#{progname} :: #{line}" end.join("") + "\n" end self.level = [:level] self end |
#trace(progname = nil, &block) ⇒ Object
12 13 14 |
# File 'lib/waithook/logger_with_trace.rb', line 12 def trace(progname = nil, &block) add(TRACE, nil, progname, &block) end |
#trace? ⇒ Boolean
16 17 18 |
# File 'lib/waithook/logger_with_trace.rb', line 16 def trace? @level <= TRACE end |