Class: WEBrick::BasicLog
- Inherits:
-
Object
- Object
- WEBrick::BasicLog
- Defined in:
- lib/webrick/log.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
- #<<(obj) ⇒ Object
- #close ⇒ Object
- #debug(msg) ⇒ Object
- #debug? ⇒ Boolean
- #error(msg) ⇒ Object
- #error? ⇒ Boolean
- #fatal(msg) ⇒ Object
- #fatal? ⇒ Boolean
- #info(msg) ⇒ Object
- #info? ⇒ Boolean
-
#initialize(log_file = nil, level = nil) ⇒ BasicLog
constructor
A new instance of BasicLog.
- #log(level, data) ⇒ Object
- #warn(msg) ⇒ Object
- #warn? ⇒ Boolean
Constructor Details
#initialize(log_file = nil, level = nil) ⇒ BasicLog
Returns a new instance of BasicLog.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/webrick/log.rb', line 18 def initialize(log_file=nil, level=nil) @level = level || INFO case log_file when String @log = open(log_file, "a+") @log.sync = true @opened = true when NilClass @log = $stderr else @log = log_file # requires "<<". (see BasicLog#log) end end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level
16 17 18 |
# File 'lib/webrick/log.rb', line 16 def level @level end |
Instance Method Details
#<<(obj) ⇒ Object
44 45 46 |
# File 'lib/webrick/log.rb', line 44 def <<(obj) log(INFO, obj.to_s) end |
#close ⇒ Object
32 33 34 35 |
# File 'lib/webrick/log.rb', line 32 def close @log.close if @opened @log = nil end |
#debug(msg) ⇒ Object
52 |
# File 'lib/webrick/log.rb', line 52 def debug(msg) log(DEBUG, "DEBUG " << format(msg)); end |
#debug? ⇒ Boolean
58 |
# File 'lib/webrick/log.rb', line 58 def debug?; @level >= DEBUG; end |
#error(msg) ⇒ Object
49 |
# File 'lib/webrick/log.rb', line 49 def error(msg) log(ERROR, "ERROR " << format(msg)); end |
#error? ⇒ Boolean
55 |
# File 'lib/webrick/log.rb', line 55 def error?; @level >= ERROR; end |
#fatal(msg) ⇒ Object
48 |
# File 'lib/webrick/log.rb', line 48 def fatal(msg) log(FATAL, "FATAL " << format(msg)); end |
#fatal? ⇒ Boolean
54 |
# File 'lib/webrick/log.rb', line 54 def fatal?; @level >= FATAL; end |
#info(msg) ⇒ Object
51 |
# File 'lib/webrick/log.rb', line 51 def info(msg) log(INFO, "INFO " << format(msg)); end |
#info? ⇒ Boolean
57 |
# File 'lib/webrick/log.rb', line 57 def info?; @level >= INFO; end |
#log(level, data) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/webrick/log.rb', line 37 def log(level, data) if @log && level <= @level data += "\n" if /\n\Z/ !~ data @log << data end end |
#warn(msg) ⇒ Object
50 |
# File 'lib/webrick/log.rb', line 50 def warn(msg) log(WARN, "WARN " << format(msg)); end |
#warn? ⇒ Boolean
56 |
# File 'lib/webrick/log.rb', line 56 def warn?; @level >= WARN; end |