class Locomotive::Common::Logger

Attributes

logger[RW]

Public Class Methods

close() click to toggle source
# File lib/locomotive/common/logger.rb, line 49
def self.close
  instance.logger.close
end
instance() click to toggle source
# File lib/locomotive/common/logger.rb, line 36
def self.instance
  @@instance ||= new
end
new() click to toggle source
# File lib/locomotive/common/logger.rb, line 10
def initialize
  self.logger = nil
end
setup(*args) click to toggle source
# File lib/locomotive/common/logger.rb, line 40
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
  instance.setup args.first
end

Public Instance Methods

setup(log_file_full_path = nil) click to toggle source

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)

# File lib/locomotive/common/logger.rb, line 19
def setup(log_file_full_path = nil)
  require 'logger'

  output = if log_file_full_path
             log_file_path log_file_full_path
           else
             $stdout
           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

Private Instance Methods

log_file_path(log_file_full_path) click to toggle source
# File lib/locomotive/common/logger.rb, line 63
def log_file_path(log_file_full_path)
  if File.directory? log_file_full_path
    puts '[DEPRECATION] Please use fully log file path like: /home/locomotivecms/log/server.log'
    File.expand_path(File.join(log_file_full_path, 'log', 'locomotivecms.log'))
  else
    log_file_full_path
  end.tap { |path| FileUtils.mkdir_p(File.dirname(path)) }
end