Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/logging/layouts/pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def self.pattern( *args )
# [p] Used to output the process ID of the currently running program.
# [r] Used to output the number of milliseconds elapsed from the
# construction of the Layout until creation of the log event.
# [R] Used to output the number of seconds (with milliseconds) elapsed
# between the construction of the Layout and the creation of the log
# event formatted like #.#### (always 4 decimal places).
# [t] Used to output the object ID of the thread that generated the
# log event.
# [T] Used to output the name of the thread that generated the log event.
Expand Down Expand Up @@ -311,6 +314,7 @@ class FormatMethodBuilder
'h' => "'#{Socket.gethostname}'".freeze,
'p' => 'Process.pid'.freeze,
'r' => 'Integer((event.time-@created_at)*1000).to_s'.freeze,
'R' => 'Kernel.format("%.4f", event.time-@created_at)'.freeze,
't' => 'Thread.current.object_id.to_s'.freeze,
'T' => 'Thread.current[:name]'.freeze,
'X' => :placeholder,
Expand All @@ -326,6 +330,7 @@ class FormatMethodBuilder
'h' => :hostname,
'p' => :pid,
'r' => :time,
'R' => :time,
'T' => :thread,
't' => :thread_id,
'F' => :file,
Expand Down
3 changes: 3 additions & 0 deletions test/layouts/test_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def test_pattern_all
@layout.pattern = '%r'
assert_match %r/\A\d+\z/, @layout.format(event)

@layout.pattern = '%R'
assert_match %r/\A\d+\.\d{4}\z/, @layout.format(event)

@layout.pattern = '%t'
assert_match %r/\A-?\d+\z/, @layout.format(event)

Expand Down