lib/sitefuel/SiteFuelLogger.rb in sitefuel-0.0.0b vs lib/sitefuel/SiteFuelLogger.rb in sitefuel-0.1.0a
- old
+ new
@@ -1,10 +1,10 @@
#
# File:: SiteFuelLogger.rb
# Author:: wkm
-# Copyright:: 2009
-# License:: GPL
+# Copyright:: 2009, Zanoccio LLC.
+# License:: GPL version 2.0 (see LICENSE.rb)
#
module SiteFuel
require 'logger'
@@ -38,10 +38,11 @@
#
# default:: use the Logger logging style
# clean:: gives a clean logging output intended for human use
attr_accessor :log_style
+
def initialize(filename = STDOUT)
super(filename)
@fatal_count = 0
@error_count = 0
@@ -52,35 +53,41 @@
self.level = WARN
@log_style = :default
@progname = 'SiteFuel'
end
+
def fatal(*args)
@fatal_count += 1
super(*args)
end
+
def error(*args)
@error_count += 1
super(*args)
end
+
def warn(*args)
@warn_count += 1
super(*args)
end
+
def info(*args)
@info_count += 1
super(*args)
end
+
def debug(*args)
@debug_count += 1
super(*args)
end
+
# implement our own #add so we can have cleaner logs
def format_message(severity, date_time, program_name, msg)
case @log_style
when :default
super(severity, date_time, program_name, msg)
@@ -92,37 +99,59 @@
string = bold(red(string))
when 'WARN'
string = yellow(string)
- when 'DEBUG'
- string = string
+ when 'INFO', 'DEBUG'
+ string = dark(string)
end
string
end
end
end
+
+
# mixin for adding logging functionality to any class, typically included
# by every SiteFuel class
module Logging
# sets the logger for a class
def logger=(logger)
@logger = logger
end
+
# adds a fatal error to the log
def fatal(*args) @logger.fatal(*args); end
-
+
+
# adds an error to the log
def error(*args) @logger.error(*args); end
+
# adds a warning to the log
def warn(*args) @logger.warn(*args); end
+
# adds an info message to the log
def info(*args) @logger.info(*args); end
+
# adds a debugging message to the log
def debug(*args) @logger.debug(*args); end
+ end
+
+
+
+ # module for extending classes and thus giving class methods logging
+ # capability
+ module ClassLogging
+ @@logger = SiteFuelLogger.instance
+
+ def fatal(*args) @@logger.fatal(*args); end
+ def error(*args) @@logger.error(*args); end
+ def warn(*args) @@logger.warn(*args); end
+ def info(*args) @@logger.info(*args); end
+ def debug(*args) @@logger.debug(*args); end
+
end
end
\ No newline at end of file