lib/openwfe/logging.rb in openwferu-0.9.2 vs lib/openwfe/logging.rb in openwferu-0.9.3
- old
+ new
@@ -48,37 +48,56 @@
#
# A Mixin for adding logging method to any class
#
module Logging
- def init_default_logging (filename)
- log = Logger.new(filename)
- @application_context[S_LOGGER] = log
+ def ldebug (message=nil, &block)
+ do_log(:debug, message, &block)
end
- def ldebug (&block)
- log = get_logger
- log.debug(who(), &block) if log
+ def linfo (message=nil, &block)
+ do_log(:info, message, &block)
end
- def linfo (&block)
- log = get_logger
- log.info(who(), &block) if log
+ def lwarn (message=nil, &block)
+ do_log(:warn, message, &block)
end
- def lwarn (&block)
- log = get_logger
- log.warn(who(), &block) if log
+ def lerror (message=nil, &block)
+ do_log(:error, message, &block)
end
+ def lfatal (message=nil, &block)
+ do_log(:fatal, message, &block)
+ end
+
+ def lunknown (message=nil, &block)
+ do_log(:unknown, message, &block)
+ end
+
private
- def get_logger
- return @application_context[S_LOGGER] if @application_context
- return Logger.new(STDOUT)
+ def do_log (level, message, &block)
+
+ return unless $OWFE_LOG
+
+ logblock = lambda do
+ if block
+ "#{log_prepare(message)} - #{block.call}"
+ else
+ "#{log_prepare(message)}"
+ end
+ end
+
+ $OWFE_LOG.send level, &logblock
end
- def who
+ def log_prepare (message)
+ return log_author() if not message
+ return "#{log_author} - #{message}"
+ end
+
+ def log_author
if respond_to? :service_name
"#{self.class} '#{self.service_name}'"
else
"#{self.class}"
end