Parent

Class/Module Index [+]

Quicksearch

Webgen::Logger

The class used by a Website to do the logging and the normal output.

Attributes

sync[R]

Specifies whether log output should be synchronous with normal output.

verbosity[RW]

Normal output verbosity (:normal, :verbose, :quiet).

Public Class Methods

new(outdev=$stdout, sync=false) click to toggle source

Create a new Logger object which uses outdev as output device. If sync is set to true, log messages are interspersed with normal output.

# File lib/webgen/logger.rb, line 18
def initialize(outdev=$stdout, sync=false)
  @sync = sync
  @outdev = outdev
  @logger = (@sync ? ::Logger.new(@outdev) : ::Logger.new(@logio = StringIO.new))
  @logger.formatter = Proc.new do |severity, timestamp, progname, msg|
    if self.level == ::Logger::DEBUG
      "%5s -- %s: %s\n" % [severity, progname, msg ]
    else
      "%5s -- %s\n" % [severity, msg]
    end
  end
  self.level = ::Logger::WARN
  self.verbosity = :normal
  @marks = []
end

Public Instance Methods

debug(source='', &block) click to toggle source

Utiltity method for logging a debug message.

# File lib/webgen/logger.rb, line 86
def debug(source='', &block); log(:debug, source, &block); end
error(source='', &block) click to toggle source

Utiltity method for logging an error message.

# File lib/webgen/logger.rb, line 77
def error(source='', &block); log(:error, source, &block); end
info(source='', &block) click to toggle source

Utiltity method for logging an informational message.

# File lib/webgen/logger.rb, line 83
def info(source='', &block); log(:info, source, &block); end
level() click to toggle source

The severity threshold level.

# File lib/webgen/logger.rb, line 56
def level
  @logger.level
end
level=(value) click to toggle source

Set the severity threshold to value which can be one of the stdlib Logger severity levels.

# File lib/webgen/logger.rb, line 61
def level=(value)
  @logger.level = value
end
log(sev_level, source='', &block) click to toggle source

Log a message of sev_level from source. The mandatory block has to return the message.

# File lib/webgen/logger.rb, line 66
def log(sev_level, source='', &block)
  if sev_level == :stdout
    @outdev.write(block.call + "\n") if @verbosity == :normal || @verbosity == :verbose
  elsif sev_level == :verbose
    @outdev.write(block.call + "\n") if @verbosity == :verbose
  else
    @logger.send(sev_level, source, &block)
  end
end
log_output() click to toggle source

Returns the output of the logger when sync is false. Otherwise an empty string is returned.

# File lib/webgen/logger.rb, line 35
def log_output
  if @sync
    ''
  else
    out = @logio.string.dup
    @marks.reverse.each_with_index do |mark, index|
      out.insert(mark, " INFO -- Log messages for run #{@marks.length - index} are following\n")
    end if out.length > 0
    out
  end
end
mark_new_cycle() click to toggle source

Only used when sync is +false: Mark the location in the log stream where a new update/write run begins.

# File lib/webgen/logger.rb, line 49
def mark_new_cycle
  if !@sync
    @marks << @logio.string.length
  end
end
stdout(source='', &block) click to toggle source

Utiltity method for writing a normal output message.

# File lib/webgen/logger.rb, line 89
def stdout(source='', &block); log(:stdout, source, &block); end
verbose(source='', &block) click to toggle source

Utiltity method for writing a verbose output message.

# File lib/webgen/logger.rb, line 92
def verbose(source='', &block); log(:verbose, source, &block); end
warn(source='', &block) click to toggle source

Utiltity method for logging a warning message.

# File lib/webgen/logger.rb, line 80
def warn(source='', &block); log(:warn, source, &block); end

[Validate]

Generated with the Darkfish Rdoc Generator 2.