File: loggers.py

package info (click to toggle)
matrix-synapse 1.146.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 79,996 kB
  • sloc: python: 261,671; javascript: 7,230; sql: 4,758; sh: 1,302; perl: 626; makefile: 207
file content (25 lines) | stat: -rw-r--r-- 822 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import logging

root_logger = logging.getLogger()


class ExplicitlyConfiguredLogger(logging.Logger):
    """
    A custom logger class that only allows logging if the logger is explicitly
    configured (does not inherit log level from parent).
    """

    def isEnabledFor(self, level: int) -> bool:
        # Check if the logger is explicitly configured
        explicitly_configured_logger = self.manager.loggerDict.get(self.name)

        log_level = logging.NOTSET
        if isinstance(explicitly_configured_logger, logging.Logger):
            log_level = explicitly_configured_logger.level

        # If the logger is not configured, we don't log anything
        if log_level == logging.NOTSET:
            return False

        # Otherwise, follow the normal logging behavior
        return level >= log_level