Code_beginner
Code_beginner

Reputation: 102

Get package level logs into webservice between logging and structlog

So the situation is the following:

But now we want to see the error logs which are made in the packages and see them in a best case as json log entry, but atleast in some way even if it means just a blank string. Currently the package logs are not logged to std.out when we run the service and trigger the functionality.

Here is an example of the package logging.logger config:

import logging
logger = logging.getLogger(__name__)

def anyfunc():
    logger.info("hello world")

This is our configuration of the structlog logger in one of the webservices:

import structlog

structlog.configure(
    processors=[
        structlog.stdlib.add_log_level,
        structlog.processors.ExceptionRenderer(),
        structlog.processors.TimeStamper("iso", key="ts"),
        structlog.processors.EventRenamer("msg"),
        structlog.processors.JSONRenderer(sort_keys=True),
    ],
    cache_logger_on_first_use=True,
)

logger = structlog.get_logger()

As said we want to see the logs from the package but in some way maybe structlog is surpressing the standard logger? Any help would be appreciated. I wonder that I could not find a question about this. Is this a bad setup because I would assume it is quite common, structlog for services and logging for packages(in case other people do not want to use structlog).

Any help is welcome.

Upvotes: 0

Views: 19

Answers (1)

hynek
hynek

Reputation: 4166

Given standard library logging's complexity, integration is not a simple feat.

https://www.structlog.org/en/stable/standard-library.html outlines various strategies, but either way you'll have to configure standard library's logging to show up.

Then, you have to decide how to make sure that their log format are as similar as possible to each other where the "Don't integrate" strategy is the simplest one.

See also the recent discussion in: https://github.com/hynek/structlog/issues/395

Upvotes: 1

Related Questions