class LyberCore::Log
Constants
- DEFAULT_FORMATTER
- DEFAULT_LOGFILE
Default values
- DEFAULT_LOG_LEVEL
Public Class Methods
debug(msg)
click to toggle source
# File lib/lyber_core/log.rb, line 91 def Log.debug(msg) @@log.add(Logger::DEBUG) { msg } end
error(msg)
click to toggle source
# File lib/lyber_core/log.rb, line 79 def Log.error(msg) @@log.add(Logger::ERROR) { msg } end
exception(exc)
click to toggle source
# File lib/lyber_core/log.rb, line 95 def Log.exception(exc) msg = Log.exception_message(exc) Log.error(msg) end
exception_message(exc)
click to toggle source
# File lib/lyber_core/log.rb, line 100 def Log.exception_message(exc) msg = exc.inspect.split($/).join('; ') + "\n" msg << exc.backtrace.join("\n") if exc.backtrace end
fatal(msg)
click to toggle source
# File lib/lyber_core/log.rb, line 75 def Log.fatal(msg) @@log.add(Logger::FATAL) { msg } end
info(msg)
click to toggle source
# File lib/lyber_core/log.rb, line 87 def Log.info(msg) @@log.add(Logger::INFO) { msg } end
level()
click to toggle source
Return the current log level
# File lib/lyber_core/log.rb, line 71 def Log.level @@log.level end
logfile()
click to toggle source
The current location of the logfile
# File lib/lyber_core/log.rb, line 30 def Log.logfile @@logfile end
restore_defaults()
click to toggle source
Restore LyberCore::Log
to its default state
# File lib/lyber_core/log.rb, line 23 def Log.restore_defaults @@log.level = DEFAULT_LOG_LEVEL Log.set_logfile(DEFAULT_LOGFILE) @@log.formatter = DEFAULT_FORMATTER end
set_level(loglevel)
click to toggle source
Set the log level. See ruby-doc.org/core/classes/Logger.html for more info. Possible values are:
Logger::FATAL (4): an unhandleable error that results in a program crash Logger::ERROR (3): a handleable error condition Logger::WARN (2): a warning Logger::INFO (1): generic (useful) information about system operation Logger::DEBUG (0): low-level information for developers
# File lib/lyber_core/log.rb, line 57 def Log.set_level(loglevel) if [0, 1, 2, 3, 4].include? loglevel @@log.level = loglevel @@log.debug "Setting LyberCore::Log.level to #{loglevel}" else @@log.warn "I received an invalid option for log level. I expected a number between 0 and 4 but I got #{loglevel}" @@log.warn "I'm setting the loglevel to 0 (debug) because you seem to be having trouble." @@log.level = 0 end rescue Exception => e raise e, "Couldn't set log level because\n#{e.message}: #{e.backtrace.join(%(\n))}" end
set_logfile(new_logfile)
click to toggle source
Accepts a filename as an argument, and checks to see whether that file can be opened for writing. If it can be opened, it closes the existing Logger object and re-opens it with the new logfile location. It raises an exception if it cannot write to the specified logfile.
# File lib/lyber_core/log.rb, line 38 def Log.set_logfile(new_logfile) current_log_level = @@log.level current_formatter = @@log.formatter @@log = Logger.new(new_logfile) @@logfile = new_logfile @@log.level = current_log_level @@log.formatter = current_formatter rescue Exception => e raise e, "Couldn't initialize logfile #{new_logfile} because\n#{e.message}: #{e.backtrace.join(%(\n))}}" end
warn(msg)
click to toggle source
# File lib/lyber_core/log.rb, line 83 def Log.warn(msg) @@log.add(Logger::WARN) { msg } end