Module: Libis::Tools::Logger
- Defined in:
- lib/libis/tools/logger.rb
Overview
The Logger module adds logging functionality to any class.
Just include the ::Libis::Tools::Logger module and the methods debug, info, warn, error and fatal will be available to the class instance. Each method takes a message argument and optional extra parameters.
The methods all call the #message method with the logging level as first argument and the supplied arguments appended.
Class Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/libis/tools/logger.rb', line 19 def self.included(klass) klass.class_eval do def debug(msg, *args) return if (self.[:quiet] rescue false) ::Logger::DEBUG, msg, *args end def info(msg, *args) return if (self.[:quiet] rescue false) ::Logger::INFO, msg, *args end def warn(msg, *args) return if (self.[:quiet] rescue false) ::Logger::WARN, msg, *args end def error(msg, *args) ::Logger::ERROR, msg, *args end def fatal(msg, *args) ::Logger::FATAL, msg, *args end # The method that performs the code logging action. # # If extra arguments are supplied, the message string is expected to be a format specification string and the # extra arguments will be applied to it. # # This default message method implementation uses the logger of ::Libis::Tools::Config. If an 'appname' # parameter is defined in the Config object, it will be used as program name by the logger, otherwise the # class name is taken. # # @param [{::Logger::Severity}] severity # @param [String] msg message string # @param [Object] args optional list of extra arguments def (severity, msg, *args) = (msg % args rescue ((msg + ' - %s') % args.to_s)) appname = Config.appname appname = self.name if self.respond_to? :name appname = self.class.name if appname.blank? Config.logger.add(severity, , appname) end end end |