clogger 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97fb2f9fb82bfc33a07ee55de5b946830c6562dc9fc9d11f5c75d89323f3543e
4
- data.tar.gz: 96062fd19c193f6b9a5418ebf237b2425966f56f23133ad389c19bf1de1ebcd1
3
+ metadata.gz: aa136dd8c34021aa1fe06bc527ddee6f0b2e3f1c6690292bba0566938efc11f4
4
+ data.tar.gz: c91b0dcb15b374bf6d89812b0dbcb002e9811b94a537465d96d5639191c55ab3
5
5
  SHA512:
6
- metadata.gz: '019753504c2aa28353ed40da5b4612ed9c6e8f94daa91fcfdc7090a7486d45a18448ae03cd75519f79a557b8e7dd576f0939f6e62ef1a65d928c5e9844aed503'
7
- data.tar.gz: b4c50eafffa057ccfae3dc9473a19f33a7f1efddf534dd73623002e2d4545daae19a4ea2e1156b539a5d32df56afac3eda351524eb49007a46ae50b936981a1b
6
+ metadata.gz: a3dc7e9f494fcd6acc52c82ba5f1c50d0bead5b5042189766f48f0229e595682c704f054a4d45ac5857a77a98c0c9d09e53c333f63a42e5c1232a2af9e1c1fe3
7
+ data.tar.gz: e72490ade869362cca1dd0df4cbd56c93c08a45f5baf32e88fd38b9a806b043286d1d58adaf3e31dae200a1f61f4e002b7f3e7bea15174d599af897609759cb2
@@ -6,7 +6,10 @@ public_email: clogger-public@yhbt.net
6
6
  ml_url:
7
7
  - https://yhbt.net/clogger-public/
8
8
  - http://ou63pmih66umazou.onion/clogger-public/
9
- - nntp://news.public-inbox.org/inbox.comp.lang.ruby.clogger
9
+ - imaps://news.public-inbox.org/inbox.comp.lang.ruby.clogger.0
10
+ - imap://ou63pmih66umazou.onion/inbox.comp.lang.ruby.clogger.0
11
+ - nntps://news.public-inbox.org/inbox.comp.lang.ruby.clogger
12
+ - nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.clogger
10
13
  source_code:
11
14
  - git clone git://yhbt.net/clogger.git
12
15
  - git clone https://yhbt.net/clogger.git
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v2.2.1
4
+ DEF_VER=v2.3.0
5
5
 
6
6
  LF='
7
7
  '
data/README CHANGED
@@ -69,10 +69,12 @@ that receives a "<<" method:
69
69
  * $request_uri - the URI requested ($path_info?$query_string)
70
70
  * $request - the first line of the HTTP request
71
71
  ($request_method $request_uri $http_version)
72
- * $request_time, $request_time{PRECISION} - time taken for request
73
- (including response body iteration). PRECISION defaults to 3
74
- (milliseconds) if not specified but may be specified anywhere from
75
- 0(seconds) to 6(microseconds).
72
+ * $request_time, $request_time{PRECISION}, $request_time{POWER,PRECISION} -
73
+ time taken for request (including response body iteration). PRECISION
74
+ defaults to 3 (milliseconds) if not specified but may be specified
75
+ anywhere from 0(seconds) to 6(microseconds). POWER will raise the time to
76
+ the provided power of 10, useful for converting to micro- or nanoseconds.
77
+ POWER defaults to 0 if not specified but may be specified any from 0 to 9
76
78
  * $time_iso8601 - current local time in ISO 8601 format,
77
79
  e.g. "1970-01-01T00:00:00+00:00"
78
80
  * $time_local - current local time in Apache log format,
@@ -87,7 +89,7 @@ that receives a "<<" method:
87
89
  * $ip - X-Forwarded-For request header if available, $remote_addr if not
88
90
  * $pid - process ID of the current process
89
91
  * $e{Thread.current} - Thread processing the request
90
- * $e{Actor.current} - Actor processing the request (Revactor or Rubinius)
92
+ * $e{Fiber.current} - Fiber processing the request
91
93
  * $env{variable_name} - any Rack environment variable (e.g. rack.url_scheme)
92
94
 
93
95
  == REQUIREMENTS
@@ -106,18 +108,30 @@ You may also browse and download snapshot tarballs:
106
108
  * https://yhbt.net/clogger.git
107
109
  * http://repo.or.cz/w/clogger.git (gitweb)
108
110
 
109
- The mailing list (see below) is central for coordination and
110
- development. Patches should always be sent inline
111
- (git format-patch -M + git send-email) so we can reply to them inline.
111
+ We use email for coordination and development, see below:
112
112
 
113
113
  == CONTACT
