Browse files

One step in the right direction.

git-svn-id: svn://rubyforge.org/var/svn/mongrel/trunk@915 19e92222-5c0b-0410-8929-a290d50e31e9
  • Loading branch information...
1 parent d0dbc45 commit 47d6792da17314c4acb0b246392971dbd7fc7a7e wayneeseguin committed Dec 16, 2007
Showing with 17 additions and 13 deletions.
  1. +1 −0 Manifest
  2. +0 −4 TODO
  3. +5 −2 lib/mongrel.rb
  4. +5 −5 lib/mongrel/configurator.rb
  5. +6 −2 lib/mongrel/logger.rb
View
1 Manifest
@@ -37,6 +37,7 @@ lib/mongrel/header_out.rb
lib/mongrel/http_request.rb
lib/mongrel/http_response.rb
lib/mongrel/init.rb
+lib/mongrel/logger.rb
lib/mongrel/mime_types.yml
lib/mongrel/rails.rb
lib/mongrel/stats.rb
View
4 TODO
@@ -1,6 +1,2 @@
* Rewrite and merge mongrel cluster and mongrel_rails into something small and maintainable.
-* Refactor logging to include timestamps.
-* See if Java is setting the server version string in the request properly.
-* Figure out why Java writes to STDERR instead of the file in the middle of one of the tests.
-* Remove cgi_multipart_eof_fix and fastthread permanently (for 1.2).
View
7 lib/mongrel.rb
@@ -69,6 +69,8 @@ class HttpServer
attr_reader :timeout
attr_reader :num_processors
+ attr_accessor :logger
+
# Creates a working server on host:port (strange things happen if port isn't a Number).
# Use HttpServer::run to start the server and HttpServer.acceptor.join to
# join the thread that's processing incoming requests on the socket.
@@ -82,7 +84,7 @@ class HttpServer
# The throttle parameter is a sleep timeout (in hundredths of a second) that is placed between
# socket.accept calls in order to give the server a cheap throttle time. It defaults to 0 and
# actually if it is 0 then the sleep is not done at all.
- def initialize(host, port, num_processors=950, throttle=0, timeout=60, log=nil)
+ def initialize(host, port, num_processors=950, throttle=0, timeout=60, log=nil, log_level=:debug)
tries = 0
@socket = TCPServer.new(host, port)
@@ -94,7 +96,8 @@ def initialize(host, port, num_processors=950, throttle=0, timeout=60, log=nil)
@throttle = throttle
@num_processors = num_processors
@timeout = timeout
- Mongrel::Logger = Mongrel::Log.new(log || "mongrel-#{port}.log")
+ # Mongrel.logger = Mongrel::Log.new(log || "mongrel-#{port}.log")
+ @logger = Mongrel::Log.new(log || "mongrel-#{port}.log", log_level)
end
# Does the majority of the IO processing. It has been written in Ruby using
View
10 lib/mongrel/configurator.rb
@@ -249,7 +249,7 @@ def load_mime_map(file, mime={})
mime = load_yaml(file, mime)
# check all the mime types to make sure they are the right format
- mime.each {|k,v| log(, "WARNING: MIME type #{k} must start with '.'") if k.index(".") != 0 }
+ mime.each {|k,v| log(:warning, "WARNING: MIME type #{k} must start with '.'") if k.index(".") != 0 }
return mime
end
@@ -361,18 +361,18 @@ def setup_signals(options={})
ops = resolve_defaults(options)
# forced shutdown, even if previously restarted (actually just like TERM but for CTRL-C)
- trap("INT") { log(:notice, "INT signal received."; stop(false) }
+ trap("INT") { log(:notice, "INT signal received."); stop(false) }
# always clean up the pid file
at_exit { remove_pid_file }
unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/
# graceful shutdown
- trap("TERM") { log(:notice, "TERM signal received."; stop) }
+ trap("TERM") { log(:notice, "TERM signal received."); stop }
# debug mode
- trap("USR1") { log(:notice, "USR1 received, toggling $mongrel_debug_client to #{!$mongrel_debug_client}"; $mongrel_debug_client = !$mongrel_debug_client) }
+ trap("USR1") { log(:notice, "USR1 received, toggling $mongrel_debug_client to #{!$mongrel_debug_client}"); $mongrel_debug_client = !$mongrel_debug_client }
# restart
- trap("USR2") { log(:notice, "USR2 signal received."; stop(true)) }
+ trap("USR2") { log(:notice, "USR2 signal received."); stop(true) }
log(:notice, "Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).")
else
View
8 lib/mongrel/logger.rb
@@ -3,6 +3,10 @@
# Merb: http://merbivore.com
module Mongrel
+ #class << self
+ # attr_accessor :logger
+ #end
+
class Log
attr_accessor :logger
attr_accessor :log_level
@@ -12,7 +16,7 @@ class Log
:id => { 0 => :emergency, 1 => :alert, 2 => :critical, 3 => :error, 4 => :warning, 5 => :notice, 6 => :info, 7 => :debug }
}
- def initialize(log, log_level)
+ def initialize(log, log_level = :debug)
@logger = initialize_io(log)
@log_level = Levels[:name][log_level]
@@ -56,7 +60,7 @@ def initialize_io(log)
# Convenience wrapper for logging, allows us to use Mongrel.log
def self.log(level, string)
- Mongrel::Logger.log(level,string)
+ logger.log(level,string)
end
end

0 comments on commit 47d6792

Please sign in to comment.