class DTK::Client::Logger

Constants

LOG_FILE_NAME
LOG_MB_SIZE
LOG_NUMBER_OF_OLD_FILES
LoggerMethods

Public Class Methods

method_missing(method, *args) click to toggle source
Calls superclass method
# File lib/client/logger.rb, line 55
def self.method_missing(method, *args)
  if LoggerMethods.include?(method)
    instance.send(method, *args)
  else
    super(method, *args)
  end
end
new() click to toggle source
# File lib/client/logger.rb, line 35
def initialize
  log_location_dir = log_dir
  begin
    if File.directory?(log_location_dir)
      file = File.open(log_file_path, 'a')
      file.sync = true
      @logger = ::Logger.new(file, LOG_NUMBER_OF_OLD_FILES, LOG_MB_SIZE * 1024000)
      
      @logger.formatter = proc do |severity, datetime, progname, msg|
        "[#{datetime}] #{severity} -- : #{msg}\n"
      end
    else
      no_log_dir(log_location_dir)
    end
  rescue Errno::EACCES
    no_log_permissions(log_location_dir)
  end
end
respond_to?(method) click to toggle source
Calls superclass method
# File lib/client/logger.rb, line 63
def self.respond_to?(method)
  LoggerMethods.include?(method) or super(method)
end

Public Instance Methods

debug(log_text, sttdout_out=false) click to toggle source
# File lib/client/logger.rb, line 67
def debug(log_text, sttdout_out=false)
  puts log_text if sttdout_out || development_mode?
  @logger.debug(log_text) if log_created?
end
error(log_text, sttdout_out=false) click to toggle source
# File lib/client/logger.rb, line 82
def error(log_text, sttdout_out=false)
  OsUtil.print_error(log_text) if sttdout_out || development_mode?
  @logger.error(log_text) if log_created?
end
error_pp(message, backtrace, sttdout_out = true) click to toggle source
# File lib/client/logger.rb, line 87
def error_pp(message, backtrace, sttdout_out = true)
  error(message, sttdout_out)
  # we do not print this to STDOUT (will be overriden with development_mode?)s
  error("#{message}\n" + PP.pp(backtrace, ""), false) if backtrace
end
fatal(log_text, sttdout_out=false) click to toggle source
# File lib/client/logger.rb, line 100
def fatal(log_text, sttdout_out=false)
  puts log_text if sttdout_out || development_mode?
  @logger.fatal(log_text) if log_created?
end
fatal_pp(message, backtrace, sttdout_out = true) click to toggle source
# File lib/client/logger.rb, line 93
def fatal_pp(message, backtrace, sttdout_out = true)
  fatal(message, sttdout_out)
  # we do not print this to STDOUT (will be overriden with development_mode?)
  fatal("#{message}\n" + PP.pp(backtrace, ""), false) if backtrace
end
info(log_text, sttdout_out=false) click to toggle source
# File lib/client/logger.rb, line 72
def info(log_text, sttdout_out=false)
  puts log_text if sttdout_out || development_mode?
  @logger.info(log_text) if log_created?
end
warn(log_text, sttdout_out=false) click to toggle source
# File lib/client/logger.rb, line 77
def warn(log_text, sttdout_out=false)
  OsUtil.print_warning(log_text) if sttdout_out || development_mode?
  @logger.warn(log_text) if log_created?
end

Private Instance Methods

development_mode?() click to toggle source
# File lib/client/logger.rb, line 115
def development_mode?
  unless @development_mode.nil?
    @development_mode
  else
    @development_mode = !!Config[:development_mode]
  end
end
log_created?() click to toggle source
# File lib/client/logger.rb, line 123
def log_created?
  #no log found if @logger.nil?
  return !@logger.nil?
end
log_dir() click to toggle source
# File lib/client/logger.rb, line 107
def log_dir
  DtkPath.log_dir
end
log_file_path() click to toggle source
# File lib/client/logger.rb, line 111
def log_file_path
  "#{log_dir}/#{LOG_FILE_NAME}"
end
no_log_dir(dir) click to toggle source
# File lib/client/logger.rb, line 128
def no_log_dir(dir)
  puts "[WARNING] Log directory (#{dir}) does not exist; please add it manually or re-install DTK client."
end
no_log_permissions(dir) click to toggle source
# File lib/client/logger.rb, line 132
def no_log_permissions(dir)
  puts "[WARNING] User (#{::DTK::Common::Aux.running_process_user}) does not have permissions to create a log file in log directory (#{dir})"
end