Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

logging: Split out registration logging.

Alex Vandiver6ad3dce8dba5
diff --git a/puppet/zulip/templates/logrotate/zulip.template.erb b/puppet/zulip/templates/logrotate/zulip.template.erb
index 486a50fbfdf..c71c66d90d9 100644
--- a/puppet/zulip/templates/logrotate/zulip.template.erb
+++ b/puppet/zulip/templates/logrotate/zulip.template.erb
@@ -19,6 +19,7 @@
/var/log/zulip/webhooks_errors.log
/var/log/zulip/webhooks_unsupported_events.log
/var/log/zulip/workers.log
+/var/log/zulip/registration.log
{
missingok
rotate 3
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py
index 789942596ab..1a2363d6921 100644
--- a/zerver/tests/test_signup.py
+++ b/zerver/tests/test_signup.py
@@ -1433,7 +1433,11 @@ class UserSignUpTest(ZulipTestCase):
side_effect=EmailNotDeliveredError,
)
- with smtp_mock, self.assertLogs(level="ERROR") as m:
+ with (
+ smtp_mock,
+ self.assertLogs("zulip.registration", level="ERROR") as registration_logs,
+ self.assertLogs(level="ERROR"),
+ ):
result = self.client_post("/accounts/home/", {"email": email})
self.assertEqual(result.status_code, 500)
@@ -1441,7 +1445,8 @@ class UserSignUpTest(ZulipTestCase):
"https://zulip.readthedocs.io/en/latest/subsystems/email.html", result
)
self.assertTrue(
- "ERROR:root:Failed to deliver email during user registration" in m.output[0]
+ "ERROR:zulip.registration:Failed to deliver email during user registration"
+ in registration_logs.output[0]
)
@override_settings(CORPORATE_ENABLED=True)
@@ -1456,7 +1461,11 @@ class UserSignUpTest(ZulipTestCase):
side_effect=EmailNotDeliveredError,
)
- with smtp_mock, self.assertLogs(level="ERROR") as m:
+ with (
+ smtp_mock,
+ self.assertLogs("zulip.registration", level="ERROR") as registration_logs,
+ self.assertLogs(level="ERROR"),
+ ):
result = self.client_post("/accounts/home/", {"email": email})
self.assertEqual(result.status_code, 500)
@@ -1465,7 +1474,8 @@ class UserSignUpTest(ZulipTestCase):
)
self.assert_in_response("Something went wrong. Sorry about that!", result)
self.assertTrue(
- "ERROR:root:Failed to deliver email during user registration" in m.output[0]
+ "ERROR:zulip.registration:Failed to deliver email during user registration"
+ in registration_logs.output[0]
)
@override_settings(CORPORATE_ENABLED=False)
@@ -1480,7 +1490,11 @@ class UserSignUpTest(ZulipTestCase):
side_effect=EmailNotDeliveredError,
)
- with smtp_mock, self.assertLogs(level="ERROR") as m:
+ with (
+ smtp_mock,
+ self.assertLogs("zulip.registration", level="ERROR") as registration_logs,
+ self.assertLogs(level="ERROR"),
+ ):
result = self.submit_realm_creation_form(
email, realm_subdomain="custom-test", realm_name="Zulip test"
)
@@ -1489,7 +1503,10 @@ class UserSignUpTest(ZulipTestCase):
self.assert_in_response(
"https://zulip.readthedocs.io/en/latest/subsystems/email.html", result
)
- self.assertTrue("ERROR:root:Failed to deliver email during realm creation" in m.output[0])
+ self.assertTrue(
+ "ERROR:zulip.registration:Failed to deliver email during realm creation"
+ in registration_logs.output[0]
+ )
@override_settings(CORPORATE_ENABLED=True)
def test_bad_email_configuration_for_corporate_create_realm(self) -> None:
@@ -1503,7 +1520,11 @@ class UserSignUpTest(ZulipTestCase):
side_effect=EmailNotDeliveredError,
)
- with smtp_mock, self.assertLogs(level="ERROR") as m:
+ with (
+ smtp_mock,
+ self.assertLogs("zulip.registration", level="ERROR") as registration_logs,
+ self.assertLogs(level="ERROR"),
+ ):
result = self.submit_realm_creation_form(
email, realm_subdomain="custom-test", realm_name="Zulip test"
)
@@ -1513,7 +1534,10 @@ class UserSignUpTest(ZulipTestCase):
"https://zulip.readthedocs.io/en/latest/subsystems/email.html", result.content.decode()
)
self.assert_in_response("Something went wrong. Sorry about that!", result)
- self.assertTrue("ERROR:root:Failed to deliver email during realm creation" in m.output[0])
+ self.assertTrue(
+ "ERROR:zulip.registration:Failed to deliver email during realm creation"
+ in registration_logs.output[0]
+ )
def test_user_default_language_and_timezone(self) -> None:
"""
@@ -2167,7 +2191,7 @@ class UserSignUpTest(ZulipTestCase):
with (
patch("zerver.views.registration.authenticate", side_effect=invalid_subdomain),
- self.assertLogs(level="ERROR") as m,
+ self.assertLogs("zulip.registration", level="ERROR") as registration_logs,
):
result = self.client_post(
"/accounts/register/",
@@ -2179,8 +2203,10 @@ class UserSignUpTest(ZulipTestCase):
},
)
self.assertEqual(
- m.output,
- ["ERROR:root:Subdomain mismatch in registration zulip: [email protected]"],
+ registration_logs.output,
+ [
+ "ERROR:zulip.registration:Subdomain mismatch in registration zulip: [email protected]"
+ ],
)
self.assertEqual(result.status_code, 302)
diff --git a/zerver/views/registration.py b/zerver/views/registration.py
index 6e9e6bea848..34ee7c29e13 100644
--- a/zerver/views/registration.py
+++ b/zerver/views/registration.py
@@ -148,6 +148,7 @@ from zproject.backends import (
)
ldap_logger = logging.getLogger("zulip.ldap")
+logger = logging.getLogger("zulip.registration")
@typed_endpoint
@@ -866,7 +867,7 @@ def registration_helper(
)
if return_data.get("invalid_subdomain"):
# By construction, this should never happen.
- logging.error(
+ logger.error(
"Subdomain mismatch in registration %s: %s",
realm.subdomain,
user_profile.delivery_email,
@@ -1373,7 +1374,7 @@ def create_realm(request: HttpRequest, confirmation_key: str | None = None) -> H
request=request,
)
except EmailNotDeliveredError:
- logging.exception("Failed to deliver email during realm creation")
+ logger.exception("Failed to deliver email during realm creation")
if settings.CORPORATE_ENABLED:
return render(request, "500.html", status=500)
return config_error(request, "smtp")
@@ -1707,7 +1708,7 @@ def accounts_home(
try:
send_confirm_registration_email(email, activation_url, request=request, realm=realm)
except EmailNotDeliveredError:
- logging.exception("Failed to deliver email during user registration")
+ logger.exception("Failed to deliver email during user registration")
if settings.CORPORATE_ENABLED:
return render(request, "500.html", status=500)
return config_error(request, "smtp")
diff --git a/zproject/computed_settings.py b/zproject/computed_settings.py
index ce930873711..6d8110fbedb 100644
--- a/zproject/computed_settings.py
+++ b/zproject/computed_settings.py
@@ -764,6 +764,7 @@ TRACEMALLOC_DUMP_DIR = zulip_path("/var/log/zulip/tracemalloc")
RETENTION_LOG_PATH = zulip_path("/var/log/zulip/message_retention.log")
AUTH_LOG_PATH = zulip_path("/var/log/zulip/auth.log")
SCIM_LOG_PATH = zulip_path("/var/log/zulip/scim.log")
+REGISTRATION_LOG_PATH = zulip_path("/var/log/zulip/registration.log")
ZULIP_WORKER_TEST_FILE = zulip_path("/var/log/zulip/zulip-worker-test-file")
@@ -873,6 +874,7 @@ LOGGING: dict[str, Any] = {
"ldap_file": file_handler(LDAP_LOG_PATH),
"scim_file": file_handler(SCIM_LOG_PATH),
"slow_queries_file": file_handler(SLOW_QUERIES_LOG_PATH, level="INFO"),
+ "registration_file": file_handler(REGISTRATION_LOG_PATH, level="INFO"),
"webhook_anomalous_file": file_handler(
WEBHOOK_ANOMALOUS_PAYLOADS_LOG_PATH, formatter="webhook_request_data"
),
@@ -1016,6 +1018,10 @@ LOGGING: dict[str, Any] = {
"zulip.queue": {
"level": "WARNING",
},
+ "zulip.registration": {
+ "handlers": ["registration_file", "errors_file"],
+ "propagate": False,
+ },
"zulip.retention": {
"handlers": ["file", "errors_file"],
"propagate": False,