Skip to content

Commit

Permalink
Merge pull request Uninett#2640 from lunkwill42/feature/ipdevpoll-log…
Browse files Browse the repository at this point in the history
…ging

Improve ipdevpoll logging of SQL queries and from Twisted library
  • Loading branch information
lunkwill42 authored Jun 14, 2023
2 parents 4599982 + e8416e6 commit cc6dc7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions python/nav/ipdevpoll/daemon.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit cc6dc7a

Please sign in to comment.