Skip to content

Commit

Permalink
[ruby/logger] Another performance improvement on the Formatter by
Browse files Browse the repository at this point in the history
using Kernel#sprintf over String#%
(ruby/logger#75)

* Prefer Kernel#sprintf over String#% for formatting Strings
  • Loading branch information
amatsuda authored and matzbot committed Dec 8, 2022
1 parent 7ab4820 commit 7e121dc
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/logger/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Logger
# Default formatter for log messages.
class Formatter
Format = "%s, [%s #%d] %5s -- %s: %s\n"
Format = "%.1s, [%s #%d] %5s -- %s: %s\n"
DatetimeFormat = "%Y-%m-%dT%H:%M:%S.%6N"

attr_accessor :datetime_format
Expand All @@ -13,8 +13,7 @@ def initialize
end

def call(severity, time, progname, msg)
Format % [severity[0, 1], format_datetime(time), Process.pid, severity, progname,
msg2str(msg)]
sprintf(Format, severity, format_datetime(time), Process.pid, severity, progname, msg2str(msg))
end

private
Expand Down

0 comments on commit 7e121dc

Please sign in to comment.