class DtkLogger

Constants

DEVELOPMENT_MODE
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/dtk_logger.rb, line 62
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/dtk_logger.rb, line 38
def initialize
  log_location_dir = DTK::Client::OsUtil.get_log_location()
  begin
    if File.directory?(log_location_dir)
      file = File.open(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/dtk_logger.rb, line 70
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/dtk_logger.rb, line 74
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/dtk_logger.rb, line 89
def error(log_text, sttdout_out=false)
  DTK::Client::OsUtil.print(log_text, :red) 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/dtk_logger.rb, line 94
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/dtk_logger.rb, line 107
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/dtk_logger.rb, line 100
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
file_path() click to toggle source
# File lib/dtk_logger.rb, line 57
def file_path()
  "#{DTK::Client::OsUtil.get_log_location()}/#{LOG_FILE_NAME}"
end
info(log_text, sttdout_out=false) click to toggle source
# File lib/dtk_logger.rb, line 79
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/dtk_logger.rb, line 84
def warn(log_text, sttdout_out=false)
  DTK::Client::OsUtil.print(log_text, :yellow) if sttdout_out || DEVELOPMENT_MODE
  @logger.warn(log_text) if log_created?
end

Private Instance Methods

log_created?() click to toggle source
# File lib/dtk_logger.rb, line 114
def log_created?
  #no log found if @logger.nil?
  return !@logger.nil?
end
no_log_dir(dir) click to toggle source
# File lib/dtk_logger.rb, line 119
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/dtk_logger.rb, line 123
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