LinuxForHealth/connect

Support Trace Logging Via a Method

Closed this issue · 3 comments

Let's see if we can take our current trace logging facility and support it as a logger instance method.

I have trace logging running within a local feature branch. Trace logging is configured using a bootstrapping method integrated within server handlers

def add_trace_logging():
    """
    Adds trace level logging support to logging and the root logging class
    """

    def trace(self, message, *args, **kwargs):
        """
        Generates a TRACE log record
        """
        self.log(5, message, *args, **kwargs)

    logging.addLevelName(5, "TRACE")
    logging.getLoggerClass().trace = trace

Logging config

version: 1
disable_existing_loggers: false
formatters:
  simple:
    format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
  console:
    class: logging.StreamHandler
    level: TRACE
    formatter: simple
    stream: ext://sys.stdout
root:
  level: WARN
  handlers: [console]
loggers:
  connect:
    level: TRACE
  uvicorn:
    level: INFO

I will also test with the handler set to DEBUG to verify that we aren't emitting log events.

So, with this approach, does getting the logger and using trace look like:

logger = logging.getLogger(__name__)
logger.trace("message")

? If so, that's exactly what we are looking for.

So, with this approach, does getting the logger and using trace look like:

logger = logging.getLogger(__name__)
logger.trace("message")

? If so, that's exactly what we are looking for.

@ccorley - exactly! We still may not have "auto-completion" support since we're appending a function to the type at runtime, but we can look at refining that later if needed.