Parent

Class 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 19
19:     def initialize(outdev=$stdout, sync=false)
20:       @sync = sync
21:       @outdev = outdev
22:       @logger = (@sync ? ::Logger.new(@outdev) : ::Logger.new(@logio = StringIO.new))
23:       @logger.formatter = Proc.new do |severity, timestamp, progname, msg|
24:         if self.level == ::Logger::DEBUG
25:           "%5s -- %s: %s\n" % [severity, progname, msg ]
26:         else
27:           "%5s -- %s\n" % [severity, msg]
28:         end
29:       end
30:       self.level = ::Logger::WARN
31:       self.verbosity = :normal
32:       @marks = []
33:     end

Public Instance Methods

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

Utiltity method for logging a debug message.

    # File lib/webgen/logger.rb, line 87
87:     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 78
78:     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 84
84:     def info(source='', &block); log(:info, source, &block); end
level() click to toggle source

The severity threshold level.

    # File lib/webgen/logger.rb, line 57
57:     def level
58:       @logger.level
59:     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 62
62:     def level=(value)
63:       @logger.level = value
64:     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 67
67:     def log(sev_level, source='', &block)
68:       if sev_level == :stdout
69:         @outdev.write(block.call + "\n") if @verbosity == :normal || @verbosity == :verbose
70:       elsif sev_level == :verbose
71:         @outdev.write(block.call + "\n") if @verbosity == :verbose
72:       else
73:         @logger.send(sev_level, source, &block)
74:       end
75:     end
log_output() click to toggle source

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

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

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

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

Utiltity method for writing a normal output message.

    # File lib/webgen/logger.rb, line 90
90:     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 93
93:     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 81
81:     def warn(source='', &block); log(:warn, source, &block); end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.