114
114
 
115
115
  All feedback (bug reports, user/development discussion, patches, pull
116
- requests) go to the public mailing list.
116
+ requests) is done via publicly-archived email:
117
117
 
118
- * mailto:clogger-public@yhbt.net
118
+ * https://yhbt.net/clogger-public/
119
+ * imaps://news.public-inbox.org/inbox.comp.lang.ruby.clogger.0
120
+ * nntps://news.public-inbox.org/inbox.comp.lang.ruby.clogger
121
+
122
+ Tor users may also access HTTP, IMAP, and NNTP archives via .onion:
123
+
124
+ * http://ou63pmih66umazou.onion/clogger-public/
125
+ * imap://ou63pmih66umazou.onion/inbox.comp.lang.ruby.clogger.0
126
+ * nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.clogger
119
127
 
120
- Do not send HTML mail or attachments. Do not top post.
128
+ AUTH=ANONYMOUS is supported for IMAP and IMAPS, and any
129
+ username + password will work.
130
+
131
+ No subscription or real names will ever be required to email us.
132
+ Do not send HTML email, do not top post.
133
+
134
+ * mailto:clogger-public@yhbt.net
121
135
 
122
136
  Homepage: https://yhbt.net/clogger/
123
137
 
@@ -1,3 +1,6 @@
1
+ /* quiet deprecation for _BSD_SOURCE and _SVID_SOURCE: */
2
+ #define _DEFAULT_SOURCE 1
3
+
1
4
  #include <ruby.h>
2
5
  #ifdef HAVE_RUBY_IO_H
3
6
  # include <ruby/io.h>
@@ -374,12 +377,40 @@ static void append_ts(struct clogger *c, VALUE op, struct timespec *ts)
374
377
  rb_str_buf_cat(c->log_buf, buf, nr);
375
378
  }
376
379
 
380
+ #define NANO_PER_SEC (1000 * 1000 * 1000)
377
381
  static void append_request_time_fmt(struct clogger *c, VALUE op)
378
382
  {
379
383
  struct timespec now;
384
+ unsigned long ipow = NUM2ULONG(rb_ary_entry(op, 3));
380
385
 
381
386
  clock_gettime(hopefully_CLOCK_MONOTONIC, &now);
382
387
  clock_diff(&now, &c->ts_start);
388
+ if (ipow) {
389
+ struct timespec prev;
390
+ unsigned long adj = 1;
391
+ /*
392
+ * n.b. timespec.tv_sec may not be time_t on some platforms,
393
+ * so we use a full timespec struct instead of time_t:
394
+ */
395
+ prev.tv_sec = now.tv_sec;
396
+ do { adj *= 10; } while (--ipow);
397
+ now.tv_sec *= adj;
398
+ now.tv_nsec *= adj;
399
+ if (now.tv_nsec >= NANO_PER_SEC) {
400
+ int64_t add = now.tv_nsec / NANO_PER_SEC;
401
+ now.tv_sec += add;
402
+ now.tv_nsec %= NANO_PER_SEC;
403
+ }
404
+ if (now.tv_sec < prev.tv_sec) { /* overflowed */
405
+ now.tv_nsec = NANO_PER_SEC - 1;
406
+ /*
407
+ * some platforms may use unsigned .tv_sec, but
408
+ * they're not worth supporting, so keep unsigned:
409
+ */
410
+ now.tv_sec = (time_t)(sizeof(now.tv_sec) == 4 ?
411
+ INT_MAX : LONG_MAX);
412
+ }
413
+ }
383
414
  append_ts(c, op, &now);
384
415
  }
385
416
 
@@ -51,7 +51,7 @@ private
51
51
 
52
52
  SCAN = /([^$]*)(\$+(?:env\{\w+(?:\.[\w\.]+)?\}|
53
53
  e\{[^\}]+\}|
54
- (?:request_)?time\{\d+\}|
54
+ (?:request_)?time\{\d+(?:,\d+)?\}|
55
55
  time_(?:utc|local)\{[^\}]+\}|
56
56
  \w*))?([^$]*)/x
57
57
 
@@ -92,7 +92,14 @@ private
92
92
  when /\A\$time\{(\d+)\}\z/
93
93
  rv << [ OP_TIME, *usec_conv_pair(tok, $1.to_i) ]
94
94
  when /\A\$request_time\{(\d+)\}\z/
