mirror of
https://github.com/bugsink/bugsink.git
synced 2026-02-08 23:08:36 -06:00
Use logger in middleware to avoid cluttering the tests with print statements
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import logging
|
||||
from time import time
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db import connection
|
||||
|
||||
performance_logger = logging.getLogger("bugsink.performance")
|
||||
|
||||
|
||||
class LoginRequiredMiddleware:
|
||||
def __init__(self, get_response):
|
||||
@@ -46,5 +49,5 @@ class PerformanceStatsMiddleware:
|
||||
result = view_func(request, *view_args, **view_kwargs)
|
||||
took = (time() - t0) * 1000
|
||||
if took > 1 and not request.path.startswith("/static"):
|
||||
print(f" {took:.2f}ms / {len(connection.queries)} queries for '{ view_func.__name__ }' ↴")
|
||||
performance_logger.info(f" {took:.2f}ms / {len(connection.queries)} queries: '{ view_func.__name__ }' ↴")
|
||||
return result
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from copy import deepcopy
|
||||
import os
|
||||
|
||||
from pathlib import Path
|
||||
@@ -5,6 +6,8 @@ from pathlib import Path
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.django import DjangoIntegration
|
||||
|
||||
from django.utils.log import DEFAULT_LOGGING
|
||||
|
||||
from debug_toolbar.middleware import show_toolbar
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
@@ -172,6 +175,13 @@ DEBUG_TOOLBAR_CONFIG = {
|
||||
}
|
||||
|
||||
|
||||
LOGGING = deepcopy(DEFAULT_LOGGING)
|
||||
LOGGING['loggers']['bugsink'] = {
|
||||
"level": "INFO",
|
||||
"handlers": ["console"],
|
||||
}
|
||||
|
||||
|
||||
# ###################### SERVER-MODE SETTINGS #################
|
||||
|
||||
BUGSINK_DIGEST_IMMEDIATELY = True
|
||||
|
||||
Reference in New Issue
Block a user