Class: Locomotive::Common::Logger

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



10
11
12
# File 'lib/locomotive/common/logger.rb', line 10

def initialize
  self.logger = nil
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/locomotive/common/logger.rb', line 8

def logger
  @logger
end

Class Method Details

.instanceObject



38
39
40
# File 'lib/locomotive/common/logger.rb', line 38

def self.instance
  @@instance ||= self.new
end

.setup(*args) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/locomotive/common/logger.rb', line 42

def self.setup *args
  if args.size > 1
    puts "[DEPRECATION] Logger.setup(path, stdout=false) is deprecated. " \
      "Please use Logger.setup(log_file_full_path) instead, " \
      "like: /home/locomotivecms/log/server.log"
  end
  self.instance.setup args.first
end

Instance Method Details

#setup(log_file_full_path = nil) ⇒ Object

Setup the single instance of the ruby logger.

@param[ optional ] [ String ] path The path to the log file, full path with log file name Sample /home/locomotivecms/log/server.log (default: nil => Stdout)



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/locomotive/common/logger.rb', line 19

def setup log_file_full_path=nil
  require 'logger'

  output = begin
    if log_file_full_path
      log_file_path log_file_full_path
    else
      STDOUT
    end
  end

  self.logger = ::Logger.new(output).tap do |log|
    log.level = ::Logger::DEBUG
    log.formatter = proc do |severity, datetime, progname, msg|
      "#{msg}\n"
    end
  end
end