95
- rv << [ OP_REQUEST_TIME, *usec_conv_pair(tok, $1.to_i) ]
95
+ rv << [ OP_REQUEST_TIME, *usec_conv_pair(tok, $1.to_i), 0 ]
96
+ when /\A\$request_time\{(\d+),(\d+)\}\z/
97
+ ipow = $1.to_i
98
+ prec = $2.to_i
99
+ if ipow > 9 # nanosecond precision is the highest POSIX goes
100
+ raise ArgumentError, "#{tok}: too big: #{ipow} (max=9)"
101
+ end
102
+ rv << [ OP_REQUEST_TIME, *usec_conv_pair(tok, prec), ipow ]
96
103
  else
97
104
  tok_sym = tok[1..-1].to_sym
98
105
  if special_code = SPECIAL_VARS[tok_sym]
@@ -166,6 +166,7 @@ private
166
166
  when OP_TIME_UTC; Time.now.utc.strftime(op[1])
167
167
  when OP_REQUEST_TIME
168
168
  t = mono_now - start
169
+ t = t * (10 ** op[3])
169
170
  time_format(t.to_i, (t - t.to_i) * 1000000, op[1], op[2])
170
171
  when OP_TIME
171
172
  t = Time.now
@@ -167,10 +167,11 @@ class TestClogger < Test::Unit::TestCase
167
167
  ary = compile_format(
168
168
  '$remote_addr - $remote_user [$time_local] ' \
169
169
  '"$request" $status $body_bytes_sent "$http_referer" ' \
170
- '"$http_user_agent" "$http_cookie" $request_time ' \
170
+ '"$http_user_agent" "$http_cookie" $request_time $request_time{6,0} ' \
171
171
  '$env{rack.url_scheme}' \
172
172
  "\n")
173
173
  }
174
+
174
175
  expect = [
175
176
  [ Clogger::OP_REQUEST, "REMOTE_ADDR" ],
176
177
  [ Clogger::OP_LITERAL, " - " ],
@@ -190,7 +191,9 @@ class TestClogger < Test::Unit::TestCase
190
191
  [ Clogger::OP_LITERAL, "\" \"" ],
191
192
  [ Clogger::OP_REQUEST, "HTTP_COOKIE" ],
192
193
  [ Clogger::OP_LITERAL, "\" " ],
193
- [ Clogger::OP_REQUEST_TIME, '%d.%03d', 1000 ],
194
+ [ Clogger::OP_REQUEST_TIME, '%d.%03d', 1000, 0],
195
+ [ Clogger::OP_LITERAL, " " ],
196
+ [ Clogger::OP_REQUEST_TIME, '%d', 1, 6],
194
197
  [ Clogger::OP_LITERAL, " " ],
195
198
  [ Clogger::OP_REQUEST, "rack.url_scheme" ],
196
199
  [ Clogger::OP_LITERAL, "\n" ],
@@ -209,6 +212,22 @@ class TestClogger < Test::Unit::TestCase
209
212
  assert_equal "-#{current}-\n", str.string
210
213
  end
211
214
 
215
+ def test_fiber
216
+ begin
217
+ current = Fiber.current.to_s
218
+ rescue NameError => e
219
+ warn "your Ruby does not support fibers #{e}"
220
+ return
221
+ end
222
+ str = StringIO.new
223
+ app = lambda { |env| [ 302, {}, [] ] }
224
+ cl = Clogger.new(app,
225
+ :logger => str,
226
+ :format => "-$e{Fiber.current}-\n")
227
+ status, headers, body = cl.call(@req)
228
+ assert_equal "-#{current}-\n", str.string
229
+ end
230
+
212
231
  def test_pid
213
232
  str = StringIO.new
214
233
  app = lambda { |env| [ 302, {}, [] ] }
@@ -721,6 +740,24 @@ class TestClogger < Test::Unit::TestCase
721
740
  assert s[-1].to_f <= 0.110
722
741
  end
723
742
 
743
+ def test_request_time_with_multiplier
744
+ s = []
745
+ app = lambda { |env| sleep(0.1) ; [302, [], [] ] }
746
+ cl = Clogger.new(app, :logger => s, :format => "$request_time{9,0}")
747
+ status, headers, body = cl.call(@req)
748
+ assert_nothing_raised { body.each { |x| } ; body.close }
749
+ assert s[-1].to_f >= 100000000
750
+ assert s[-1].to_f <= 300000000
751
+ end
752
+
753
+ def test_request_time_with_invalid_multiplier
754
+ s = []
755
+ app = lambda { |env| sleep(0.1) ; [302, [], [] ] }
756
+ assert_raise(ArgumentError) {
757
+ cl = Clogger.new(app, :logger => s, :format => "$request_time{10,0}")
758
+ }
759
+ end
760
+
724
761
  def test_insanely_long_time_format
725
762
  s = []
726
763
  app = lambda { |env| [200, [], [] ] }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cloggers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-08 00:00:00.000000000 Z
11
+ date: 2020-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack