clogger 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ === 0.0.5 / 2009-09-02
2
+
3
+ The following variables are now exposed: $request_method,
4
+ $content_length and $content_type. Additionally, attempts
5
+ to use $http_content_length or $http_content_type will be
6
+ remapped to use the non-"$http_"-prefixed variable instead
7
+ since the "$http_"-variants of those variables is not allowed
8
+ by Rack.
9
+
1
10
  === 0.0.4 / 2009-09-02
2
11
 
3
12
  The pure Ruby version now escapes with uppercase A-F
data/README.txt CHANGED
@@ -14,13 +14,14 @@ is customizable so you can specify exactly which fields to log.
14
14
 
15
15
  * pre-defines Apache Common Log Format, Apache Combined Log Format and
16
16
  Rack::CommonLogger (as distributed by Rack 1.0) formats.
17
+ See Clogger::Format for the predefined formats.
17
18
 
18
19
  * Untrusted values are escaped (all HTTP headers, request URI components)
19
20
  to make life easier for HTTP log parsers. The following bytes are escaped:
20
21
 
21
22
  ' (single quote)
22
23
  " (double quote)
23
- all bytes in the range of \x00-\x1f
24
+ all bytes in the range of \x00-\x1F
24
25
 
25
26
  == SYNOPSIS
26
27
 
@@ -43,6 +44,10 @@ somewhere inside the "Rails::Initializer.run do |config|" block:
43
44
 
44
45
  * $http_* - HTTP request headers (e.g. $http_user_agent)
45
46
  * $sent_http_* - HTTP response headers (e.g. $sent_http_content_length)
47
+ * $content_length - HTTP request body size
48
+ ($http_content_length is not allowed by Rack)
49
+ * $content_type - HTTP request content type
50
+ ($http_content_type is not allowed by Rack)
46
51
  * $cookie_* - HTTP request cookie (e.g. $cookie_session_id)
47
52
  Rack::Request#cookies must have been used by the underlying application
48
53
  to parse the cookies into a hash.
@@ -54,8 +59,8 @@ somewhere inside the "Rails::Initializer.run do |config|" block:
54
59
  ($request_method $request_uri $http_version)
55
60
  * $request_time, $request_time{PRECISION} - time taken for request
56
61
  (including response body iteration). PRECISION defaults to 3
57
- (milliseconds) if not specified but may be specified 0(seconds) to
58
- 6(microseconds).
62
+ (milliseconds) if not specified but may be specified anywhere from
63
+ 0(seconds) to 6(microseconds).
59
64
  * $time_local, $time_local{FORMAT} - current local time, FORMAT defaults to
60
65
  "%d/%b/%Y:%H:%M:%S %z" but accepts any strftime(3)-compatible format
61
66
  * $time_utc, $time_utc{FORMAT} - like $time_local, except with UTC
data/lib/clogger.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: binary -*-
2
2
  class Clogger
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
 
5
5
  OP_LITERAL = 0
6
6
  OP_REQUEST = 1
@@ -19,6 +19,8 @@ class Clogger
19
19
  '$time_local' => '$time_local{%d/%b/%Y:%H:%M:%S %z}',
20
20
  '$msec' => '$time{3}',
21
21
  '$usec' => '$time{6}',
22
+ '$http_content_length' => '$content_length',
23
+ '$http_content_type' => '$content_type',
22
24
  }
23
25
 
24
26
  SPECIAL_VARS = {
@@ -35,7 +37,8 @@ class Clogger
35
37
  private
36
38
 
37
39
  CGI_ENV = Regexp.new('\A\$(' <<
38
- %w(remote_addr remote_ident remote_user
40
+ %w(request_method content_length content_type
41
+ remote_addr remote_ident remote_user
39
42
  path_info query_string script_name
40
43
  server_name server_port).join('|') << ')\z').freeze
41
44
 
data/test/test_clogger.rb CHANGED
@@ -402,4 +402,36 @@ class TestClogger < Test::Unit::TestCase
402
402
  assert_equal "GET /hello?goodbye=true\n", str.string
403
403
  end
404
404
 
405
+ def test_request_method_only
406
+ str = StringIO.new
407
+ app = lambda { |env| [302, [ %w(a) ], []] }
408
+ cl = Clogger.new(app, :logger => str, :format => '$request_method')
409
+ cl.call(@req)
410
+ assert_equal "GET\n", str.string
411
+ end
412
+
413
+ def test_content_length_null
414
+ str = StringIO.new
415
+ app = lambda { |env| [302, [ %w(a) ], []] }
416
+ cl = Clogger.new(app, :logger => str, :format => '$content_length')
417
+ cl.call(@req)
418
+ assert_equal "-\n", str.string
419
+ end
420
+
421
+ def test_content_length_set
422
+ str = StringIO.new
423
+ app = lambda { |env| [302, [ %w(a) ], []] }
424
+ cl = Clogger.new(app, :logger => str, :format => '$content_length')
425
+ cl.call(@req.merge('CONTENT_LENGTH' => '5'))
426
+ assert_equal "5\n", str.string
427
+ end
428
+
429
+ def test_http_content_type_fallback
430
+ str = StringIO.new
431
+ app = lambda { |env| [302, [ %w(a) ], []] }
432
+ cl = Clogger.new(app, :logger => str, :format => '$http_content_type')
433
+ cl.call(@req.merge('CONTENT_TYPE' => 'text/plain'))
434
+ assert_equal "text/plain\n", str.string
435
+ end
436
+
405
437
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Wong