diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicorn.rb | 3 | ||||
-rw-r--r-- | lib/unicorn/configurator.rb | 34 | ||||
-rw-r--r-- | lib/unicorn/http_request.rb | 2 |
3 files changed, 29 insertions, 10 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 998f8b8..d5867b1 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -90,6 +90,9 @@ module Unicorn listen(Const::DEFAULT_LISTENER) if @listeners.empty? self.pid = @config[:pid] build_app! if @preload_app + $stderr.reopen(@stderr_path, "a") if @stderr_path + $stdout.reopen(@stdout_path, "a") if @stdout_path + $stderr.sync = $stdout.sync = true spawn_missing_workers self end diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb index 65b29c6..a51dcd3 100644 --- a/lib/unicorn/configurator.rb +++ b/lib/unicorn/configurator.rb @@ -4,7 +4,7 @@ module Unicorn class Configurator include ::Unicorn::SocketHelper - DEFAULT_LOGGER = Logger.new(STDERR) unless defined?(DEFAULT_LOGGER) + DEFAULT_LOGGER = Logger.new($stderr) unless defined?(DEFAULT_LOGGER) DEFAULTS = { :timeout => 60, @@ -24,6 +24,8 @@ module Unicorn :pid => nil, :backlog => 1024, :preload_app => false, + :stderr_path => nil, + :stdout_path => nil, } attr_reader :config_file @@ -130,14 +132,7 @@ module Unicorn end # sets the +path+ for the PID file of the unicorn master process - def pid(path) - if path - path = File.expand_path(path) - File.writable?(File.dirname(path)) or raise ArgumentError, - "directory for pid=#{path} not writable" - end - @set[:pid] = path - end + def pid(path); set_path(:pid, path); end def directory(path) @set[:directory] = path ? File.expand_path(path) : nil @@ -152,8 +147,29 @@ module Unicorn end end + def stderr_path(path) + set_path(:stderr_path, path) + end + + def stdout_path(path) + set_path(:stdout_path, path) + end + private + def set_path(var, path) #:nodoc: + case path + when NilClass + when String + path = File.expand_path(path) + File.writable?(File.dirname(path)) or \ + raise ArgumentError, "directory for #{var}=#{path} not writable" + else + raise ArgumentError + end + @set[var] = path + end + def set_hook(var, my_proc) #:nodoc: case my_proc when Proc diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 9571754..6e909b6 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -133,7 +133,7 @@ module Unicorn @params.delete "HTTP_CONTENT_LENGTH" @params.update({ "rack.version" => [0,1], "rack.input" => @body, - "rack.errors" => STDERR, + "rack.errors" => $stderr, "rack.multithread" => false, "rack.multiprocess" => true, "rack.run_once" => false, |