lib/logging.rb in lorj-1.0.3 vs lib/logging.rb in lorj-1.0.4
- old
+ new
@@ -150,18 +150,12 @@
@out_logger.error(message + ANSI.clear_eol)
@file_logger.error(message + "\n" + caller.join("\n"))
end
# Log to STDOUT and Log file and FATAL class message
- # fatal retrieve the caller list of functions and save it to the log file if
- # the exception class is given.
- # The exception class should provide message and backtrace.
- def fatal(message, e = nil)
+ def fatal(message)
@out_logger.fatal(message + ANSI.clear_eol)
- return @file_logger.fatal(format("%s\n%s\n%s",
- message, e.message,
- e.backtrace.join("\n"))) if e
@file_logger.fatal(message)
end
# Log to STDOUT and Log file and WARNING class message
def warn(message)
@@ -182,22 +176,15 @@
end
private
def file_logger_initialize
- log_file = PrcLib.log_file
- if log_file.nil?
- default_log_file = format('%s.log', PrcLib.app_name)
- log_file = File.join(PrcLib.data_path, default_log_file)
- end
-
- @file_logger = Logger.new(log_file, 'weekly')
+ @file_logger = Logger.new(PrcLib.log_file, 'weekly')
@file_logger.level = Logger::DEBUG
@file_logger.formatter = proc do |severity, datetime, progname, msg|
"#{progname} : #{datetime}: #{severity}: #{msg} \n"
end
- PrcLib.log_file = log_file
end
end
module_function
@@ -258,15 +245,15 @@
# with a return code.
# fatal retrieve the caller list of functions and save it to the log file if
# the exception class is given.
# The exception class should provide message and backtrace.
def fatal(rc, message, *p)
- e = nil
if p.length > 0 && p[-1].is_a?(Exception)
e = p[-1]
p.pop
+ message = format("%s\n%s\n%s", message, e.message, e.backtrace.join("\n"))
end
- log_object.fatal(format(message, *p), e)
+ log_object.fatal(format(message, *p))
puts format('Issues found. Please fix it and retry. Process aborted. '\
"See details in log file '%s'.", PrcLib.log_file)
exit rc
end