mongrel2 0.21.0 → 0.22.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,9 +4,9 @@ require 'socket'
4
4
  require 'zmq'
5
5
  require 'yajl'
6
6
  require 'digest/sha1'
7
+ require 'loggability'
7
8
 
8
9
  require 'mongrel2' unless defined?( Mongrel2 )
9
- require 'mongrel2/mixins'
10
10
 
11
11
 
12
12
  # The Mongrel2 connection class. Connection objects serve as a front end for
@@ -17,7 +17,10 @@ require 'mongrel2/mixins'
17
17
  # == References
18
18
  # * http://mongrel2.org/static/mongrel2-manual.html#x1-700005.3
19
19
  class Mongrel2::Connection
20
- include Mongrel2::Loggable
20
+ extend Loggability
21
+
22
+ # Loggability API -- set up logging under the 'mongrel2' log host
23
+ log_to :mongrel2
21
24
 
22
25
 
23
26
  ### Create a new Connection identified by +app_id+ (a UUID or other unique string) that
@@ -3,9 +3,9 @@
3
3
  require 'zmq'
4
4
  require 'yajl'
5
5
  require 'tnetstring'
6
+ require 'loggability'
6
7
 
7
8
  require 'mongrel2' unless defined?( Mongrel2 )
8
- require 'mongrel2/mixins'
9
9
 
10
10
 
11
11
  # An interface to the Mongrel2 control port.
@@ -13,7 +13,11 @@ require 'mongrel2/mixins'
13
13
  # == References
14
14
  # (http://mongrel2.org/static/mongrel2-manual.html#x1-380003.8)
15
15
  class Mongrel2::Control
16
- include Mongrel2::Loggable
16
+ extend Loggability
17
+
18
+ # Loggability API -- set up logging under the 'mongrel2' log host
19
+ log_to :mongrel2
20
+
17
21
 
18
22
  # The default zmq connection spec to use when talking to a mongrel2 server
19
23
  DEFAULT_PORT = 'ipc://run/control'
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'zmq'
4
+ require 'loggability'
4
5
 
5
6
  require 'mongrel2' unless defined?( Mongrel2 )
6
7
  require 'mongrel2/config'
@@ -81,16 +82,20 @@ require 'mongrel2/websocket'
81
82
  # app.run
82
83
  #
83
84
  class Mongrel2::Handler
84
- include Mongrel2::Loggable,
85
- Mongrel2::Constants
85
+ extend Loggability
86
+ include Mongrel2::Constants
87
+
88
+
89
+ # Loggability API -- set up logging under the 'mongrel2' log host
90
+ log_to :mongrel2
86
91
 
87
92
 
88
93
  ### Create an instance of the handler using the config from the database with
89
94
  ### the given +appid+ and run it.
90
95
  def self::run( appid )
91
- Mongrel2.log.info "Running application %p" % [ appid ]
96
+ self.log.info "Running application %p" % [ appid ]
92
97
  send_spec, recv_spec = self.connection_info_for( appid )
93
- Mongrel2.log.info " config specs: %s <-> %s" % [ send_spec, recv_spec ]
98
+ self.log.info " config specs: %s <-> %s" % [ send_spec, recv_spec ]
94
99
  new( appid, send_spec, recv_spec ).run
95
100
  end
96
101
 
@@ -98,11 +103,11 @@ class Mongrel2::Handler
98
103
  ### Return the send_spec and recv_spec for the given +appid+ from the current configuration
99
104
  ### database. Returns +nil+ if no Handler is configured with +appid+ as its +sender_id+.
100
105
  def self::connection_info_for( appid )
101
- Mongrel2.log.debug "Looking up handler spec for appid %p" % [ appid ]
106
+ self.log.debug "Looking up handler spec for appid %p" % [ appid ]
102
107
  hconfig = Mongrel2::Config::Handler.by_send_ident( appid ).first or
