Skip to content

Commit

Permalink
don't try to redirect stdout/stderr to the logfile.
Browse files Browse the repository at this point in the history
Logging to a logfile should be explicit and gunicorn should not try to
be smarter here. Partially fix #591
  • Loading branch information
benoitc committed Jan 1, 2014
1 parent 141aa9d commit 4152318
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions gunicorn/glogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import socket
import sys
import traceback
import threading

from gunicorn import util
from gunicorn.six import string_types
Expand Down Expand Up @@ -164,25 +163,13 @@ def __init__(self, cfg):
self.error_handlers = []
self.access_handlers = []
self.cfg = cfg
self.logfile = None
self.lock = threading.Lock()
self.setup(cfg)

def setup(self, cfg):
loglevel = self.LOG_LEVELS.get(cfg.loglevel.lower(), logging.INFO)
self.error_log.setLevel(loglevel)
self.access_log.setLevel(logging.INFO)

if cfg.errorlog != "-":
# if an error log file is set redirect stdout & stderr to
# this log file.
for stream in sys.stdout, sys.stderr:
stream.flush()

self.logfile = open(cfg.errorlog, 'a+')
os.dup2(self.logfile.fileno(), sys.stdout.fileno())
os.dup2(self.logfile.fileno(), sys.stderr.fileno())

# set gunicorn.error handler
self._set_handler(self.error_log, cfg.errorlog,
logging.Formatter(self.error_fmt, self.datefmt))
Expand Down Expand Up @@ -287,20 +274,6 @@ def now(self):
now.year, now.hour, now.minute, now.second)

def reopen_files(self):
if self.cfg.errorlog != "-":
# if an error log file is set redirect stdout & stderr to
# this log file.
for stream in sys.stdout, sys.stderr:
stream.flush()

with self.lock:
if self.logfile is not None:
self.logfile.close()

self.logfile = open(self.cfg.errorlog, 'a+')
os.dup2(self.logfile.fileno(), sys.stdout.fileno())
os.dup2(self.logfile.fileno(), sys.stderr.fileno())

for log in loggers():
for handler in log.handlers:
if isinstance(handler, logging.FileHandler):
Expand Down

0 comments on commit 4152318

Please sign in to comment.