[ruby/logger] Another performance improvement on the Formatter by

using Kernel#sprintf over String#%
(https://github.com/ruby/logger/pull/75)

* Prefer Kernel#sprintf over String#% for formatting Strings
This commit is contained in:
Akira Matsuda 2022-12-08 12:31:30 +09:00 коммит произвёл git
Родитель 7ab4820af7
Коммит 7e121dc4a8
1 изменённых файлов: 2 добавлений и 3 удалений

Просмотреть файл

@ -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
@ -13,8 +13,7 @@ class Logger
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