Class: Howzit::ConsoleLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/howzit/console_logger.rb

Overview

Console logging

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level = nil) ⇒ ConsoleLogger

Init the console logging object

Parameters:

  • level (Integer) (defaults to: nil)

    log level



21
22
23
# File 'lib/howzit/console_logger.rb', line 21

def initialize(level = nil)
  @log_level = level.to_i || Howzit.options[:log_level]
end

Instance Attribute Details

#log_levelObject

Returns the value of attribute log_level.



14
15
16
# File 'lib/howzit/console_logger.rb', line 14

def log_level
  @log_level
end

Instance Method Details

#debug(msg) ⇒ Object

Write a message at debug level

Parameters:

  • msg

    The message



50
51
52
# File 'lib/howzit/console_logger.rb', line 50

def debug(msg)
  write msg, :debug
end

#error(msg) ⇒ Object

Write a message at error level

Parameters:

  • msg

    The message



77
78
79
# File 'lib/howzit/console_logger.rb', line 77

def error(msg)
  write msg, :error
end

#info(msg) ⇒ Object

Write a message at info level

Parameters:

  • msg

    The message



59
60
61
# File 'lib/howzit/console_logger.rb', line 59

def info(msg)
  write msg, :info
end

#reset_levelInteger

Get the log level from options

Returns:

  • (Integer)

    log level



30
31
32
# File 'lib/howzit/console_logger.rb', line 30

def reset_level
  @log_level = Howzit.options[:log_level]
end

#warn(msg) ⇒ Object

Write a message at warn level

Parameters:

  • msg

    The message



68
69
70
# File 'lib/howzit/console_logger.rb', line 68

def warn(msg)
  write msg, :warn
end

#write(msg, level = :info) ⇒ Object

Write a message to the console based on the urgency level and user's log level setting

Parameters:

  • msg (String)

    The message

  • level (Symbol) (defaults to: :info)

    The level



41
42
43
# File 'lib/howzit/console_logger.rb', line 41

def write(msg, level = :info)
  $stderr.puts msg if LOG_LEVELS[level] >= @log_level
end