Changeset 917
- Timestamp:
- 12/17/07 12:15:22 (8 months ago)
- Files:
-
- trunk/bin/mongrel_rails (modified) (3 diffs)
- trunk/lib/mongrel.rb (modified) (2 diffs)
- trunk/lib/mongrel/configurator.rb (modified) (7 diffs)
- trunk/lib/mongrel/logger.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/bin/mongrel_rails
r916 r917 75 75 def run 76 76 if @generate 77 @generate = File.expand_path(@generate)77 @generate = File.expand_path(@generate) 78 78 Mongrel.log(:error, "** Writing config to \"#@generate\".") 79 79 open(@generate, "w") {|f| f.write(settings.to_yaml) } … … 85 85 if defaults[:daemon] 86 86 if File.exist? defaults[:pid_file] 87 Mongrel. error(:info, "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors.")87 Mongrel.log(:error, "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors.") 88 88 Mongrel.log(:error, "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start.") 89 89 exit 1 … … 95 95 end 96 96 97 Mongrel.log(:info, "Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]} ")97 Mongrel.log(:info, "Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}, further information can be found in log/mongrel-#{defaults[:host]}-#{defaults[:port]}.log") 98 98 99 99 listener do trunk/lib/mongrel.rb
r916 r917 55 55 # You use it by doing the following: 56 56 # 57 # server = HttpServer.new("0.0.0.0", 3000)57 # server = 2("0.0.0.0", 3000) 58 58 # server.register("/stuff", MyNiftyHandler.new) 59 59 # server.run.join … … 103 103 @num_processors = num_processors 104 104 @timeout = timeout 105 # Mongrel.logger = Mongrel::Log.new(log || "mongrel-#{port}.log") 106 @logger = Mongrel::Log.new(log || "mongrel-#{port}.log", log_level) 107 end 108 105 @logger = Mongrel::Log.new(log || "log/mongrel-#{host}-#{port}.log", log_level) 106 end 107 109 108 # Does the majority of the IO processing. It has been written in Ruby using 110 109 # about 7 different IO processing strategies and no matter how it's done trunk/lib/mongrel/configurator.rb
r916 r917 132 132 def listener(options={},&block) 133 133 raise "Cannot call listener inside another listener block." if (@listener or @listener_name) 134 ops = resolve_defaults(options) 135 ops[:num_processors] ||= 950 136 ops[:throttle] ||= 0 137 ops[:timeout] ||= 60 138 139 @listener = Mongrel::HttpServer.new(ops[:host], ops[:port].to_i, ops[:num_processors].to_i, ops[:throttle].to_i, ops[:timeout].to_i) 140 @listener_name = "#{ops[:host]}:#{ops[:port]}" 134 opts = resolve_defaults(options) 135 opts[:num_processors] ||= 950 136 opts[:throttle] ||= 0 137 opts[:timeout] ||= 60 138 139 @listener = Mongrel::HttpServer.new( 140 opts[:host], opts[:port].to_i, opts[:num_processors].to_i, 141 opts[:throttle].to_i, opts[:timeout].to_i, 142 opts[:log], opts[:log_level] 143 ) 144 @listener_name = "#{opts[:host]}:#{opts[:port]}" 141 145 @listeners[@listener_name] = @listener 142 146 143 if op s[:user] and ops[:group]144 change_privilege(op s[:user], ops[:group])147 if opts[:user] and opts[:group] 148 change_privilege(opts[:user], opts[:group]) 145 149 end 146 150 … … 164 168 # * :in_front => true/false -- Rather than appending, it prepends this handler. 165 169 def uri(location, options={}) 166 op s = resolve_defaults(options)167 @listener.register(location, op s[:handler], ops[:in_front])170 opts = resolve_defaults(options) 171 @listener.register(location, opts[:handler], opts[:in_front]) 168 172 end 169 173 … … 184 188 # gem/library if NOT win32. 185 189 def daemonize(options={}) 186 op s = resolve_defaults(options)190 opts = resolve_defaults(options) 187 191 # save this for later since daemonize will hose it 188 192 unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ 189 193 require 'daemons/daemonize' 190 194 191 logfile = op s[:log_file]195 logfile = opts[:log_file] 192 196 if logfile[0].chr != "/" 193 logfile = File.join(op s[:cwd],logfile)197 logfile = File.join(opts[:cwd],logfile) 194 198 if not File.exist?(File.dirname(logfile)) 195 199 Mongrel.log(:critical, "!!! Log file directory not found at full path #{File.dirname(logfile)}. Update your configuration to use a full path.") … … 201 205 202 206 # change back to the original starting directory 203 Dir.chdir(op s[:cwd])207 Dir.chdir(opts[:cwd]) 204 208 205 209 else … … 214 218 # or exclude from the determining the dependencies. 215 219 def load_plugins(options={}) 216 op s = resolve_defaults(options)220 opts = resolve_defaults(options) 217 221 218 222 load_settings = {} 219 if op s[:includes]220 op s[:includes].each do |plugin|223 if opts[:includes] 224 opts[:includes].each do |plugin| 221 225 load_settings[plugin] = GemPlugin::INCLUDE 222 226 end 223 227 end 224 228 225 if op s[:excludes]226 op s[:excludes].each do |plugin|229 if opts[:excludes] 230 opts[:excludes].each do |plugin| 227 231 load_settings[plugin] = GemPlugin::EXCLUDE 228 232 end … … 260 264 # are merged with the defaults prior to passing them in. 261 265 def plugin(name, options={}) 262 op s = resolve_defaults(options)263 GemPlugin::Manager.instance.create(name, op s)266 opts = resolve_defaults(options) 267 GemPlugin::Manager.instance.create(name, opts) 264 268 end 265 269 … … 359 363 # This command is safely ignored if the platform is win32 (with a warning) 360 364 def setup_signals(options={}) 361 op s = resolve_defaults(options)365 opts = resolve_defaults(options) 362 366 363 367 # forced shutdown, even if previously restarted (actually just like TERM but for CTRL-C) trunk/lib/mongrel/logger.rb
r916 r917 9 9 10 10 Levels = { 11 :name => { :emergency => 0, :alert => 1, :critical => 2, :error => 3, :warning => 4, :notice => 5, :info => 6, :debug => 7 }, 12 :id => { 0 => :emergency, 1 => :alert, 2 => :critical, 3 => :error, 4 => :warning, 5 => :notice, 6 => :info, 7 => :debug } 11 :name => { :emergency => 0, :alert => 1, :critical => 2, :error => 3, 12 :warning => 4, :notice => 5, :info => 6, :debug => 7 }, 13 :id => { 0 => :emergency, 1 => :alert, 2 => :critical, 3 => :error, 14 4 => :warning, 5 => :notice, 6 => :info, 7 => :debug } 13 15 } 14 16 15 17 def initialize(log, log_level = :debug) 16 18 @logger = initialize_io(log) 17 @log_level = Levels[:name][log_level] 19 @log_level = Levels[:name][log_level] || 7 18 20 19 21 if !RUBY_PLATFORM.match(/java|mswin/) && !(@log == STDOUT) && … … 27 29 # higher than the logger's log level. If the logger responds to write_nonblock and is not on 28 30 # the java or windows platforms then the logger will use non-blocking asynchronous writes. 29 def log(level, string) 30 return if (Levels[:name][level] > @log_level) 31 def log(*args) 32 if args[0].is_a?(String) 33 level, string = 6, args[0] 34 else 35 level = (args[0].is_a?(Fixnum) ? args[0] : Levels[:name][args[0]]) || 6 36 string = args[1] 37 end 38 39 return if (level > log_level) 40 31 41 if @aio 32 @log.write_nonblock("#{Time.now.httpdate} :#{string}\n")42 @log.write_nonblock("#{Time.now.httpdate} | #{Levels[:id][level]} | #{string}\n") 33 43 else 34 @log.write("#{Time.now.httpdate} :#{string}\n")44 @log.write("#{Time.now.httpdate} | #{Levels[:id][level]} | #{string}\n") 35 45 end 36 46 end … … 46 56 @log.sync = true 47 57 else 58 FileUtils.mkdir_p(File.dirname(log)) unless File.exists?(File.dirname(log)) 48 59 @log = open(log, (File::WRONLY | File::APPEND | File::CREAT)) 49 60 @log.sync = true 50 @log.write("#{Time.now.httpdate} Logfile created\n")61 @log.write("#{Time.now.httpdate} | info | Logfile created\n") 51 62 end 52 63 end … … 56 67 # Convenience wrapper for logging, allows us to use Mongrel.log 57 68 def self.log(level, string) 58 # If no logger was defined, log to STDOUT.69 # If no logger has been defined yet at this point, log to STDOUT. 59 70 $MongrelLogger ||= Mongrel::Log.new(STDOUT, :debug) 60 71 $MongrelLogger.log(level,string)
