Object
The class used by a Website to do the logging and the normal output.
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
Utiltity method for logging a debug message.
# File lib/webgen/logger.rb, line 86 def debug(source='', &block); log(:debug, source, &block); end
Utiltity method for logging an error message.
# File lib/webgen/logger.rb, line 77 def error(source='', &block); log(:error, source, &block); end
Utiltity method for logging an informational message.
# File lib/webgen/logger.rb, line 83 def info(source='', &block); log(:info, source, &block); end
The severity threshold level.
# File lib/webgen/logger.rb, line 56 def level @logger.level end
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 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
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
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
Utiltity method for writing a normal output message.
# File lib/webgen/logger.rb, line 89 def stdout(source='', &block); log(:stdout, source, &block); end
Generated with the Darkfish Rdoc Generator 2.