Class: Rpush::Logger

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Logger

Returns a new instance of Logger.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rpush/logger.rb', line 3

def initialize(options)
  @options = options

  begin
    log_dir = File.join(Rails.root, 'log')
    FileUtils.mkdir_p(log_dir)
    log = File.open(File.join(log_dir, 'rpush.log'), 'a')
    log.sync = true
    setup_logger(log)
  rescue Errno::ENOENT, Errno::EPERM => e
    @logger = nil
    error(e)
    error('Logging disabled.')
  end
end

Instance Method Details

#error(msg) ⇒ Object



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

def error(msg)
  log(:error, msg, 'ERROR', STDERR)
end

#info(msg) ⇒ Object



19
20
21
# File 'lib/rpush/logger.rb', line 19

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

#warn(msg) ⇒ Object



27
28
29
# File 'lib/rpush/logger.rb', line 27

def warn(msg)
  log(:warn, msg, 'WARNING', STDERR)
end