103
108
  raise ArgumentError, "no handler with a send_ident of %p configured" % [ appid ]
104
109
 
105
- Mongrel2.log.debug " found: %s" % [ hconfig.values ]
110
+ self.log.debug " found: %s" % [ hconfig.values ]
106
111
  return hconfig.send_spec, hconfig.recv_spec
107
112
  end
108
113
 
@@ -1,19 +1,24 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
+ require 'ipaddr'
4
+ require 'loggability'
5
+
3
6
  require 'mongrel2/request' unless defined?( Mongrel2::Request )
4
- require 'mongrel2/mixins'
5
7
  require 'mongrel2/httpresponse'
6
- require 'ipaddr'
7
8
 
8
9
 
9
10
  # The Mongrel2 HTTP Request class. Instances of this class represent an HTTP request from
10
11
  # a Mongrel2 server.
11
12
  class Mongrel2::HTTPRequest < Mongrel2::Request
12
- include Mongrel2::Loggable
13
+ extend Loggability
14
+
15
+ # Loggability API -- set up logging under the 'mongrel2' log host
16
+ log_to :mongrel2
13
17
 
14
18
  # HTTP verbs from RFC2616
15
19
  HANDLED_HTTP_METHODS = [ :OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE, :TRACE, :CONNECT ]
16
20
 
21
+ # Mongrel2::Request API -- register this class as handling the HTTP verbs
17
22
  register_request_type( self, *HANDLED_HTTP_METHODS )
18
23
 
19
24
 
@@ -2,16 +2,19 @@
2
2
  #encoding: utf-8
3
3
 
4
4
  require 'time'
5
+ require 'loggability'
5
6
 
6
7
  require 'mongrel2/response' unless defined?( Mongrel2::Response )
7
- require 'mongrel2/mixins'
8
8
  require 'mongrel2/constants'
9
9
 
10
10
 
11
11
  # The Mongrel2 HTTP Response class.
12
12
  class Mongrel2::HTTPResponse < Mongrel2::Response
13
- include Mongrel2::Loggable,
14
- Mongrel2::Constants
13
+ extend Loggability
14
+ include Mongrel2::Constants
15
+
16
+ # Loggability API -- set up logging under the 'mongrel2' log host
17
+ log_to :mongrel2
15
18
 
16
19
  # The format for building valid HTTP responses
17
20
  STATUS_LINE_FORMAT = "HTTP/1.1 %03d %s".freeze
@@ -1,16 +1,20 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  require 'yajl'
4
+ require 'loggability'
4
5
 
5
6
  require 'mongrel2/request' unless defined?( Mongrel2::Request )
6
- require 'mongrel2/mixins'
7
7
 
8
8
 
9
9
  # The Mongrel2 JSON Request class. Instances of this class represent a JSSocket request from
10
10
  # a Mongrel2 server.
11
11
  class Mongrel2::JSONRequest < Mongrel2::Request
12
- include Mongrel2::Loggable
12
+ extend Loggability
13
13
 
14
+ # Loggability API -- set up logging under the 'mongrel2' log host
15
+ log_to :mongrel2
16
+
17
+ # Mongrel2::Request API -- register this request type as handling 'JSON' requests
14
18
  register_request_type( self, :JSON )
15
19
 
16
20
 
@@ -2,17 +2,19 @@
2
2
 
3
3
  require 'tnetstring'
4
4
  require 'yajl'
5
+ require 'loggability'
5
6
 
6
7
  require 'mongrel2' unless defined?( Mongrel2 )
7
- require 'mongrel2/mixins'
8
8
  require 'mongrel2/table'
9
9
 
10
10
 
11
11
  # The Mongrel2 Request base class. Derivatives of this class represent a request from
12
12
  # a Mongrel2 server.
13
13
  class Mongrel2::Request
14
- include Mongrel2::Loggable
14
+ extend Loggability
15
15
 
16
+ # Loggability API -- set up logging under the 'mongrel2' log host
17
+ log_to :mongrel2
16
18
 
17
19
  # METHOD header -> request class mapping
18
20
  @request_types = Hash.new {|h,k| h[k] = Mongrel2::Request }
@@ -23,7 +25,7 @@ class Mongrel2::Request
23
25
  ### request object.
24
26
  def self::parse( raw_request )
25
27
  sender, conn_id, path, rest = raw_request.split( ' ', 4 )
26
- Mongrel2.log.debug "Parsing request for %p from %s:%s (rest: %p)" %
28
+ self.log.debug "Parsing request for %p from %s:%s (rest: %p)" %
27
29
  [ path, sender, conn_id, rest ]
28
30
 
29
31
  # Extract the headers and the body, ignore the rest
@@ -32,7 +34,7 @@ class Mongrel2::Request
32
34
 
33
35
  # Headers will be a JSON String when not using the TNetString protocol
34
36
  if headers.is_a?( String )
35
- Mongrel2.log.debug " parsing old-style headers"
37
+ self.log.debug " parsing old-style headers"
36
38
  headers = Yajl::Parser.parse( headers )
37
39
  end
38
40
 
@@ -40,7 +42,7 @@ class Mongrel2::Request
40
42
  headers['METHOD'] =~ /^(\w+)$/ or
41
43
  raise Mongrel2::UnhandledMethodError, headers['METHOD']
42
44
  req_method = $1.untaint.to_sym
43
- Mongrel2.log.debug "Request method is: %p" % [ req_method ]
45
+ self.log.debug "Request method is: %p" % [ req_method ]
44
46
  concrete_class = self.subclass_for_method( req_method )
45
47
 
46
48
  return concrete_class.new( sender, conn_id, path, headers, body, raw_request )
@@ -72,15 +74,15 @@ class Mongrel2::Request
72
74
  ### If you wish one of your subclasses to be used instead of Mongrel2::Request
73
75
  ### for the default request class, register it with a METHOD of :__default.
74
76
  def self::register_request_type( subclass, *req_methods )
75
- Mongrel2.log.debug "Registering %p for %p requests" % [ subclass, req_methods ]
77
+ self.log.debug "Registering %p for %p requests" % [ subclass, req_methods ]
76
78
  req_methods.each do |methname|
77
79
  if methname == :__default
78
80
  # Clear cached lookups
79
- Mongrel2.log.info "Registering %p as the default request type." % [ subclass ]
81
+ self.log.info "Registering %p as the default request type." % [ subclass ]
80
82
  Mongrel2::Request.request_types.delete_if {|_, klass| klass == Mongrel2::Request }
81
83
  Mongrel2::Request.request_types.default_proc = lambda {|h,k| h[k] = subclass }
82
84
  else
83
- Mongrel2.log.info "Registering %p for the %p method." % [ subclass, methname ]
85
+ self.log.info "Registering %p for the %p method." % [ subclass, methname ]
84
86
  Mongrel2::Request.request_types[ methname.to_sym ] = subclass
85
87
  end
86
88
  end
@@ -2,14 +2,17 @@
2
2
 
3
3
  require 'tnetstring'
4
4
  require 'yajl'
5
+ require 'loggability'
5
6
 
6
7
  require 'mongrel2' unless defined?( Mongrel2 )
7
- require 'mongrel2/mixins'
8
8
 
9
9
 
10
10
  # The Mongrel2 Response base class.
11
11
  class Mongrel2::Response
12
- include Mongrel2::Loggable
12
+ extend Loggability
13
+
14
+ # Loggability API -- set up logging under the 'mongrel2' log host
15
+ log_to :mongrel2
13
16
 
14
17
  # The default number of bytes of the response body to send to the mongrel2
15
18
  # server at a time.
@@ -18,7 +21,7 @@ class Mongrel2::Response
18
21
 
19
22
  ### Create a response to the specified +request+ and return it.
