-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from goodtune/feature/logging-filter
Add TenantContextFilter for schema/domain logging
- Loading branch information
Showing
7 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import logging | ||
|
||
from django.db import connection | ||
|
||
|
||
class TenantContextFilter(logging.Filter): | ||
""" | ||
Add the current ``schema_name`` and ``domain_url`` to log records. | ||
Thanks to @regolith for the snippet on #248 | ||
""" | ||
def filter(self, record): | ||
record.schema_name = connection.tenant.schema_name | ||
record.domain_url = getattr(connection.tenant, 'domain_url', '') | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from test_routes import * | ||
from test_tenants import * | ||
from test_cache import * | ||
from test_log import * | ||
from test_utils import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import logging | ||
|
||
from django.test import TestCase | ||
|
||
from tenant_schemas import log | ||
|
||
|
||
class LoggingFilterTests(TestCase): | ||
|
||
def test_tenant_context_filter(self): | ||
filter_ = log.TenantContextFilter() | ||
record = logging.makeLogRecord({}) | ||
res = filter_.filter(record) | ||
self.assertEqual(res, True) | ||
self.assertEqual(record.schema_name, 'public') | ||
self.assertEqual(record.domain_url, '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters