mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[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.
7cbd434349
This commit is contained in:
parent
cc5fcae170
commit
a8b11b5cdd
1 changed files with 3 additions and 2 deletions
|
@ -3,7 +3,8 @@
|
||||||
class Logger
|
class Logger
|
||||||
# Default formatter for log messages.
|
# Default formatter for log messages.
|
||||||
class Formatter
|
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
|
attr_accessor :datetime_format
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ class Logger
|
||||||
private
|
private
|
||||||
|
|
||||||
def format_datetime(time)
|
def format_datetime(time)
|
||||||
time.strftime(@datetime_format || "%Y-%m-%dT%H:%M:%S.%6N ")
|
time.strftime(@datetime_format || DatetimeFormat)
|
||||||
end
|
end
|
||||||
|
|
||||||
def msg2str(msg)
|
def msg2str(msg)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue