[前][次][番号順一覧][スレッド一覧]

ruby-changes:70291

From: Baron <ko1@a...>
Date: Sat, 18 Dec 2021 09:31:05 +0900 (JST)
Subject: [ruby-changes:70291] a8b11b5cdd (master): [ruby/logger] Changes to datetime formatting

https://git.ruby-lang.org/ruby.git/commit/?id=a8b11b5cdd

From a8b11b5cdd5fedd30a65e60bdae4c00d259d4191 Mon Sep 17 00:00:00 2001
From: Baron Bloomer <baronbloomer@g...>
Date: Thu, 29 Jul 2021 09:31:33 +0100
Subject: [ruby/logger] Changes to datetime formatting

Formatting a datetime should only pertain to itself and valid datetimes do not contain a space. Should there be a desire to show show a space between the datetime and the process pid in the formatted log, this formatting logic should take place there.
Furthermore, the default datetime format is moved to a class variable to allowing this variable to be overwritten by subclasses.

https://github.com/ruby/logger/commit/7cbd434349
---
 lib/logger/formatter.rb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/logger/formatter.rb b/lib/logger/formatter.rb
index 6a135b6fabb..62bff7097aa 100644
--- a/lib/logger/formatter.rb
+++ b/lib/logger/formatter.rb
@@ -3,7 +3,8 @@ https://github.com/ruby/ruby/blob/trunk/lib/logger/formatter.rb#L3
 class Logger
   # Default formatter for log messages.
   class Formatter
-    Format = "%s, [%s#%d] %5s -- %s: %s\n"
+    Format = "%s, [%s #%d] %5s -- %s: %s\n"
+    DatetimeFormat = "%Y-%m-%dT%H:%M:%S.%6N"
 
     attr_accessor :datetime_format
 
@@ -19,7 +20,7 @@ class Logger https://github.com/ruby/ruby/blob/trunk/lib/logger/formatter.rb#L20
   private
 
     def format_datetime(time)
-      time.strftime(@datetime_format || "%Y-%m-%dT%H:%M:%S.%6N ")
+      time.strftime(@datetime_format || DatetimeFormat)
     end
 
     def msg2str(msg)
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]