diff options
Diffstat (limited to 'lib/mongrel')
-rw-r--r-- | lib/mongrel/command.rb | 12 | ||||
-rw-r--r-- | lib/mongrel/configurator.rb | 30 | ||||
-rw-r--r-- | lib/mongrel/debug.rb | 2 | ||||
-rw-r--r-- | lib/mongrel/logger.rb | 17 | ||||
-rw-r--r-- | lib/mongrel/rails.rb | 8 |
5 files changed, 33 insertions, 36 deletions
diff --git a/lib/mongrel/command.rb b/lib/mongrel/command.rb index a3ee57d..d99208e 100644 --- a/lib/mongrel/command.rb +++ b/lib/mongrel/command.rb @@ -55,14 +55,14 @@ module Mongrel # 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 @@ module Mongrel # 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 @@ module Mongrel 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 diff --git a/lib/mongrel/configurator.rb b/lib/mongrel/configurator.rb index 0bb3c62..0d5aa37 100644 --- a/lib/mongrel/configurator.rb +++ b/lib/mongrel/configurator.rb @@ -59,18 +59,18 @@ module Mongrel 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 @@ module Mongrel # 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 @@ module Mongrel 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 @@ module Mongrel 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 @@ module Mongrel 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 @@ module Mongrel 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 diff --git a/lib/mongrel/debug.rb b/lib/mongrel/debug.rb index 220af60..d2363fb 100644 --- a/lib/mongrel/debug.rb +++ b/lib/mongrel/debug.rb @@ -97,7 +97,7 @@ module RequestLog 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 diff --git a/lib/mongrel/logger.rb b/lib/mongrel/logger.rb index e3dee7f..1adb593 100644 --- a/lib/mongrel/logger.rb +++ b/lib/mongrel/logger.rb @@ -3,10 +3,6 @@ # Merb: http://merbivore.com module Mongrel - #class << self - # attr_accessor :logger - #end - class Log attr_accessor :logger attr_accessor :log_level @@ -20,12 +16,11 @@ module Mongrel @logger = initialize_io(log) @log_level = Levels[:name][log_level] - if !RUBY_PLATFORM.match(/java|mswin/) && - !(@log == STDOUT) && - @log.respond_to?(:write_nonblock) - + if !RUBY_PLATFORM.match(/java|mswin/) && !(@log == STDOUT) && + @log.respond_to?(:write_nonblock) @aio = true end + $MongrelLogger = self end # Writes a string to the logger. Writing of the string is skipped if the string's log level is @@ -52,7 +47,7 @@ module Mongrel else @log = open(log, (File::WRONLY | File::APPEND | File::CREAT)) @log.sync = true - @log.write("#{Time.now.httpdate} Logfile created") + @log.write("#{Time.now.httpdate} Logfile created\n") end end @@ -60,7 +55,9 @@ module Mongrel # Convenience wrapper for logging, allows us to use Mongrel.log def self.log(level, string) - logger.log(level,string) + # If no logger was defined, log to STDOUT. + $MongrelLogger ||= Mongrel::Log.new(STDOUT, :debug) + $MongrelLogger.log(level,string) end end diff --git a/lib/mongrel/rails.rb b/lib/mongrel/rails.rb index f0ecff6..62f7d67 100644 --- a/lib/mongrel/rails.rb +++ b/lib/mongrel/rails.rb @@ -161,9 +161,9 @@ module Mongrel raise "Rails was not configured. Read the docs for RailsConfigurator." end - log "Reloading Rails..." + Mongrel.log(:info, "Reloading Rails...") @rails_handler.reload! - log "Done reloading Rails." + Mongrel.log(:info, "Done reloading Rails.") end @@ -175,9 +175,9 @@ module Mongrel unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ # rails reload - trap("HUP") { log "HUP signal received."; reload! } + trap("HUP") { Mongrel.log(:info, "HUP signal received."); reload! } - log "Rails signals registered. HUP => reload (without restart). It might not work well." + Mongrel.log(:info, "Rails signals registered. HUP => reload (without restart). It might not work well.") end end end |