modify log_file option

Gunicorn should generally only bother writing its own log and let
the application handle the way it want to log its own errors.

Now the log_file option will be overriden by the gunicorn options
`--error-logfile` and `--access-logfile` if they are given.
This commit is contained in:
benoitc 2013-12-27 11:50:16 +01:00
parent 5fb4b49a91
commit a0ccfa0c4f
3 changed files with 69 additions and 38 deletions

View File

@ -46,3 +46,33 @@ class=logging.Formatter
[formatter_access] [formatter_access]
format=%(message)s format=%(message)s
class=logging.Formatter class=logging.Formatter
2014-01-01 14:30:00 [15391] [INFO] Starting gunicorn 18.2
2014-01-01 14:30:00 [15391] [INFO] Listening at: http://127.0.0.1:8000 (15391)
2014-01-01 14:30:00 [15391] [INFO] Using worker: sync
2014-01-01 14:30:00 [15395] [INFO] Booting worker with pid: 15395
2014-01-01 14:30:00 [15396] [INFO] Booting worker with pid: 15396
2014-01-01 14:30:00 [15397] [INFO] Booting worker with pid: 15397
2014-01-01 14:30:02 [15397] [INFO] Worker exiting (pid: 15397)
2014-01-01 14:30:02 [15396] [INFO] Worker exiting (pid: 15396)
2014-01-01 14:30:02 [15391] [INFO] Handling signal: int
2014-01-01 14:30:02 [15391] [INFO] Shutting down: Master
2014-01-01 14:31:36 [15399] [INFO] Starting gunicorn 18.2
2014-01-01 14:31:36 [15399] [INFO] Listening at: http://127.0.0.1:8000 (15399)
2014-01-01 14:31:36 [15399] [INFO] Using worker: sync
2014-01-01 14:31:36 [15402] [INFO] Booting worker with pid: 15402
2014-01-01 14:31:36 [15403] [INFO] Booting worker with pid: 15403
2014-01-01 14:31:36 [15404] [INFO] Booting worker with pid: 15404
2014-01-01 14:31:37 [15403] [INFO] Worker exiting (pid: 15403)
2014-01-01 14:31:37 [15404] [INFO] Worker exiting (pid: 15404)
2014-01-01 14:31:37 [15399] [INFO] Handling signal: int
2014-01-01 14:31:37 [15399] [INFO] Shutting down: Master
2014-01-01 14:32:18 [15405] [INFO] Starting gunicorn 18.2
2014-01-01 14:32:18 [15405] [INFO] Listening at: http://127.0.0.1:8000 (15405)
2014-01-01 14:32:18 [15405] [INFO] Using worker: sync
2014-01-01 14:32:18 [15408] [INFO] Booting worker with pid: 15408
2014-01-01 14:32:18 [15409] [INFO] Booting worker with pid: 15409
2014-01-01 14:32:18 [15410] [INFO] Booting worker with pid: 15410
2014-01-01 14:32:20 [15410] [INFO] Worker exiting (pid: 15410)
2014-01-01 14:32:20 [15409] [INFO] Worker exiting (pid: 15409)
2014-01-01 14:32:20 [15405] [INFO] Handling signal: int
2014-01-01 14:32:20 [15405] [INFO] Shutting down: Master

View File

@ -983,7 +983,7 @@ class ErrorLog(Setting):
cli = ["--error-logfile", "--log-file"] cli = ["--error-logfile", "--log-file"]
meta = "FILE" meta = "FILE"
validator = validate_string validator = validate_string
default = "-" default = None
desc = """\ desc = """\
The Error log file to write to. The Error log file to write to.
@ -1044,6 +1044,7 @@ Gunicorn uses the standard Python logging module's Configuration
file format. file format.
""" """
class SyslogTo(Setting): class SyslogTo(Setting):
name = "syslog_addr" name = "syslog_addr"
section = "Logging" section = "Logging"

View File

@ -13,7 +13,6 @@ import sys
import traceback import traceback
import threading import threading
from gunicorn import util from gunicorn import util
from gunicorn.six import string_types from gunicorn.six import string_types
@ -168,7 +167,6 @@ class Logger(object):
self.setup(cfg) self.setup(cfg)
def setup(self, cfg): def setup(self, cfg):
if not cfg.logconfig:
loglevel = self.LOG_LEVELS.get(cfg.loglevel.lower(), logging.INFO) loglevel = self.LOG_LEVELS.get(cfg.loglevel.lower(), logging.INFO)
self.error_log.setLevel(loglevel) self.error_log.setLevel(loglevel)
self.access_log.setLevel(logging.INFO) self.access_log.setLevel(logging.INFO)
@ -196,12 +194,13 @@ class Logger(object):
if cfg.syslog: if cfg.syslog:
self._set_syslog_handler(self.error_log, cfg, self.syslog_fmt) self._set_syslog_handler(self.error_log, cfg, self.syslog_fmt)
else: if cfg.logconfig:
if os.path.exists(cfg.logconfig): if os.path.exists(cfg.logconfig):
fileConfig(cfg.logconfig, defaults=CONFIG_DEFAULTS, fileConfig(cfg.logconfig, defaults=CONFIG_DEFAULTS,
disable_existing_loggers=False) disable_existing_loggers=False)
else: else:
raise RuntimeError("Error: log config '%s' not found" % cfg.logconfig) raise RuntimeError("Error: log config '%s' not found" %
cfg.logconfig)
def critical(self, msg, *args, **kwargs): def critical(self, msg, *args, **kwargs):
self.error_log.critical(msg, *args, **kwargs) self.error_log.critical(msg, *args, **kwargs)
@ -334,6 +333,7 @@ class Logger(object):
if h: if h:
log.handlers.remove(h) log.handlers.remove(h)
if output is not None:
if output == "-": if output == "-":
h = logging.StreamHandler() h = logging.StreamHandler()
else: else: