This class provides an Appender that can send notifications to the Growl notification system on Mac OS X.
growlnotify
must be installed somewhere in the path in order
for the appender to function properly.
Create an appender that will log messages to the Growl framework on a Mac OS X machine.
# File lib/logging/appenders/growl.rb, line 29 def initialize( name, opts = {} ) super @growl = "growlnotify -w -n \"#{@name}\" -t \"%s\" -m \"%s\" -p %d &" @coalesce = opts.getopt(:coalesce, false) @title_sep = opts.getopt(:separator) # provides a mapping from the default Logging levels # to the Growl notification levels @map = [-2, -1, 0, 1, 2] map = opts.getopt(:map) self.map = map unless map.nil? setup_coalescing if @coalesce # make sure the growlnotify command can be called unless system('growlnotify -v >> /dev/null 2>&1') self.level = :off ::Logging.log_internal {'growl notifications have been disabled'} end end
Configure the mapping from the Logging levels to the Growl notification levels. This is needed in order to log events at the proper Growl level.
Without any configuration, the following mapping will be used:
:debug => -2 :info => -1 :warn => 0 :error => 1 :fatal => 2
# File lib/logging/appenders/growl.rb, line 67 def map=( levels ) map = [] levels.keys.each do |lvl| num = ::Logging.level_num(lvl) map[num] = growl_level_num(levels[lvl]) end @map = map end