Class WEBrick::BasicLog
In: lib/webrick/log.rb
Parent: Object

Methods

<<   close   debug   debug?   error   error?   fatal   fatal?   format   info   info?   log   new   warn   warn?  

Constants

DEBUG = 1, 2, 3, 4, 5

Attributes

level  [RW] 

Public Class methods

[Source]

    # File lib/webrick/log.rb, line 18
18:     def initialize(log_file=nil, level=nil)
19:       @level = level || INFO
20:       case log_file
21:       when String
22:         @log = open(log_file, "a+")
23:         @log.sync = true
24:         @opened = true
25:       when NilClass
26:         @log = $stderr
27:       else
28:         @log = log_file  # requires "<<". (see BasicLog#log)
29:       end
30:     end

Public Instance methods

[Source]

    # File lib/webrick/log.rb, line 44
44:     def <<(obj)
45:       log(INFO, obj.to_s)
46:     end

[Source]

    # File lib/webrick/log.rb, line 32
32:     def close
33:       @log.close if @opened
34:       @log = nil
35:     end

[Source]

    # File lib/webrick/log.rb, line 52
52:     def debug(msg) log(DEBUG, "DEBUG " << format(msg)); end

[Source]

    # File lib/webrick/log.rb, line 58
58:     def debug?; @level >= DEBUG; end

[Source]

    # File lib/webrick/log.rb, line 49
49:     def error(msg) log(ERROR, "ERROR " << format(msg)); end

[Source]

    # File lib/webrick/log.rb, line 55
55:     def error?; @level >= ERROR; end

[Source]

    # File lib/webrick/log.rb, line 48
48:     def fatal(msg) log(FATAL, "FATAL " << format(msg)); end

[Source]

    # File lib/webrick/log.rb, line 54
54:     def fatal?; @level >= FATAL; end

[Source]

    # File lib/webrick/log.rb, line 51
51:     def info(msg)  log(INFO,  "INFO  " << format(msg)); end

[Source]

    # File lib/webrick/log.rb, line 57
57:     def info?;  @level >= INFO; end

[Source]

    # File lib/webrick/log.rb, line 37
37:     def log(level, data)
38:       if @log && level <= @level
39:         data += "\n" if /\n\Z/ !~ data
40:         @log << data
41:       end
42:     end

[Source]

    # File lib/webrick/log.rb, line 50
50:     def warn(msg)  log(WARN,  "WARN  " << format(msg)); end

[Source]

    # File lib/webrick/log.rb, line 56
56:     def warn?;  @level >= WARN; end

Private Instance methods

[Source]

    # File lib/webrick/log.rb, line 62
62:     def format(arg)
63:       str = if arg.is_a?(Exception)
64:         "#{arg.class}: #{arg.message}\n\t" <<
65:         arg.backtrace.join("\n\t") << "\n"
66:       elsif arg.respond_to?(:to_str)
67:         arg.to_str
68:       else
69:         arg.inspect
70:       end
71:     end

[Validate]