Skip to content

Commit

Permalink
Merge pull request #1528 from hramezani/redirect_accesslog_issue_1403
Browse files Browse the repository at this point in the history
Redirect accesslog issue 1403
  • Loading branch information
benoitc authored Aug 22, 2017
2 parents 92afaa5 + 919871d commit 60efb10
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
17 changes: 17 additions & 0 deletions docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,18 @@ The Access log file to write to.

``'-'`` means log to stdout.

.. _disable-redirect-access-to-syslog:

disable-redirect-access-to-syslog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* ``--disable-redirect-access-to-syslog``
* ``False``

Disable redirect access logs to syslog.

.. versionadded:: 19.8

.. _access-log-format:

access_log_format
Expand Down Expand Up @@ -753,6 +765,11 @@ syslog

Send *Gunicorn* logs to syslog.

.. versionchanged:: 19.8

You can now disable sending access logs by using the
:ref:`disable-redirect-access-to-syslog` setting.

.. _syslog-prefix:

syslog_prefix
Expand Down
18 changes: 18 additions & 0 deletions gunicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,19 @@ class AccessLog(Setting):
``'-'`` means log to stdout.
"""

class DisableRedirectAccessToSyslog(Setting):
name = "disable_redirect_access_to_syslog"
section = "Logging"
cli = ["--disable-redirect-access-to-syslog"]
validator = validate_bool
action = 'store_true'
default = False
desc = """\
Disable redirect access logs to syslog.
.. versionadded:: 19.8
"""


class AccessLogFormat(Setting):
name = "access_log_format"
Expand Down Expand Up @@ -1349,6 +1362,11 @@ class Syslog(Setting):
default = False
desc = """\
Send *Gunicorn* logs to syslog.
.. versionchanged:: 19.8
You can now disable sending access logs by using the
:ref:`disable-redirect-access-to-syslog` setting.
"""


Expand Down
10 changes: 6 additions & 4 deletions gunicorn/glogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ def setup(self, cfg):
self._set_syslog_handler(
self.error_log, cfg, self.syslog_fmt, "error"
)
self._set_syslog_handler(
self.access_log, cfg, self.syslog_fmt, "access"
)
if not cfg.disable_redirect_access_to_syslog:
self._set_syslog_handler(
self.access_log, cfg, self.syslog_fmt, "access"
)

if cfg.logconfig:
if os.path.exists(cfg.logconfig):
Expand Down Expand Up @@ -316,7 +317,8 @@ def access(self, resp, req, environ, request_time):
for format details
"""

if not (self.cfg.accesslog or self.cfg.logconfig or self.cfg.syslog):
if not (self.cfg.accesslog or self.cfg.logconfig or
(self.cfg.syslog and not self.cfg.disable_access_log_redirection)):
return

# wrap atoms:
Expand Down

0 comments on commit 60efb10

Please sign in to comment.