Class: Locomotive::Steam::Logger

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



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

def initialize
  self.logger = nil
end

Instance Attribute Details

#logfile_pathObject

Returns the value of attribute logfile_path.



6
7
8
# File 'lib/locomotive/steam/logger.rb', line 6

def logfile_path
  @logfile_path
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/locomotive/steam/logger.rb', line 6

def logger
  @logger
end

#stdoutObject

Returns the value of attribute stdout.



6
7
8
# File 'lib/locomotive/steam/logger.rb', line 6

def stdout
  @stdout
end

Class Method Details

.instanceObject



35
36
37
# File 'lib/locomotive/steam/logger.rb', line 35

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

.setup(path, stdout = false) ⇒ Object



39
40
41
# File 'lib/locomotive/steam/logger.rb', line 39

def self.setup(path, stdout = false)
  self.instance.setup(path, stdout)
end

Instance Method Details

#setup(path, stdout = false) ⇒ Object

Setup the single instance of the ruby logger.

Parameters:

  • path (String)

    The path to the log file (default: log/steam.log)

  • stdout (Boolean) (defaults to: false)

    Instead of having a file, log to the standard output



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/locomotive/steam/logger.rb', line 17

def setup(path, stdout = false)
  require 'logger'

  self.stdout = stdout

  self.logfile_path = File.expand_path(File.join(path, 'log', 'steam.log'))
  FileUtils.mkdir_p(File.dirname(logfile_path))

  out = self.stdout ? STDOUT : self.logfile_path

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