lib/logging/appenders/remote-syslog.rb in logging-remote-syslog-0.0.4 vs lib/logging/appenders/remote-syslog.rb in logging-remote-syslog-0.0.5
- old
+ new
@@ -32,10 +32,11 @@
#
# :ident => identifier string (name is used by default)
# :syslog_server => address of the remote syslog server
# :port => port of the remote syslog server
# :facility => the syslog facility to use
+ # :modifier => an optional callback method for altering original message; takes original message and returns updated one
#
# The parameter :ident is a string that will be prepended to every
# message. The :facility parameter encodes a default facility to be
# assigned to all messages that do not have an explicit facility encoded.
#
@@ -76,10 +77,11 @@
#
def initialize( name, opts = {} )
@ident = opts.getopt(:ident, name)
@syslog_server = opts.getopt(:syslog_server, '127.0.0.1')
@port = opts.getopt(:port, 514, :as => Integer)
+ @modifier = opts.getopt(:modifier)
@strip_colors = opts.getopt(:strip_colors, true)
facility_name = opts.getopt(:facility, 'user')
@@ -121,10 +123,12 @@
def strip_ansi_colors(message)
message.gsub /\e\[?.*?[\@-~]/, ''
end
def prepare_message(message)
- @strip_colors ? strip_ansi_colors(message) : message
+ message = @strip_colors ? strip_ansi_colors(message) : message
+ message = @modifier.call(message) if @modifier
+ message
end
private
# call-seq: