webhooks: Configure webhook loggers in zproject/computed_settings.py.

This limits the webhook errors to only go to their respective log
files, and not to the general server logs.
This commit is contained in:
Alex Vandiver 2020-09-01 18:15:08 -07:00 committed by Tim Abbott
parent 006875e7d0
commit b8a2e6b5f8
2 changed files with 14 additions and 7 deletions

View File

@ -34,7 +34,6 @@ from zerver.lib.exceptions import (
OrganizationOwnerRequired,
UnsupportedWebhookEventType,
)
from zerver.lib.logging_util import log_to_file
from zerver.lib.queue import queue_json_publish
from zerver.lib.rate_limiter import RateLimitedUser
from zerver.lib.request import REQ, has_request_variables
@ -50,11 +49,7 @@ if settings.ZILENCER_ENABLED:
from zilencer.models import RemoteZulipServer, get_remote_server_by_uuid
webhook_logger = logging.getLogger("zulip.zerver.webhooks")
log_to_file(webhook_logger, settings.WEBHOOK_LOG_PATH)
webhook_unsupported_events_logger = logging.getLogger("zulip.zerver.webhooks.unsupported")
log_to_file(webhook_unsupported_events_logger,
settings.WEBHOOK_UNSUPPORTED_EVENTS_LOG_PATH)
FuncT = TypeVar('FuncT', bound=Callable[..., object])

View File

@ -791,6 +791,18 @@ LOGGING: Dict[str, Any] = {
'formatter': 'default',
'filename': SLOW_QUERIES_LOG_PATH,
},
'webhook_file': {
'level': 'DEBUG',
'class': 'logging.handlers.WatchedFileHandler',
'formatter': 'default',
'filename': WEBHOOK_LOG_PATH,
},
'webhook_unsupported_file': {
'level': 'DEBUG',
'class': 'logging.handlers.WatchedFileHandler',
'formatter': 'default',
'filename': WEBHOOK_UNSUPPORTED_EVENTS_LOG_PATH,
},
},
'loggers': {
# The Python logging module uses a hierarchy of logger names for config:
@ -937,12 +949,12 @@ LOGGING: Dict[str, Any] = {
},
'zulip.zerver.webhooks': {
'level': 'DEBUG',
'handlers': ['file', 'errors_file'],
'handlers': ['webhook_file'],
'propagate': False,
},
'zulip.zerver.webhooks.unsupported': {
'level': 'DEBUG',
'handlers': ['file', 'errors_file'],
'handlers': ['webhook_unsupported_file'],
'propagate': False,
},
},