diff options
author | Josh N <josh@natanson.net> | 2020-08-03 08:54:15 -0400 |
---|---|---|
committer | Eric Wong <bofh@yhbt.net> | 2020-08-03 20:48:13 +0000 |
commit | 81cf3b2f31a55a2caf8222c6847ca8d9c01f8eee (patch) | |
tree | bae4b80a6583c6699015c295445b564267aa7243 /lib | |
parent | dde1e39757e2b0fdf0434fa2a3f32891213ea617 (diff) | |
download | clogger-81cf3b2f31a55a2caf8222c6847ca8d9c01f8eee.tar.gz |
This argument allows for conversion of response_time to microsecond or nanosecond by multiplying by a power of 10, up to a limit of 9. Defaults to 0 so backwards compatible.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/clogger.rb | 11 | ||||
-rw-r--r-- | lib/clogger/pure.rb | 1 |
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/clogger.rb b/lib/clogger.rb index be1bdce..7ce2b24 100644 --- a/lib/clogger.rb +++ b/lib/clogger.rb @@ -51,7 +51,7 @@ private SCAN = /([^$]*)(\$+(?:env\{\w+(?:\.[\w\.]+)?\}| e\{[^\}]+\}| - (?:request_)?time\{\d+\}| + (?:request_)?time\{\d+(?:,\d+)?\}| time_(?:utc|local)\{[^\}]+\}| \w*))?([^$]*)/x @@ -92,7 +92,14 @@ private when /\A\$time\{(\d+)\}\z/ rv << [ OP_TIME, *usec_conv_pair(tok, $1.to_i) ] when /\A\$request_time\{(\d+)\}\z/ - rv << [ OP_REQUEST_TIME, *usec_conv_pair(tok, $1.to_i) ] + rv << [ OP_REQUEST_TIME, *usec_conv_pair(tok, $1.to_i), 0 ] + when /\A\$request_time\{(\d+),(\d+)\}\z/ + ipow = $1.to_i + prec = $2.to_i + if ipow > 9 # nanosecond precision is the highest POSIX goes + raise ArgumentError, "#{tok}: too big: #{ipow} (max=9)" + end + rv << [ OP_REQUEST_TIME, *usec_conv_pair(tok, prec), ipow ] else tok_sym = tok[1..-1].to_sym if special_code = SPECIAL_VARS[tok_sym] diff --git a/lib/clogger/pure.rb b/lib/clogger/pure.rb index fddfe79..8f1f706 100644 --- a/lib/clogger/pure.rb +++ b/lib/clogger/pure.rb @@ -166,6 +166,7 @@ private when OP_TIME_UTC; Time.now.utc.strftime(op[1]) when OP_REQUEST_TIME t = mono_now - start + t = t * (10 ** op[3]) time_format(t.to_i, (t - t.to_i) * 1000000, op[1], op[2]) when OP_TIME t = Time.now |