Class: WEBrick::BasicLog

Inherits:
Object
  • Object
show all
Defined in:
lib/webrick/log.rb

Direct Known Subclasses

Log

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#levelObject

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

#closeObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


56
# File 'lib/webrick/log.rb', line 56

def warn?;  @level >= WARN; end