Permalink
Browse files

escape % in log so that message with % and other control characters w…

…ill not crash
  • Loading branch information...
1 parent d1dbbc1 commit a6185899fcd1980b7c0e88b9ebdde281eedd434c @siuying committed Jul 30, 2012
Showing with 11 additions and 1 deletion.
  1. +1 −0 lib/logger/log.rb
  2. +1 −1 lib/logger/version.rb
  3. +9 −0 spec/log_spec.rb
View
1 lib/logger/log.rb
@@ -58,6 +58,7 @@ def __log(flag, message)
return unless logging?(flag)
raise ArgumentError, "flag must be one of #{FLAGS.keys}" unless FLAGS.keys.include?(flag)
async_enabled = self.async || (self.level == :error)
+ message = message.gsub('%', '%%')
log(async_enabled,
level:LEVELS[level],
View
2 lib/logger/version.rb
@@ -1,5 +1,5 @@
module Motion
module Logger
- VERSION = "0.1.2"
+ VERSION = "0.1.3"
end
end
View
9 spec/log_spec.rb
@@ -16,6 +16,15 @@
Log.removeAllLoggers
end
+ it "should escape %@ in logs" do
+ Log.warn "%@"
+ Log.flush
+
+ file = @file_logger.logFileManager.sortedLogFilePaths.first
+ logs = open(file).read
+ logs.should.include "%@"
+ end
+
describe "FileLogger" do
it "should log with specific levels" do
Log.level = :warn

0 comments on commit a618589

Please sign in to comment.