Permalink
Browse files

New Mongrel.log is verified working for Mongrel Handler, Rails and Merb.

git-svn-id: svn://rubyforge.org/var/svn/mongrel/trunk@916 19e92222-5c0b-0410-8929-a290d50e31e9
  • Loading branch information...
1 parent 47d6792 commit 79948cb846f06a750877e27d6b849ee57cac269f wayneeseguin committed Dec 16, 2007
View
@@ -75,49 +75,49 @@ module Mongrel
def run
if @generate
@generate = File.expand_path(@generate)
- log(:error, "** Writing config to \"#@generate\".")
+ Mongrel.log(:error, "** Writing config to \"#@generate\".")
open(@generate, "w") {|f| f.write(settings.to_yaml) }
- log(:error, "** Finished. Run \"mongrel_rails start -C #@generate\" to use the config file.")
+ Mongrel.log(:error, "** Finished. Run \"mongrel_rails start -C #@generate\" to use the config file.")
exit 0
end
config = Mongrel::Rails::RailsConfigurator.new(settings) do
if defaults[:daemon]
if File.exist? defaults[:pid_file]
- log "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors."
- log "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start."
+ Mongrel.error(:info, "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors.")
+ Mongrel.log(:error, "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start.")
exit 1
end
daemonize
- log "Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info."
- log "Settings loaded from #{@config_file} (they override command line)." if @config_file
+ Mongrel.log(:info, "Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info.")
+ Mongrel.log(:info, "Settings loaded from #{@config_file} (they override command line).") if @config_file
end
- log "Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}"
+ Mongrel.log(:info, "Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}")
listener do
mime = {}
if defaults[:mime_map]
- log "Loading additional MIME types from #{defaults[:mime_map]}"
+ Mongrel.log(:info, "Loading additional MIME types from #{defaults[:mime_map]}")
mime = load_mime_map(defaults[:mime_map], mime)
end
if defaults[:debug]
- log "Installing debugging prefixed filters. Look in log/mongrel_debug for the files."
+ Mongrel.log(:info, "Installing debugging prefixed filters. Look in log/mongrel_debug for the files.")
debug "/"
end
- log "Starting Rails with #{defaults[:environment]} environment..."
- log "Mounting Rails at #{defaults[:prefix]}..." if defaults[:prefix]
+ Mongrel.log(:info, "Starting Rails with #{defaults[:environment]} environment...")
+ Mongrel.log(:info, "Mounting Rails at #{defaults[:prefix]}...") if defaults[:prefix]
uri defaults[:prefix] || "/", :handler => rails(:mime => mime, :prefix => defaults[:prefix])
- log "Rails loaded."
+ Mongrel.log(:info, "Rails loaded.")
- log "Loading any Rails specific GemPlugins"
+ Mongrel.log(:info, "Loading any Rails specific GemPlugins" )
load_plugins
if defaults[:config_script]
- log "Loading #{defaults[:config_script]} external config script"
+ Mongrel.log(:info, "Loading #{defaults[:config_script]} external config script")
run_config(defaults[:config_script])
end
@@ -126,31 +126,31 @@ module Mongrel
end
config.run
- config.log "Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}"
+ Mongrel.log(:info, "Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}")
if config.defaults[:daemon]
config.write_pid_file
else
- config.log "Use CTRL-C to stop."
+ Mongrel.log(:info, "Use CTRL-C to stop.")
end
config.join
if config.needs_restart
unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/
cmd = "ruby #{__FILE__} start #{original_args.join(' ')}"
- config.log "Restarting with arguments: #{cmd}"
+ Mongrel.log(:info, "Restarting with arguments: #{cmd}")
config.stop(false, true)
config.remove_pid_file
if config.defaults[:daemon]
system cmd
else
- log(:error, "Can't restart unless in daemon mode.")
+ Mongrel.log(:error, "Can't restart unless in daemon mode.")
exit 1
end
else
- config.log "Win32 does not support restarts. Exiting."
+ Mongrel.log(:info, "Win32 does not support restarts. Exiting.")
end
end
end
@@ -160,7 +160,7 @@ module Mongrel
begin
settings = YAML.load_file(@config_file)
ensure
- log(:error, "** Loading settings from #{@config_file} (they override command line)." unless @daemon || settings[:daemon] )
+ Mongrel.log(:error, "** Loading settings from #{@config_file} (they override command line).") unless @daemon || settings[:daemon]
end
settings[:includes] ||= ["mongrel"]
View
@@ -4,9 +4,9 @@ class TestPlugin < GemPlugin::Plugin "/handlers"
include Mongrel::HttpHandlerPlugin
def process(request, response)
- log(:error, "My options are: #{options.inspect}")
- log(:error, "Request Was:")
- log(:error, request.params.to_yaml)
+ Mongrel.log(:error, "My options are: #{options.inspect}")
+ Mongrel.log(:error, "Request Was:")
+ Mongrel.log(:error, request.params.to_yaml)
end
end
View
@@ -391,7 +391,7 @@ void Init_http11()
DEF_GLOBAL(server_protocol, "SERVER_PROTOCOL");
DEF_GLOBAL(server_protocol_value, "HTTP/1.1");
DEF_GLOBAL(http_host, "HTTP_HOST");
- DEF_GLOBAL(mongrel_version, "Mongrel 1.1.1"); /* XXX Why is this defined here? */
+ DEF_GLOBAL(mongrel_version, "Mongrel 1.1.2"); /* XXX Why is this defined here? */
DEF_GLOBAL(server_software, "SERVER_SOFTWARE");
DEF_GLOBAL(port_80, "80");
View
@@ -1,3 +1,4 @@
+# Ruby
require 'socket'
require 'tempfile'
require 'yaml'
@@ -6,10 +7,15 @@
require 'uri'
require 'stringio'
+# Ensure working require
require 'mongrel/gems'
+# TODO: Only require these for RUBY_VERSION <= 1.8.6
+# and only for platforms that require it, exclusive matching
+if !RUBY_PLATFORM.match(/java|mswin/) && !RUBY_VERSION.match(/1\.8\.\d/)
Mongrel::Gems.require 'cgi_multipart_eof_fix'
Mongrel::Gems.require 'fastthread'
+end
require 'thread'
require 'http11'
@@ -183,23 +189,23 @@ def process_client(client)
rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF
client.close rescue nil
rescue HttpParserError => e
- log(:error, "#{Time.now.httpdate}: HTTP parse error, malformed request (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #{e.inspect}")
- log(:error, "#{Time.now.httpdate}: REQUEST DATA: #{data.inspect}\n---\nPARAMS: #{params.inspect}\n---\n")
+ Mongrel.log(:error, "#{Time.now.httpdate}: HTTP parse error, malformed request (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #{e.inspect}")
+ Mongrel.log(:error, "#{Time.now.httpdate}: REQUEST DATA: #{data.inspect}\n---\nPARAMS: #{params.inspect}\n---\n")
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4
client.write(Const::ERROR_400_RESPONSE)
rescue Errno::EMFILE
reap_dead_workers('too many files')
rescue Object => e
- log(:error, "#{Time.now.httpdate}: Read error: #{e.inspect}")
- log(:error, e.backtrace.join("\n"))
+ Mongrel.log(:error, "#{Time.now.httpdate}: Read error: #{e.inspect}")
+ Mongrel.log(:error, e.backtrace.join("\n"))
ensure
begin
client.close
rescue IOError
# Already closed
rescue Object => e
- log(:error, "#{Time.now.httpdate}: Client error: #{e.inspect}")
- log(:error, e.backtrace.join("\n"))
+ Mongrel.log(:error, "#{Time.now.httpdate}: Client error: #{e.inspect}")
+ Mongrel.log(:error, e.backtrace.join("\n"))
end
request.body.delete if request and request.body.class == Tempfile
end
@@ -211,14 +217,14 @@ def process_client(client)
# after the reap is done. It only runs if there are workers to reap.
def reap_dead_workers(reason='unknown')
if @workers.list.length > 0
- log(:error, "#{Time.now.httpdate}: Reaping #{@workers.list.length} threads for slow workers because of '#{reason}'")
+ Mongrel.log(:error, "#{Time.now.httpdate}: Reaping #{@workers.list.length} threads for slow workers because of '#{reason}'")
error_msg = "#{Time.now.httpdate}: Mongrel timed out this thread: #{reason}"
mark = Time.now
@workers.list.each do |worker|
worker[:started_on] = Time.now if not worker[:started_on]
if mark - worker[:started_on] > @timeout + @throttle
- log(:error, "#{Time.now.httpdate}: Thread #{worker.inspect} is too old, killing.")
+ Mongrel.log(:error, "#{Time.now.httpdate}: Thread #{worker.inspect} is too old, killing.")
worker.raise(TimeoutError.new(error_msg))
end
end
@@ -233,7 +239,7 @@ def reap_dead_workers(reason='unknown')
# that much longer.
def graceful_shutdown
while reap_dead_workers("shutdown") > 0
- log(:error, "#{Time.now.httpdate}: Waiting for #{@workers.list.length} requests to finish, could take #{@timeout + @throttle} seconds.")
+ Mongrel.log(:error, "#{Time.now.httpdate}: Waiting for #{@workers.list.length} requests to finish, could take #{@timeout + @throttle} seconds.")
sleep @timeout / 10
end
end
@@ -279,7 +285,7 @@ def run
worker_list = @workers.list
if worker_list.length >= @num_processors
- log(:error, "#{Time.now.httpdate}: Server overloaded with #{worker_list.length} processors (#@num_processors max). Dropping connection.")
+ Mongrel.log(:error, "#{Time.now.httpdate}: Server overloaded with #{worker_list.length} processors (#@num_processors max). Dropping connection.")
client.close rescue nil
reap_dead_workers("max processors")
else
@@ -298,14 +304,14 @@ def run
# client closed the socket even before accept
client.close rescue nil
rescue Object => e
- log(:error, "#{Time.now.httpdate}: Unhandled listen loop exception #{e.inspect}.")
- log(:error, e.backtrace.join("\n"))
+ Mongrel.log(:error, "#{Time.now.httpdate}: Unhandled listen loop exception #{e.inspect}.")
+ Mongrel.log(:error, e.backtrace.join("\n"))
end
end
graceful_shutdown
ensure
@socket.close
- # log(:error, "#{Time.now.httpdate}: Closed socket.")
+ # Mongrel.log(:error, "#{Time.now.httpdate}: Closed socket.")
end
end
View
@@ -55,14 +55,14 @@ def initialize(options={})
# I need to add my own -h definition to prevent the -h by default from exiting.
@opt.on_tail("-h", "--help", "Show this message") do
@done_validating = true
- puts @opt
+ Mongrel.log(:info, @opt)
end
# I need to add my own -v definition to prevent the -v from exiting by default as well.
@opt.on_tail("--version", "Show version") do
@done_validating = true
if VERSION
- puts "Version #{Mongrel::Const::MONGREL_VERSION}"
+ Mongrel.log(:info, "Version #{Mongrel::Const::MONGREL_VERSION}")
end
end
@@ -155,17 +155,17 @@ def commands
# Prints a list of available commands.
def print_command_list
- puts "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n"
+ Mongrel.log(:info, "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n")
self.commands.each do |name|
if /mongrel::/ =~ name
name = name[9 .. -1]
end
- puts " - #{name[1 .. -1]}\n"
+ Mongrel.log(:info, " - #{name[1 .. -1]}\n")
end
- puts "\nEach command takes -h as an option to get help."
+ Mongrel.log(:info, "\nEach command takes -h as an option to get help.")
end
@@ -180,7 +180,7 @@ def run(args)
print_command_list
return true
elsif cmd_name == "--version"
- puts "Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}"
+ Mongrel.log(:info, "Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}")
return true
end
@@ -59,18 +59,18 @@ def change_privilege(user, group)
target_gid = Etc.getgrnam(group).gid if group
if uid != target_uid or gid != target_gid
- log(:info, "Initiating groups for #{user.inspect}:#{group.inspect}.")
+ Mongrel.log(:info, "Initiating groups for #{user.inspect}:#{group.inspect}.")
Process.initgroups(user, target_gid)
- log(:info, "Changing group to #{group.inspect}.")
+ Mongrel.log(:info, "Changing group to #{group.inspect}.")
Process::GID.change_privilege(target_gid)
- log(:info, "Changing user to #{user.inspect}." )
+ Mongrel.log(:info, "Changing user to #{user.inspect}." )
Process::UID.change_privilege(target_uid)
end
rescue Errno::EPERM => e
- log(:critical, "Couldn't change user and group to #{user.inspect}:#{group.inspect}: #{e.to_s}.")
- log(:critical, "Mongrel failed to start.")
+ Mongrel.log(:critical, "Couldn't change user and group to #{user.inspect}:#{group.inspect}: #{e.to_s}.")
+ Mongrel.log(:critical, "Mongrel failed to start.")
exit 1
end
end
@@ -82,7 +82,7 @@ def remove_pid_file
# Writes the PID file if we're not on Windows.
def write_pid_file
unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/
- log(:info, "Writing PID file to #{@pid_file}")
+ Mongrel.log(:info, "Writing PID file to #{@pid_file}")
open(@pid_file,"w") {|f| f.write(Process.pid) }
open(@pid_file,"w") do |f|
f.write(Process.pid)
@@ -192,7 +192,7 @@ def daemonize(options={})
if logfile[0].chr != "/"
logfile = File.join(ops[:cwd],logfile)
if not File.exist?(File.dirname(logfile))
- log(:critical, "!!! Log file directory not found at full path #{File.dirname(logfile)}. Update your configuration to use a full path.")
+ Mongrel.log(:critical, "!!! Log file directory not found at full path #{File.dirname(logfile)}. Update your configuration to use a full path.")
exit 1
end
end
@@ -203,7 +203,7 @@ def daemonize(options={})
Dir.chdir(ops[:cwd])
else
- log(:warning, "WARNING: Win32 does not support daemon mode.")
+ Mongrel.log(:warning, "WARNING: Win32 does not support daemon mode.")
end
end
@@ -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, "WARNING: MIME type #{k} must start with '.'") if k.index(".") != 0 }
+ mime.each {|k,v| Mongrel.log(:warning, "WARNING: MIME type #{k} must start with '.'") if k.index(".") != 0 }
return mime
end
@@ -361,22 +361,22 @@ 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") { Mongrel.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") { Mongrel.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") { Mongrel.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") { Mongrel.log(:notice, "USR2 signal received."); stop(true) }
- log(:notice, "Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).")
+ Mongrel.log(:notice, "Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).")
else
- log(:notice, "Signals ready. INT => stop (no restart).")
+ Mongrel.log(:notice, "Signals ready. INT => stop (no restart).")
end
end
View
@@ -97,7 +97,7 @@ class Access < GemPlugin::Plugin "/handlers"
def process(request,response)
p = request.params
#STDERR.puts "#{p['REMOTE_ADDR']} - [#{Time.now.httpdate}] \"#{p['REQUEST_METHOD']} #{p["REQUEST_URI"]} HTTP/1.1\""
- log(:info, "#{p['REMOTE_ADDR']} \"#{p['REQUEST_METHOD']} #{p["REQUEST_URI"]} HTTP/1.1\"")
+ Mongrel.log(:info, "#{p['REMOTE_ADDR']} \"#{p['REQUEST_METHOD']} #{p["REQUEST_URI"]} HTTP/1.1\"")
end
end
Oops, something went wrong.

0 comments on commit 79948cb

Please sign in to comment.