lib/logging/appenders/remote-syslog.rb in logging-remote-syslog-0.0.2 vs lib/logging/appenders/remote-syslog.rb in logging-remote-syslog-0.0.3

- old
+ new

@@ -77,10 +77,12 @@ 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) + @strip_colors = opts.getopt(:strip_colors, true) + facility_name = opts.getopt(:facility, 'user') @facility = ::SyslogProtocol::FACILITIES[facility_name] # provides a mapping from the default Logging levels @@ -114,11 +116,18 @@ map[num] = syslog_level_num(levels[lvl]) end @map = map end + def strip_ansi_colors(message) + message.gsub /\\e\[?.*?[\@-~]/, '' + end + def prepare_message(message) + @strip_colors ? strip_ansi_colors(message) : message + end + private # call-seq: # write( event ) # @@ -142,10 +151,10 @@ :facility => @facility, :severity => pri, :program => @ident ) - udp_sender.write(message) + udp_sender.write(prepare_message(message)) self end # call-seq: