Class: J1::LogHelper
- Inherits:
-
Logger
- Object
- Logger
- J1::LogHelper
- Defined in:
- lib/j1/log_helper.rb
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil) ⇒ Object
- #close ⇒ Object
-
#error(progname = nil, &block) ⇒ Object
Log an
ERROR
message. -
#initialize ⇒ LogHelper
constructor
A new instance of LogHelper.
-
#warn(progname = nil, &block) ⇒ Object
Log a
WARN
message.
Constructor Details
#initialize ⇒ LogHelper
Returns a new instance of LogHelper.
3 4 5 6 7 8 9 10 11 |
# File 'lib/j1/log_helper.rb', line 3 def initialize @progname = nil @level = DEBUG @default_formatter = Formatter.new @logdev = $stdout @formatter = proc do |_, _, _, msg| msg.to_s end end |
Instance Method Details
#add(severity, message = nil, progname = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/j1/log_helper.rb', line 13 def add(severity, = nil, progname = nil) severity ||= UNKNOWN @logdev = logdevice(severity) if @logdev.nil? || severity < @level return true end progname ||= @progname if .nil? if block_given? = yield else = progname progname = @progname end end @logdev.puts( (format_severity(severity), Time.now, progname, ) ) true end |
#close ⇒ Object
47 48 49 |
# File 'lib/j1/log_helper.rb', line 47 def close # No LogDevice in use end |
#error(progname = nil, &block) ⇒ Object
Log an ERROR
message
42 43 44 45 |
# File 'lib/j1/log_helper.rb', line 42 def error(progname = nil, &block) #add(ERROR, nil, progname.red, &block) add(ERROR, nil, progname, &block) end |
#warn(progname = nil, &block) ⇒ Object
Log a WARN
message
36 37 38 39 |
# File 'lib/j1/log_helper.rb', line 36 def warn(progname = nil, &block) #add(WARN, nil, progname.yellow, &block) add(WARN, nil, progname, &block) end |