20
23
  def self::from_request( request )
21
- Mongrel2.log.debug "Creating a %p to request %p" % [ self, request ]
24
+ self.log.debug "Creating a %p to request %p" % [ self, request ]
22
25
  response = new( request.sender_id, request.conn_id )
23
26
  response.request = request
24
27
 
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  require 'forwardable'
4
+ require 'loggability'
4
5
 
5
6
  require 'mongrel2' unless defined?( Mongrel2 )
6
- require 'mongrel2/mixins'
7
7
 
8
8
 
9
9
  # The Mongrel2 Table class. Instances of this class provide a case-insensitive hash-like
@@ -14,15 +14,18 @@ require 'mongrel2/mixins'
14
14
  # headers['user-agent'] # => 'PornBrowser 1.1.5'
15
15
  # headers[:user_agent] # => 'PornBrowser 1.1.5'
16
16
  # headers.user_agent # => 'PornBrowser 1.1.5'
17
- #
17
+ #
18
18
  # == Author/s
19
- #
19
+ #
20
20
  # * Michael Granger <ged@FaerieMUD.org>
21
21
  # * Mahlon E. Smith <mahlon@martini.nu>
22
22
  #
23
23
  class Mongrel2::Table
24
- extend Forwardable
25
- include Mongrel2::Loggable
24
+ extend Forwardable,
25
+ Loggability
26
+
27
+ # Loggability API -- set up logging under the 'mongrel2' log host
28
+ log_to :mongrel2
26
29
 
27
30
  # Methods that understand case-insensitive keys
28
31
  KEYED_METHODS = [ :"[]", :"[]=", :delete, :fetch, :has_key?, :include?, :member?, :store ]
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'uri'
4
4
  require 'pathname'
5
+ require 'loggability'
5
6
  require 'mongrel2'
6
7
  require 'mongrel2/request'
7
8
 
@@ -19,6 +20,10 @@ module Mongrel2
19
20
 
20
21
  ### A factory for generating Mongrel2::Request objects for testing.
21
22
  class RequestFactory
23
+ extend Loggability
24
+
25
+ # Loggability API -- set up logging under the 'mongrel2' log host
26
+ log_to :mongrel2
22
27
 
23
28
  # Default testing UUID (sender_id)
24
29
  DEFAULT_TEST_UUID = 'BD17D85C-4730-4BF2-999D-9D2B2E0FCCF9'
@@ -217,8 +222,12 @@ module Mongrel2
217
222
 
218
223
  ### A factory for generating WebSocket request objects for testing.
219
224
  class WebSocketFrameFactory < Mongrel2::RequestFactory
225
+ extend Loggability
220
226
  include Mongrel2::Constants
221
227
 
228
+ # Loggability API -- set up logging under the 'mongrel2' log host
229
+ log_to :mongrel2
230
+
222
231
  # The default host
223
232
  DEFAULT_TESTING_HOST = 'localhost'
224
233
  DEFAULT_TESTING_PORT = '8113'
@@ -371,7 +380,7 @@ module Mongrel2
371
380
  flag_symbols.flatten!
372
381
  flag_symbols.compact!
373
382
 
374
- Mongrel2.log.debug "Making a flags header for symbols: %p" % [ flag_symbols ]
383
+ self.log.debug "Making a flags header for symbols: %p" % [ flag_symbols ]
375
384
 
376
385
  return flag_symbols.inject( 0x00 ) do |flags, flag|
377
386
  case flag
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  require 'mongrel2/request' unless defined?( Mongrel2::Request )
4
- require 'mongrel2/mixins'
5
4
  require 'mongrel2/constants'
6
5
 
7
6
 
@@ -211,7 +210,7 @@ module Mongrel2::WebSocket
211
210
 
212
211
  ### Create a response frame from the given request +frame+.
213
212
  def self::from_request( frame )
