lib/syslogger.rb in syslogger-1.2.1 vs lib/syslogger.rb in syslogger-1.2.2
- old
+ new
@@ -1,11 +1,11 @@
require 'syslog'
require 'logger'
class Syslogger
- VERSION = "1.2.1"
+ VERSION = "1.2.2"
attr_reader :level, :ident, :options, :facility
MAPPING = {
Logger::DEBUG => Syslog::LOG_DEBUG,
@@ -69,10 +69,12 @@
# +progname+:: optionally, a overwrite the program name that appears in the log message.
def add(severity, message = nil, progname = nil, &block)
progname ||= @ident
Syslog.open(progname, @options, @facility) { |s|
s.mask = Syslog::LOG_UPTO(MAPPING[@level])
- s.log(MAPPING[severity], (message || block.call).to_s)
+ # substitute '%' for '%%' before logging
+ # so that syslog won't complain about malformed characters
+ s.log(MAPPING[severity], (message || block.call).to_s.gsub(/%/, '%%'))
}
end
# Sets the minimum level for messages to be written in the log.
# +level+:: one of <tt>Logger::DEBUG</tt>, <tt>Logger::INFO</tt>, <tt>Logger::WARN</tt>, <tt>Logger::ERROR</tt>, <tt>Logger::FATAL</tt>, <tt>Logger::UNKNOWN</tt>
\ No newline at end of file