Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ipdevpoll logging of SQL queries and from Twisted library #2640

Merged
merged 2 commits into from Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/nav/ipdevpoll/daemon.py
Expand Up @@ -30,6 +30,7 @@
import time
import argparse

import twisted
from twisted.internet import reactor
from twisted.internet.defer import maybeDeferred, setDebugging
from twisted.python.failure import Failure
Expand Down Expand Up @@ -412,6 +413,9 @@ def run(self):

def init_logging(self, stderr_only=False):
"""Initializes ipdevpoll logging for the current process."""
observer = twisted.python.log.PythonLoggingObserver()
observer.start()

formatter = ContextFormatter(self.options.pidlog)

logfile_name = None
Expand Down
6 changes: 4 additions & 2 deletions python/nav/ipdevpoll/db.py
Expand Up @@ -29,6 +29,7 @@
from psycopg2 import InterfaceError, OperationalError

_logger = logging.getLogger(__name__)
_query_logger = logging.getLogger(".".join((__name__, "query")))


class ResetDBConnectionError(Exception):
Expand All @@ -51,7 +52,7 @@ def django_debug_cleanup():
if query_count:
runtime = sum_django_queries_runtime()
thread = threading.current_thread()
_logger.debug(
_query_logger.debug(
"Thread %s/%s: Removing %d logged Django queries "
"(total time %.03f):\n%s",
thread.ident,
Expand Down Expand Up @@ -117,8 +118,9 @@ def _reset(*args, **kwargs):
"dropped, resetting it now - you may see further "
"errors about this until the situation is fully "
"resolved for all threads "
"(this thread is '%s', error was '%s')",
"(this thread is '%s', function was: %r, error was '%s')",
thread.name,
func,
error,
)
django.db.connection.connection = None
Expand Down