Class: Twitterpunch::Logger

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Logger

Returns a new instance of Logger.



8
9
10
11
12
13
# File 'lib/twitterpunch/logger.rb', line 8

def initialize(config)
  @options = config
  @logger  = ::Logger.new(File.expand_path(config[:logfile]))

  @logger.level = config[:debug] ? ::Logger::DEBUG : ::Logger::INFO
end

Instance Method Details

#debug(message) ⇒ Object



20
21
22
23
24
# File 'lib/twitterpunch/logger.rb', line 20

def debug(message)
  return unless @options[:debug]
  puts message.yellow
  @logger.debug(message)
end

#error(message) ⇒ Object



15
16
17
18
# File 'lib/twitterpunch/logger.rb', line 15

def error(message)
  puts message.red
  @logger.error(message)
end

#info(message) ⇒ Object



26
27
28
# File 'lib/twitterpunch/logger.rb', line 26

def info(message)
  puts message.green unless @options[:quiet]
end

#log(username, message) ⇒ Object



30
31
32
# File 'lib/twitterpunch/logger.rb', line 30

def log(username, message)
  @logger.info(sprintf("%15s: %s", username, message))
end