Log printing – Object extension

Methods for printing output of Cuby programs. Supports different verbosity levels.

The module is automatically mixed into Object.

Constants

Five verbosity levels are introduced:

Global variables

Global variable storing the verbosity level is defined: $verbosity

Default level is V_VERBOSE. If the Cuby.config object exists, the program attempts to read verbosity from Cuby.config['verbosity'], using eval to read both numbers and constants.

module CubyLog

Verbosity setter

set_verbosity(level)

Sets the verbosity safely, checking whether the number is in the bounds

Ascii art

print_cuby_logo(text='',verbosity_limit=V_VERBOSE)

Prints Cuby logo in ascii art (when $verbosity > verbosity_limit)

print_cuby_logo('text')
      _______
     /\______\
    / /      /
   / / Cuby /   text
   \/______/

lputs(object)

Wrapper for puts (for possible redirection of output)

puts_hash(strings = {})

Prints string indexed by current verbosity level

$verbosity = V_BRIEF
puts_hash(V_BRIEF => "Yes!", V_VERBOSE => "blah blah blah...")
Yes!

puts_hash_or_lower(strings = {})

Prints string indexed by current verbosity level or at closest lower level

$verbosity = V_BRIEF
puts_hash_or_lower(V_MINIMAL => "!", V_VERBOSE => "blah blah blah...")
!

Log puts when verbosity >= selected level

Collection of methods hat print to output only when $verbosity is equal or higher than desired.

puts_minimal(object)

puts_brief(object)

puts_verbose(object)

puts_debug(object)

Log puts when verbosity == selected level

Collection of methods hat print to output only when $verbosity is equal than desired.

puts_minimal_only(object)

puts_brief_only(object)

puts_verbose_only(object)

puts_debug_only(object)