class Jellog::Slogger
This inner logger is used by Jellog
to encapsulate the ruby logger.
NOTE it uses a tiny touch of meta-magic to inherit all of the logging methods from Jellog
and then uses a very basic interface to the logger itself to protect it from other apps
Constants
- Levels
Default colour table
Public Class Methods
create a new logger with the given filename and following parameters. Note that there are no defaults. It is expected that these values will be set by {Jellog::Config}
@param [String] logfilename path to log file to create @param [Boolean] reset the log when opening, deleting any previous content @param [Integer] max_logs number of log files to maintain @param [Integer] max-size in megabytes being the max length of log file @param [Boolean] coloured colour logs or not @param [String] format - strftime format for time stamps @param [Boolean] sync - flag to sync the logfile or not
# File lib/jellog/logger.rb, line 44 def initialize(logfilename, reset, max_logs, max_size, coloured, format, sync) file_mode = reset ? "w" : "a" @logfile = File.open(logfilename, file_mode) @logfile.sync = sync @logger = ::Logger.new(@logfile, max_logs, max_size) @format_str = format || "%Y-%m-%d %H:%M:%S" @coloured = coloured @colours = Levels end
Public Instance Methods
close the log file
# File lib/jellog/logger.rb, line 62 def close @logfile.close end
change the colour lookup. See {Jellog::Logger} for details
@param [Hash] colour_hash - maps logging methods to colours
# File lib/jellog/logger.rb, line 57 def colours=(colour_hash) @colours = Levels.merge(colour_hash) end
handle logging methods as required
# File lib/jellog/logger.rb, line 67 def method_missing(meth, msg) raise NoMethodError unless @colours.has_key?(meth) #meth = :info if meth == :system tstamp = Time.now.strftime(@format_str) prefix = "[#{tstamp}] #{meth.to_s.upcase}" prefix = prefix.send(@colours[meth]) if @coloured prefix = prefix.send(:bold) if @coloured && (meth == :fatal || meth == :mark) @logger << prefix + " - #{msg}\n" end