logging: Add option to show the PID in each log message.

This commit is contained in:
Greg Price
2017-10-04 16:41:00 -07:00
parent 9cf44a77da
commit aa4104a5af
3 changed files with 15 additions and 3 deletions

View File

@@ -177,11 +177,17 @@ class ZulipFormatter(logging.Formatter):
# Used in the base implementation. Default uses `,`.
default_msec_format = '%s.%03d'
_fmt = '%(asctime)s %(zulip_level_abbrev)-4s [%(zulip_origin)s] %(message)s'
def __init__(self):
# type: () -> None
super().__init__(fmt=self._fmt)
super().__init__(fmt=self._compute_fmt())
def _compute_fmt(self):
# type: () -> str
pieces = ['%(asctime)s', '%(zulip_level_abbrev)-4s']
if settings.LOGGING_SHOW_PID:
pieces.append('pid:%(process)d')
pieces.extend(['[%(zulip_origin)s]', '%(message)s'])
return ' '.join(pieces)
def format(self, record):
# type: (logging.LogRecord) -> str

View File

@@ -173,6 +173,11 @@ FEEDBACK_EMAIL = ZULIP_ADMINISTRATOR
# mysterious log message, but a little verbose.
#LOGGING_SHOW_MODULE = False
# If True, each log message in the server logs will identify the
# process ID. Useful for correlating logs with information from
# system-level monitoring tools.
#LOGGING_SHOW_PID = False
# Controls whether or not Zulip will provide inline image preview when
# a link to an image is referenced in a message. Note: this feature
# can also be disabled in a realm's organization settings.

View File

@@ -135,6 +135,7 @@ DEFAULT_SETTINGS = {
'ERROR_REPORTING': True,
'BROWSER_ERROR_REPORTING': False,
'LOGGING_SHOW_MODULE': False,
'LOGGING_SHOW_PID': False,
# File uploads and avatars
'DEFAULT_AVATAR_URI': '/static/images/default-avatar.png',