diff options
Diffstat (limited to 'lib/mongrel')
-rw-r--r-- | lib/mongrel/cgi.rb | 7 | ||||
-rw-r--r-- | lib/mongrel/command.rb | 14 | ||||
-rw-r--r-- | lib/mongrel/configurator.rb | 99 | ||||
-rw-r--r-- | lib/mongrel/const.rb | 8 | ||||
-rw-r--r-- | lib/mongrel/debug.rb | 30 | ||||
-rw-r--r-- | lib/mongrel/gems.rb | 2 | ||||
-rw-r--r-- | lib/mongrel/handlers.rb | 28 | ||||
-rw-r--r-- | lib/mongrel/http_request.rb | 10 | ||||
-rw-r--r-- | lib/mongrel/http_response.rb | 9 | ||||
-rw-r--r-- | lib/mongrel/logger.rb | 74 | ||||
-rw-r--r-- | lib/mongrel/rails.rb | 12 |
11 files changed, 107 insertions, 186 deletions
diff --git a/lib/mongrel/cgi.rb b/lib/mongrel/cgi.rb index e2ac10c..3957611 100644 --- a/lib/mongrel/cgi.rb +++ b/lib/mongrel/cgi.rb @@ -26,7 +26,7 @@ module Mongrel # Refer to DirHandler#can_serve for more information on this. class CGIWrapper < ::CGI public :env_table - attr_reader :options + attr_reader :head attr_accessor :handler # Set this to false if you want calls to CGIWrapper.out to not actually send # the response until you force it. @@ -105,7 +105,7 @@ module Mongrel when Hash cookie.each_value {|c| to['Set-Cookie'] = c.to_s} else - to['Set-Cookie'] = options['cookie'].to_s + to['Set-Cookie'] = head['cookie'].to_s end @head.delete('cookie') @@ -173,10 +173,9 @@ module Mongrel # The stdoutput should be completely bypassed but we'll drop a warning just in case def stdoutput - STDERR.puts "#{Time.now.httpdate}: WARNING: Your program is doing something not expected. Please tell Zed that stdoutput was used and what software you are running. Thanks." + STDERR.puts "WARNING: Your program is doing something not expected. Please tell Zed that stdoutput was used and what software you are running. Thanks." @response.body end end - end diff --git a/lib/mongrel/command.rb b/lib/mongrel/command.rb index df993d6..a3ee57d 100644 --- a/lib/mongrel/command.rb +++ b/lib/mongrel/command.rb @@ -55,13 +55,15 @@ 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 - Mongrel.log(@opt) + puts @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 - Mongrel.log("Version #{Mongrel::Const::MONGREL_VERSION}") + if VERSION + puts "Version #{Mongrel::Const::MONGREL_VERSION}" + end end @opt.parse! argv @@ -153,17 +155,17 @@ module Mongrel # Prints a list of available commands. def print_command_list - Mongrel.log("#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n") + puts "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n" self.commands.each do |name| if /mongrel::/ =~ name name = name[9 .. -1] end - Mongrel.log(" - #{name[1 .. -1]}\n") + puts " - #{name[1 .. -1]}\n" end - Mongrel.log("\nEach command takes -h as an option to get help.") + puts "\nEach command takes -h as an option to get help." end @@ -178,7 +180,7 @@ module Mongrel print_command_list return true elsif cmd_name == "--version" - Mongrel.log("Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}") + puts "Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}" return true end diff --git a/lib/mongrel/configurator.rb b/lib/mongrel/configurator.rb index 26035b8..439b44c 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 - Mongrel.log("Initiating groups for #{user.inspect}:#{group.inspect}.") + log "Initiating groups for #{user.inspect}:#{group.inspect}." Process.initgroups(user, target_gid) - Mongrel.log("Changing group to #{group.inspect}.") + log "Changing group to #{group.inspect}." Process::GID.change_privilege(target_gid) - Mongrel.log("Changing user to #{user.inspect}." ) + log "Changing user to #{user.inspect}." Process::UID.change_privilege(target_uid) end rescue Errno::EPERM => e - Mongrel.log(:critical, "Couldn't change user and group to #{user.inspect}:#{group.inspect}: #{e.to_s}.") - Mongrel.log(:critical, "Mongrel failed to start.") + log "Couldn't change user and group to #{user.inspect}:#{group.inspect}: #{e.to_s}." + log "Mongrel failed to start." exit 1 end end @@ -81,13 +81,13 @@ 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/ - Mongrel.log("Writing PID file to #{@pid_file}") + if RUBY_PLATFORM !~ /djgpp|(cyg|ms|bcc)win|mingw/ + 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) File.chmod(0644, @pid_file) - end + end end end @@ -131,21 +131,17 @@ module Mongrel # def listener(options={},&block) raise "Cannot call listener inside another listener block." if (@listener or @listener_name) - opts = resolve_defaults(options) - opts[:num_processors] ||= 950 - opts[:throttle] ||= 0 - opts[:timeout] ||= 60 - - @listener = Mongrel::HttpServer.new( - opts[:host], opts[:port].to_i, opts[:num_processors].to_i, - opts[:throttle].to_i, opts[:timeout].to_i, - opts[:log], opts[:log_level] - ) - @listener_name = "#{opts[:host]}:#{opts[:port]}" + ops = resolve_defaults(options) + ops[:num_processors] ||= 950 + ops[:throttle] ||= 0 + ops[:timeout] ||= 60 + + @listener = Mongrel::HttpServer.new(ops[:host], ops[:port].to_i, ops[:num_processors].to_i, ops[:throttle].to_i, ops[:timeout].to_i) + @listener_name = "#{ops[:host]}:#{ops[:port]}" @listeners[@listener_name] = @listener - if opts[:user] and opts[:group] - change_privilege(opts[:user], opts[:group]) + if ops[:user] and ops[:group] + change_privilege(ops[:user], ops[:group]) end # Does the actual cloaking operation to give the new implicit self. @@ -167,8 +163,8 @@ module Mongrel # * :handler => HttpHandler -- Handler to use for this location. # * :in_front => true/false -- Rather than appending, it prepends this handler. def uri(location, options={}) - opts = resolve_defaults(options) - @listener.register(location, opts[:handler], opts[:in_front]) + ops = resolve_defaults(options) + @listener.register(location, ops[:handler], ops[:in_front]) end @@ -187,16 +183,16 @@ module Mongrel # It is safe to call this on win32 as it will only require the daemons # gem/library if NOT win32. def daemonize(options={}) - opts = resolve_defaults(options) + ops = resolve_defaults(options) # save this for later since daemonize will hose it - unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ + if RUBY_PLATFORM !~ /djgpp|(cyg|ms|bcc)win|mingw/ require 'daemons/daemonize' - logfile = opts[:log_file] + logfile = ops[:log_file] if logfile[0].chr != "/" - logfile = File.join(opts[:cwd],logfile) + logfile = File.join(ops[:cwd],logfile) if not File.exist?(File.dirname(logfile)) - Mongrel.log(:critical, "!!! Log file directory not found at full path #{File.dirname(logfile)}. Update your configuration to use a full path.") + log "!!! Log file directory not found at full path #{File.dirname(logfile)}. Update your configuration to use a full path." exit 1 end end @@ -204,10 +200,10 @@ module Mongrel Daemonize.daemonize(logfile) # change back to the original starting directory - Dir.chdir(opts[:cwd]) + Dir.chdir(ops[:cwd]) else - Mongrel.log(:warning, "WARNING: Win32 does not support daemon mode.") + log "WARNING: Win32 does not support daemon mode." end end @@ -217,17 +213,17 @@ module Mongrel # :excludes => [] setting listing the names of plugins to include # or exclude from the determining the dependencies. def load_plugins(options={}) - opts = resolve_defaults(options) + ops = resolve_defaults(options) load_settings = {} - if opts[:includes] - opts[:includes].each do |plugin| + if ops[:includes] + ops[:includes].each do |plugin| load_settings[plugin] = GemPlugin::INCLUDE end end - if opts[:excludes] - opts[:excludes].each do |plugin| + if ops[:excludes] + ops[:excludes].each do |plugin| load_settings[plugin] = GemPlugin::EXCLUDE end end @@ -253,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| Mongrel.log(:warning, "WARNING: MIME type #{k} must start with '.'") if k.index(".") != 0 } + mime.each {|k,v| log "WARNING: MIME type #{k} must start with '.'" if k.index(".") != 0 } return mime end @@ -263,8 +259,8 @@ module Mongrel # name and configured with the selected options. The options # are merged with the defaults prior to passing them in. def plugin(name, options={}) - opts = resolve_defaults(options) - GemPlugin::Manager.instance.create(name, opts) + ops = resolve_defaults(options) + GemPlugin::Manager.instance.create(name, ops) end # Lets you do redirects easily as described in Mongrel::RedirectHandler. @@ -348,7 +344,7 @@ module Mongrel # it reads it in and does an eval on the contents passing in the right # binding so they can put their own Configurator statements. def run_config(script) - open(script) {|f| eval(f.read, proc {self}.binding) } + open(script) {|f| eval(f.read, proc {self}) } end # Sets up the standard signal handlers that are used on most Ruby @@ -362,28 +358,31 @@ module Mongrel # # This command is safely ignored if the platform is win32 (with a warning) def setup_signals(options={}) - opts = resolve_defaults(options) + ops = resolve_defaults(options) # forced shutdown, even if previously restarted (actually just like TERM but for CTRL-C) - trap("INT") { Mongrel.log(:notice, "INT signal received."); stop(false) } + trap("INT") { log "INT signal received."; stop(false) } - # always clean up the pid file + # clean up the pid file always at_exit { remove_pid_file } - unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ + if RUBY_PLATFORM !~ /djgpp|(cyg|ms|bcc)win|mingw/ # graceful shutdown - trap("TERM") { Mongrel.log(:notice, "TERM signal received."); stop } - # debug mode - trap("USR1") { Mongrel.log(:notice, "USR1 received, toggling $mongrel_debug_client to #{!$mongrel_debug_client}"); $mongrel_debug_client = !$mongrel_debug_client } + trap("TERM") { log "TERM signal received."; stop } + trap("USR1") { log "USR1 received, toggling $mongrel_debug_client to #{!$mongrel_debug_client}"; $mongrel_debug_client = !$mongrel_debug_client } # restart - trap("USR2") { Mongrel.log(:notice, "USR2 signal received."); stop(true) } + trap("USR2") { log "USR2 signal received."; stop(true) } - Mongrel.log(:notice, "Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).") + log "Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart)." else - Mongrel.log(:notice, "Signals ready. INT => stop (no restart).") + log "Signals ready. INT => stop (no restart)." end end - end + # Logs a simple message to STDERR (or the mongrel log if in daemon mode). + def log(msg) + STDERR.print "** ", msg, "\n" + end + end end diff --git a/lib/mongrel/const.rb b/lib/mongrel/const.rb index e01df15..a9b100e 100644 --- a/lib/mongrel/const.rb +++ b/lib/mongrel/const.rb @@ -65,13 +65,10 @@ module Mongrel REQUEST_URI='REQUEST_URI'.freeze REQUEST_PATH='REQUEST_PATH'.freeze - MONGREL_VERSION="1.2".freeze + MONGREL_VERSION="1.2.0".freeze MONGREL_TMP_BASE="mongrel".freeze - # A standard 400 response for a request which generates a http parse exception - ERROR_400_RESPONSE="HTTP/1.1 400 Bad Request\r\nConnection: close\r\nServer: Mongrel #{MONGREL_VERSION}\r\n\r\nBAD REQUEST".freeze - # The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff. ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: Mongrel #{MONGREL_VERSION}\r\n\r\nNOT FOUND".freeze @@ -110,5 +107,4 @@ module Mongrel REDIRECT = "HTTP/1.1 302 Found\r\nLocation: %s\r\nConnection: close\r\n\r\n".freeze HOST = "HOST".freeze end - -end +end
\ No newline at end of file diff --git a/lib/mongrel/debug.rb b/lib/mongrel/debug.rb index 7bde9ec..2686c1e 100644 --- a/lib/mongrel/debug.rb +++ b/lib/mongrel/debug.rb @@ -16,7 +16,7 @@ module MongrelDbg def MongrelDbg::configure(log_dir = File.join("log","mongrel_debug")) FileUtils.mkdir_p(log_dir) @log_dir = log_dir - $objects_out = open(File.join("log","mongrel_debug","objects.log"),"w") + $objects_out=open(File.join("log","mongrel_debug","objects.log"),"w") $objects_out.puts "run,classname,last,count,delta,lenmean,lensd,lenmax" $objects_out.sync = true $last_stat = nil @@ -35,12 +35,12 @@ module MongrelDbg if not LOGGING[target] LOGGING[target] = Logger.new(File.join(@log_dir, "#{target.to_s}.log")) end - MongrelDbg::trace(target, "#{Time.now.httpdate}: TRACING ON") + MongrelDbg::trace(target, "TRACING ON #{Time.now}") end def MongrelDbg::end_trace(target) SETTINGS[:tracing][target] = false - MongrelDbg::trace(target, "#{Time.now.httpdate}: TRACING OFF") + MongrelDbg::trace(target, "TRACING OFF #{Time.now}") LOGGING[target].close LOGGING[target] = nil end @@ -86,17 +86,20 @@ module Kernel end MongrelDbg::trace(:files, open_counts.to_yaml) end -end +end + module RequestLog + # Just logs whatever requests it gets to STDERR (which ends up in the mongrel + # log when daemonized). class Access < GemPlugin::Plugin "/handlers" include Mongrel::HttpHandlerPlugin def process(request,response) p = request.params - Mongrel.log("#{p['REMOTE_ADDR']} \"#{p['REQUEST_METHOD']} #{p["REQUEST_URI"]} HTTP/1.1\"") + STDERR.puts "#{p['REMOTE_ADDR']} - [#{Time.now.httpdate}] \"#{p['REQUEST_METHOD']} #{p["REQUEST_URI"]} HTTP/1.1\"" end end @@ -105,13 +108,12 @@ module RequestLog include Mongrel::HttpHandlerPlugin def process(request, response) - MongrelDbg::trace(:files, "#{Time.now.httpdate}: FILES OPEN BEFORE REQUEST #{request.params['PATH_INFO']}") + MongrelDbg::trace(:files, "#{Time.now} FILES OPEN BEFORE REQUEST #{request.params['PATH_INFO']}") log_open_files end end - # stolen from Robert Klemme class Objects < GemPlugin::Plugin "/handlers" include Mongrel::HttpHandlerPlugin @@ -123,7 +125,7 @@ module RequestLog begin ObjectSpace.each_object do |o| begin - if o.respond_to?(:length) + if o.respond_to? :length len = o.length lengths[o.class] ||= Mongrel::Stats.new(o.class) lengths[o.class].sample(len) @@ -152,28 +154,26 @@ module RequestLog $run_count += 1 $last_stat = stats rescue Object - STDERR.puts "#{Time.now.httpdate}: object.log ERROR: #$!" + STDERR.puts "object.log ERROR: #$!" end end end - class Params < GemPlugin::Plugin "/handlers" include Mongrel::HttpHandlerPlugin def process(request, response) - MongrelDbg::trace(:rails, "#{Time.now.httpdate}: REQUEST #{request.params['PATH_INFO']}") + MongrelDbg::trace(:rails, "#{Time.now} REQUEST #{request.params['PATH_INFO']}") MongrelDbg::trace(:rails, request.params.to_yaml) end end - class Threads < GemPlugin::Plugin "/handlers" include Mongrel::HttpHandlerPlugin def process(request, response) - MongrelDbg::trace(:threads, "#{Time.now.httpdate}: REQUEST #{request.params['PATH_INFO']}") + MongrelDbg::trace(:threads, "#{Time.now} REQUEST #{request.params['PATH_INFO']}") begin ObjectSpace.each_object do |obj| begin @@ -185,7 +185,7 @@ module RequestLog worker_list.each {|t| keys << "\n\t\t-- #{t}: #{t.keys.inspect}" } end - MongrelDbg::trace(:threads, "#{Time.now.httpdate}: #{obj.host}:#{obj.port} -- THREADS: #{worker_list.length} #{keys}") + MongrelDbg::trace(:threads, "#{obj.host}:#{obj.port} -- THREADS: #{worker_list.length} #{keys}") end rescue Object # Ignore since obj.class can sometimes take parameters end @@ -198,6 +198,6 @@ end END { - MongrelDbg::trace(:files, "#{Time.now.httpdate}: FILES OPEN AT EXIT") + MongrelDbg::trace(:files, "FILES OPEN AT EXIT") log_open_files } diff --git a/lib/mongrel/gems.rb b/lib/mongrel/gems.rb index 7c09b42..eb6d0d6 100644 --- a/lib/mongrel/gems.rb +++ b/lib/mongrel/gems.rb @@ -19,4 +19,4 @@ module Mongrel end end -end +end
\ No newline at end of file diff --git a/lib/mongrel/handlers.rb b/lib/mongrel/handlers.rb index bcee6a0..e643025 100644 --- a/lib/mongrel/handlers.rb +++ b/lib/mongrel/handlers.rb @@ -8,7 +8,6 @@ require 'mongrel/stats' require 'zlib' require 'yaml' - module Mongrel # You implement your application handler with this. It's very light giving @@ -102,7 +101,8 @@ module Mongrel # # If you pass nil as the root path, it will not check any locations or # expand any paths. This lets you serve files from multiple drives - # on win32. + # on win32. It should probably not be used in a public-facing way + # without additional checks. # # The default content type is "text/plain; charset=ISO-8859-1" but you # can change it anything you want using the DirHandler.default_content_type @@ -120,7 +120,7 @@ module Mongrel # You give it the path to the directory root and and optional listing_allowed and index_html def initialize(path, listing_allowed=true, index_html="index.html") @path = File.expand_path(path) if path - @listing_allowed=listing_allowed + @listing_allowed = listing_allowed @index_html = index_html @default_content_type = "application/octet-stream".freeze end @@ -132,12 +132,8 @@ module Mongrel # Add the drive letter or root path req_path = File.join(@path, req_path) if @path req_path = File.expand_path req_path - - # do not remove the check for @path at the beginning, it's what prevents - # the serving of arbitrary files (and good programmer Rule #1 Says: If - # you don't understand something, it's not because I'm stupid, it's - # because you are). - if req_path.index(@path) == 0 and File.exist? req_path + + if File.exist? req_path and (!@path or req_path.index(@path) == 0) # It exists and it's in the right location if File.directory? req_path # The request is for a directory @@ -157,7 +153,7 @@ module Mongrel return req_path end else - # does not exist or isn't in the right spot or isn't valid because not start with @path + # does not exist or isn't in the right spot return nil end end @@ -209,11 +205,11 @@ module Mongrel # test to see if this is a conditional request, and test if # the response would be identical to the last response same_response = case - when modified_since && !last_response_time = Time.httpdate(modified_since) rescue nil then false - when modified_since && last_response_time > Time.now then false - when modified_since && mtime > last_response_time then false - when none_match && none_match == '*' then false - when none_match && !none_match.strip.split(/\s*,\s*/).include?(etag) then false + when modified_since && !last_response_time = Time.httpdate(modified_since) rescue nil : false + when modified_since && last_response_time > Time.now : false + when modified_since && mtime > last_response_time : false + when none_match && none_match == '*' : false + when none_match && !none_match.strip.split(/\s*,\s*/).include?(etag) : false else modified_since || none_match # validation successful if we get this far and at least one of the header exists end @@ -270,7 +266,7 @@ module Mongrel response.start(403) {|head,out| out.write(ONLY_HEAD_GET) } end rescue => details - STDERR.puts "#{Time.now.httpdate}: Error sending file #{req_path}: #{details}" + STDERR.puts "Error sending file #{req_path}: #{details}" end end end diff --git a/lib/mongrel/http_request.rb b/lib/mongrel/http_request.rb index 3ffff9f..c8d4ce4 100644 --- a/lib/mongrel/http_request.rb +++ b/lib/mongrel/http_request.rb @@ -89,11 +89,11 @@ module Mongrel update_request_progress(remain, total) end rescue Object => e - STDERR.puts "#{Time.now.httpdate}: Error reading HTTP body: #{e.inspect}" + STDERR.puts "#{Time.now}: Error reading HTTP body: #{e.inspect}" STDERR.puts e.backtrace.join("\n") # any errors means we should delete the file, including if the file is dumped @socket.close rescue nil - @body.delete if @body.class == Tempfile + @body.close! if @body.class == Tempfile @body = nil # signals that there was a problem end end @@ -102,14 +102,14 @@ module Mongrel if !@socket.closed? data = @socket.read(len) if !data - raise "#{Time.now.httpdate}: Socket read return nil" + raise "Socket read return nil" elsif data.length != len - raise "#{Time.now.httpdate}: Socket read returned insufficient data: #{data.length}" + raise "Socket read returned insufficient data: #{data.length}" else data end else - raise "#{Time.now.httpdate}: Socket already closed when reading." + raise "Socket already closed when reading." end end diff --git a/lib/mongrel/http_response.rb b/lib/mongrel/http_response.rb index e30bdaf..3076712 100644 --- a/lib/mongrel/http_response.rb +++ b/lib/mongrel/http_response.rb @@ -71,11 +71,14 @@ module Mongrel # sent the header or the body. This is pretty catastrophic actually. def reset if @body_sent - raise "#{Time.now.httpdate}: You have already sent the request body." + raise "You have already sent the request body." elsif @header_sent - raise "#{Time.now.httpdate}: You have already sent the request headers." + raise "You have already sent the request headers." else - @header.out.truncate(0) + # XXX Dubious ( http://mongrel.rubyforge.org/ticket/19 ) + @header.out.close + @header = HeaderOut.new(StringIO.new) + @body.close @body = StringIO.new end diff --git a/lib/mongrel/logger.rb b/lib/mongrel/logger.rb deleted file mode 100644 index b990484..0000000 --- a/lib/mongrel/logger.rb +++ /dev/null @@ -1,74 +0,0 @@ -# Note: Logger concepts are from a combination of: -# AlogR: http://alogr.rubyforge.org -# Merb: http://merbivore.com -module Mongrel - - class Log - attr_accessor :logger - attr_accessor :log_level - - Levels = { - :name => { :emergency => 0, :alert => 1, :critical => 2, :error => 3, - :warning => 4, :notice => 5, :info => 6, :debug => 7 }, - :id => { 0 => :emergency, 1 => :alert, 2 => :critical, 3 => :error, - 4 => :warning, 5 => :notice, 6 => :info, 7 => :debug } - } - - def initialize(log, log_level = :debug) - @logger = initialize_io(log) - @log_level = Levels[:name][log_level] || 7 - - 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 - # higher than the logger's log level. If the logger responds to write_nonblock and is not on - # the java or windows platforms then the logger will use non-blocking asynchronous writes. - def log(*args) - if args[0].is_a?(String) - level, string = 6, args[0] - else - level = (args[0].is_a?(Fixnum) ? args[0] : Levels[:name][args[0]]) || 6 - string = args[1] - end - - return if (level > log_level) - - if @aio - @log.write_nonblock("#{Time.now.httpdate} | #{Levels[:id][level]} | #{string}\n") - else - @log.write("#{Time.now.httpdate} | #{Levels[:id][level]} | #{string}\n") - end - end - - private - - def initialize_io(log) - if log.respond_to?(:write) - @log = log - @log.sync if log.respond_to?(:sync) - elsif File.exist?(log) - @log = open(log, (File::WRONLY | File::APPEND)) - @log.sync = true - else - FileUtils.mkdir_p(File.dirname(log)) unless File.exist?(File.dirname(log)) - @log = open(log, (File::WRONLY | File::APPEND | File::CREAT)) - @log.sync = true - @log.write("#{Time.now.httpdate} | info | Logfile created\n") - end - end - - end - - # Convenience wrapper for logging, allows us to use Mongrel.log - 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(*args) - end - -end diff --git a/lib/mongrel/rails.rb b/lib/mongrel/rails.rb index 2366ab0..7f66a5e 100644 --- a/lib/mongrel/rails.rb +++ b/lib/mongrel/rails.rb @@ -82,7 +82,7 @@ module Mongrel rescue Errno::EPIPE response.socket.close rescue Object => rails_error - STDERR.puts "#{Time.now.httpdate}: Error calling Dispatcher.dispatch #{rails_error.inspect}" + STDERR.puts "#{Time.now}: Error calling Dispatcher.dispatch #{rails_error.inspect}" STDERR.puts rails_error.backtrace.join("\n") end end @@ -161,9 +161,9 @@ module Mongrel raise "Rails was not configured. Read the docs for RailsConfigurator." end - Mongrel.log("Reloading Rails...") + log "Reloading Rails..." @rails_handler.reload! - Mongrel.log("Done reloading Rails.") + log "Done reloading Rails." end @@ -173,11 +173,11 @@ module Mongrel ops = resolve_defaults(options) setup_signals(options) - unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ + if RUBY_PLATFORM !~ /djgpp|(cyg|ms|bcc)win|mingw/ # rails reload - trap("HUP") { Mongrel.log("HUP signal received."); reload! } + trap("HUP") { log "HUP signal received."; reload! } - Mongrel.log("Rails signals registered. HUP => reload (without restart). It might not work well.") + log "Rails signals registered. HUP => reload (without restart). It might not work well." end end end |