Skip to content

Commit

Permalink
New logger API is: Mongrel.log(:log_level,"message") or Mongrel.log("…
Browse files Browse the repository at this point in the history
…message") so examples:

Mongrel.log(:error, "uh oh...") # :error level logging
Mongrel.log("hi mom!") # Defaults to :info level logging
Updated Mongrel codebase for use with this API.


git-svn-id: svn://rubyforge.org/var/svn/mongrel/trunk@918 19e92222-5c0b-0410-8929-a290d50e31e9
  • Loading branch information
wayneeseguin committed Dec 17, 2007
1 parent 21a448a commit 8aaaf16
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 44 deletions.
28 changes: 14 additions & 14 deletions bin/mongrel_rails
Expand Up @@ -90,34 +90,34 @@ module Mongrel
end

daemonize
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
Mongrel.log("Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info.")
Mongrel.log("Settings loaded from #{@config_file} (they override command line).") if @config_file
end

Mongrel.log(:info, "Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}, further information can be found in log/mongrel-#{defaults[:host]}-#{defaults[:port]}.log")
Mongrel.log("Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}, further information can be found in log/mongrel-#{defaults[:host]}-#{defaults[:port]}.log")

listener do
mime = {}
if defaults[:mime_map]
Mongrel.log(:info, "Loading additional MIME types from #{defaults[:mime_map]}")
Mongrel.log("Loading additional MIME types from #{defaults[:mime_map]}")
mime = load_mime_map(defaults[:mime_map], mime)
end

if defaults[:debug]
Mongrel.log(:info, "Installing debugging prefixed filters. Look in log/mongrel_debug for the files.")
Mongrel.log("Installing debugging prefixed filters. Look in log/mongrel_debug for the files.")
debug "/"
end

Mongrel.log(:info, "Starting Rails with #{defaults[:environment]} environment...")
Mongrel.log(:info, "Mounting Rails at #{defaults[:prefix]}...") if defaults[:prefix]
Mongrel.log("Starting Rails with #{defaults[:environment]} environment...")
Mongrel.log("Mounting Rails at #{defaults[:prefix]}...") if defaults[:prefix]
uri defaults[:prefix] || "/", :handler => rails(:mime => mime, :prefix => defaults[:prefix])
Mongrel.log(:info, "Rails loaded.")
Mongrel.log("Rails loaded.")

Mongrel.log(:info, "Loading any Rails specific GemPlugins" )
Mongrel.log("Loading any Rails specific GemPlugins" )
load_plugins

if defaults[:config_script]
Mongrel.log(:info, "Loading #{defaults[:config_script]} external config script")
Mongrel.log("Loading #{defaults[:config_script]} external config script")
run_config(defaults[:config_script])
end

Expand All @@ -126,20 +126,20 @@ module Mongrel
end

config.run
Mongrel.log(:info, "Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}")
Mongrel.log("Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}")

if config.defaults[:daemon]
config.write_pid_file
else
Mongrel.log(:info, "Use CTRL-C to stop.")
Mongrel.log("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(' ')}"
Mongrel.log(:info, "Restarting with arguments: #{cmd}")
Mongrel.log("Restarting with arguments: #{cmd}")
config.stop(false, true)
config.remove_pid_file

Expand All @@ -150,7 +150,7 @@ module Mongrel
exit 1
end
else
Mongrel.log(:info, "Win32 does not support restarts. Exiting.")
Mongrel.log("Win32 does not support restarts. Exiting.")
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/mongrel/command.rb
Expand Up @@ -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
Mongrel.log(:info, @opt)
Mongrel.log(@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
Mongrel.log(:info, "Version #{Mongrel::Const::MONGREL_VERSION}")
Mongrel.log("Version #{Mongrel::Const::MONGREL_VERSION}")
end
end

Expand Down Expand Up @@ -155,17 +155,17 @@ def commands

# Prints a list of available commands.
def print_command_list
Mongrel.log(:info, "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n")
Mongrel.log("#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n")

self.commands.each do |name|
if /mongrel::/ =~ name
name = name[9 .. -1]
end

Mongrel.log(:info, " - #{name[1 .. -1]}\n")
Mongrel.log(" - #{name[1 .. -1]}\n")
end

Mongrel.log(:info, "\nEach command takes -h as an option to get help.")
Mongrel.log("\nEach command takes -h as an option to get help.")

end

Expand All @@ -180,7 +180,7 @@ def run(args)
print_command_list
return true
elsif cmd_name == "--version"
Mongrel.log(:info, "Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}")
Mongrel.log("Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}")
return true
end

Expand Down
8 changes: 4 additions & 4 deletions lib/mongrel/configurator.rb
Expand Up @@ -59,13 +59,13 @@ def change_privilege(user, group)
target_gid = Etc.getgrnam(group).gid if group

if uid != target_uid or gid != target_gid
Mongrel.log(:info, "Initiating groups for #{user.inspect}:#{group.inspect}.")
Mongrel.log("Initiating groups for #{user.inspect}:#{group.inspect}.")
Process.initgroups(user, target_gid)

Mongrel.log(:info, "Changing group to #{group.inspect}.")
Mongrel.log("Changing group to #{group.inspect}.")
Process::GID.change_privilege(target_gid)

Mongrel.log(:info, "Changing user to #{user.inspect}." )
Mongrel.log("Changing user to #{user.inspect}." )
Process::UID.change_privilege(target_uid)
end
rescue Errno::EPERM => e
Expand All @@ -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/
Mongrel.log(:info, "Writing PID file to #{@pid_file}")
Mongrel.log("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)
Expand Down
3 changes: 1 addition & 2 deletions lib/mongrel/debug.rb
Expand Up @@ -96,8 +96,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\""
Mongrel.log(:info, "#{p['REMOTE_ADDR']} \"#{p['REQUEST_METHOD']} #{p["REQUEST_URI"]} HTTP/1.1\"")
Mongrel.log("#{p['REMOTE_ADDR']} \"#{p['REQUEST_METHOD']} #{p["REQUEST_URI"]} HTTP/1.1\"")
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/mongrel/logger.rb
Expand Up @@ -65,10 +65,10 @@ def initialize_io(log)
end

# Convenience wrapper for logging, allows us to use Mongrel.log
def self.log(level, string)
def self.log(*args)
# If no logger has been defined yet at this point, log to STDOUT.
$MongrelLogger ||= Mongrel::Log.new(STDOUT, :debug)
$MongrelLogger.log(level,string)
$MongrelLogger.log(*args)
end

end
8 changes: 4 additions & 4 deletions lib/mongrel/rails.rb
Expand Up @@ -161,9 +161,9 @@ def reload!
raise "Rails was not configured. Read the docs for RailsConfigurator."
end

Mongrel.log(:info, "Reloading Rails...")
Mongrel.log("Reloading Rails...")
@rails_handler.reload!
Mongrel.log(:info, "Done reloading Rails.")
Mongrel.log("Done reloading Rails.")

end

Expand All @@ -175,9 +175,9 @@ def setup_rails_signals(options={})

unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/
# rails reload
trap("HUP") { Mongrel.log(:info, "HUP signal received."); reload! }
trap("HUP") { Mongrel.log("HUP signal received."); reload! }

Mongrel.log(:info, "Rails signals registered. HUP => reload (without restart). It might not work well.")
Mongrel.log("Rails signals registered. HUP => reload (without restart). It might not work well.")
end
end
end
Expand Down
22 changes: 11 additions & 11 deletions projects/mongrel_cluster/lib/mongrel_cluster/init.rb
Expand Up @@ -80,20 +80,20 @@ def start
@ports.each do |port|
if @clean && pid_file_exists?(port) && !check_process(port)
pid_file = port_pid_file(port)
Mongrel.log(:info, "missing process: removing #{pid_file}")
Mongrel.log("missing process: removing #{pid_file}")
chdir_cwd do
File.unlink(pid_file)
end
end

if pid_file_exists?(port) && check_process(port)
Mongrel.log(:info, "already started port #{port}")
Mongrel.log("already started port #{port}")
next
end

exec_cmd = cmd + " -p #{port} -P #{port_pid_file(port)}"
exec_cmd += " -l #{port_log_file(port)}"
Mongrel.log(:info, "starting port #{port}")
Mongrel.log("starting port #{port}")
log_verbose exec_cmd
output = `#{exec_cmd}`
Mongrel.log(:error, output) unless $?.success?
Expand All @@ -112,17 +112,17 @@ def stop
@ports.each do |port|
pid = check_process(port)
if @clean && pid && !pid_file_exists?(port)
Mongrel.log(:info, "missing pid_file: killing mongrel_rails port #{port}, pid #{pid}")
Mongrel.log("missing pid_file: killing mongrel_rails port #{port}, pid #{pid}")
Process.kill("KILL", pid.to_i)
end

if !check_process(port)
Mongrel.log(:info, "already stopped port #{port}")
Mongrel.log("already stopped port #{port}")
next
end

exec_cmd = cmd + " -P #{port_pid_file(port)}"
Mongrel.log(:info, "stopping port #{port}")
Mongrel.log("stopping port #{port}")
log_verbose exec_cmd
output = `#{exec_cmd}`
Mongrel.log(:error, output) unless $?.success?
Expand All @@ -141,15 +141,15 @@ def status
Mongrel.log(:error, "missing pid_file: #{port_pid_file(port)}")
status = STATUS_ERROR
else
Mongrel.log(:info, "found pid_file: #{port_pid_file(port)}")
Mongrel.log("found pid_file: #{port_pid_file(port)}")
end
if pid
Mongrel.log(:info, "found mongrel_rails: port #{port}, pid #{pid}")
Mongrel.log("found mongrel_rails: port #{port}, pid #{pid}")
else
Mongrel.log(:error, "missing mongrel_rails: port #{port}")
status = STATUS_ERROR
end
Mongrel.log(:info, "")
Mongrel.log("")
end

status
Expand Down Expand Up @@ -212,7 +212,7 @@ def find_pid(port)
end

def log_verbose(message)
Mongrel.log(:info, message) if @verbose
Mongrel.log(message) if @verbose
end

end
Expand Down Expand Up @@ -329,7 +329,7 @@ def run
@options["group"] = @group if @group
@options["prefix"] = @prefix if @prefix

Mongrel.log(:info, "Writing configuration file to #{@config_file}.")
Mongrel.log("Writing configuration file to #{@config_file}.")
File.open(@config_file,"w") {|f| f.write(@options.to_yaml)}
end
end
Expand Down
2 changes: 1 addition & 1 deletion site/src/docs/howto.page
Expand Up @@ -398,7 +398,7 @@ You can use the -S configure script to add your own handlers
with code like this:

<pre><code>
trap("USR1") { Mongrel.log(:info, "I'm doing stuff.") }
trap("USR1") { Mongrel.log("I'm doing stuff.") }
</code></pre>


Expand Down

0 comments on commit 8aaaf16

Please sign in to comment.