214
- Mongrel2.log.debug "Creating a %p response to request %p" % [ self, frame ]
213
+ self.log.debug "Creating a %p response to request %p" % [ self, frame ]
215
214
  response = new( frame.sender_id, frame.conn_id, frame.path )
216
215
  response.request_frame = frame
217
216
 
@@ -1,16 +1,20 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  require 'nokogiri'
4
+ require 'loggability'
4
5
 
5
6
  require 'mongrel2/request' unless defined?( Mongrel2::Request )
6
- require 'mongrel2/mixins'
7
7
 
8
8
 
9
9
  # The Mongrel2 XML Request class. Instances of this class represent a request for an XML route from
10
10
  # a Mongrel2 server.
11
11
  class Mongrel2::XMLRequest < Mongrel2::Request
12
- include Mongrel2::Loggable
12
+ extend Loggability
13
13
 
14
+ # Loggability API -- set up logging under the 'mongrel2' log host
15
+ log_to :mongrel2
16
+
17
+ # Mongrel2::Request API -- register this class as handling 'XML' requests
14
18
  register_request_type( self, :XML )
15
19
 
16
20
 
data/spec/lib/helpers.rb CHANGED
@@ -50,33 +50,6 @@ require 'spec/lib/matchers'
50
50
  module Mongrel2::SpecHelpers
51
51
  include Mongrel2::TestConstants
52
52
 
53
- class ArrayLogger
54
- ### Create a new ArrayLogger that will append content to +array+.
55
- def initialize( array )
56
- @array = array
57
- end
58
-
59
- ### Write the specified +message+ to the array.
60
- def write( message )
61
- @array << message
62
- end
63
-
64
- ### No-op -- this is here just so Logger doesn't complain
65
- def close; end
66
-
67
- end # class ArrayLogger
68
-
69
-
70
- unless defined?( LEVEL )
71
- LEVEL = {
72
- :debug => Logger::DEBUG,
73
- :info => Logger::INFO,
74
- :warn => Logger::WARN,
75
- :error => Logger::ERROR,
76
- :fatal => Logger::FATAL,
77
- }
78
- end
79
-
80
53
  ###############
81
54
  module_function
82
55
  ###############
@@ -89,29 +62,24 @@ module Mongrel2::SpecHelpers
89
62
 
90
63
  ### Reset the logging subsystem to its default state.
91
64
  def reset_logging
92
- Mongrel2.reset_logger
65
+ Loggability.formatter = nil
66
+ Loggability.output_to( $stderr )
67
+ Loggability.level = :fatal
93
68
  end
94
69
 
95
70
 
96
71
  ### Alter the output of the default log formatter to be pretty in SpecMate output
97
- def setup_logging( level=Logger::FATAL )
98
-
99
- # Turn symbol-style level config into Logger's expected Fixnum level
100
- if Mongrel2::Logging::LOG_LEVELS.key?( level.to_s )
101
- level = Mongrel2::Logging::LOG_LEVELS[ level.to_s ]
102
- end
103
-
104
- logger = Logger.new( $stderr )
105
- Mongrel2.logger = logger
106
- Mongrel2.logger.level = level
72
+ def setup_logging( level=:fatal )
107
73
 
108
74
  # Only do this when executing from a spec in TextMate
109
75
  if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
110
- Thread.current['logger-output'] = []
111
- logdevice = ArrayLogger.new( Thread.current['logger-output'] )
112
- Mongrel2.logger = Logger.new( logdevice )
113
- # Mongrel2.logger.level = level
114
- Mongrel2.logger.formatter = Mongrel2::Logging::HtmlFormatter.new( logger )
76
+ logarray = []
77
+ Thread.current['logger-output'] = logarray
78
+ Loggability.output_to( logarray )
79
+ Loggability.format_as( :html )
80
+ Loggability.level = :debug
81
+ else
82
+ Loggability.level = level
115
83
  end
116
84
  end
117
85