Class: Webgen::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/webgen/logger.rb

Overview

This custom logger class needs to be used (either directly or via a sub-class) for the Webgen::Website logging object.

It provides the following, additional functionality over the stdlib Logger class:

  • If a logging message is an Array and #verbose is false, only the first item of the array is output. If #verbose is true, the the items of the array are joined using a line break and output.

  • You can add verbose info messages using the #vinfo method.

Direct Known Subclasses

CLI::Logger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Logger

:nodoc:



23
24
25
26
# File 'lib/webgen/logger.rb', line 23

def initialize(*args, &block) #:nodoc:
  super
  @verbose = false
end

Instance Attribute Details

#verboseObject

Whether verbose log message should be output. Either true or false (default: false).



21
22
23
# File 'lib/webgen/logger.rb', line 21

def verbose
  @verbose
end

Instance Method Details

#format_message(severity, datetime, progname, msg) ⇒ Object

:nodoc:



28
29
30
31
32
# File 'lib/webgen/logger.rb', line 28

def format_message(severity, datetime, progname, msg) #:nodoc:
  first, *rest = *msg
  msg = (@verbose ? [first, *rest].join("\n") : first)
  super(severity, datetime, progname, msg)
end

#vinfo(progname = nil, &block) ⇒ Object

Log a verbose info message.



35
36
37
# File 'lib/webgen/logger.rb', line 35

def vinfo(progname = nil, &block)
  add(::Logger::INFO, nil, progname, &block) if @verbose
end