Class: Pushr::Daemon::Logger

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Logger

Returns a new instance of Logger.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pushr/daemon/logger.rb', line 4

def initialize(options)
  @options = options

  if @options[:foreground]
    STDOUT.sync = true
    @logger = ::Logger.new(STDOUT)
  else
    log_dir = File.join(Dir.pwd, 'log')
    FileUtils.mkdir_p(log_dir)
    log = File.open(File.join(log_dir, 'pushr.log'), 'a')
    log.sync = true
    @logger = ::Logger.new(log)
  end

  @logger.level = ::Logger::INFO
  @logger.formatter = proc do |severity, datetime, progname, msg|
    "[#{datetime}] #{severity}: #{msg}\n"
  end
end

Instance Method Details

#error(msg) ⇒ Object



28
29
30
31
# File 'lib/pushr/daemon/logger.rb', line 28

def error(msg)
  error_notification(msg)
  log(::Logger::ERROR, msg, 'ERROR')
end

#info(msg) ⇒ Object



24
25
26
# File 'lib/pushr/daemon/logger.rb', line 24

def info(msg)
  log(::Logger::INFO, msg)
end

#warn(msg) ⇒ Object



33
34
35
# File 'lib/pushr/daemon/logger.rb', line 33

def warn(msg)
  log(::Logger::WARN, msg, 'WARNING')
end