Benedikt Böhm
2012-Mar-22 07:14 UTC
[PATCH] make stderr_path/stdout_path support IO objects directly
---
lib/unicorn/configurator.rb | 2 +-
lib/unicorn/http_server.rb | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 89cbf5c..c9b6816 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -559,7 +559,7 @@ private
def set_path(var, path) #:nodoc:
case path
- when NilClass, String
+ when NilClass, String, IO
set[var] = path
else
raise ArgumentError
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index 0c2af5d..bd71fbf 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -698,7 +698,11 @@ class Unicorn::HttpServer
end
def redirect_io(io, path)
- File.open(path, ''ab'') { |fp| io.reopen(fp) } if path
+ if path.is_a?(IO)
+ io.reopen(path)
+ elsif path
+ io.reopen(path, ''ab'')
+ end
io.sync = true
end
--
1.7.4.5
Eric Wong
2012-Mar-22 08:00 UTC
[PATCH] make stderr_path/stdout_path support IO objects directly
Benedikt B?hm <bb at xnull.de> wrote: Hello, can you explain in the commit message why this functionality is useful to have? SIGUSR1 log file reopening only works because it relies on knowing File#path on File objects> --- > lib/unicorn/configurator.rb | 2 +- > lib/unicorn/http_server.rb | 6 +++++- > 2 files changed, 6 insertions(+), 2 deletions(-)Test cases for new functionality would be nice, too.