1

Below snippet of logging system works fine with django application with logs following the required formate, but fails in a celery application

logging.config.dictConfig(
    {
        "version": 1,
        "disable_existing_loggers": False,
        "formatters": {
            "json": {
                "format": "%(name)s %(module)s %(filename)s %(funcName)s %(lineno)d %(message)s ",
                "class": "pythonjsonlogger.jsonlogger.JsonFormatter",
            }
        },
        "handlers": {"json": {"class": "logging.StreamHandler", "formatter": "json"}},
        "loggers": {
            "": {"handlers": ["json"], "level": logging.DEBUG}  # Set log level info
        },
    }
)


configure(
    context_class=threadlocal.wrap_dict(dict),
    logger_factory=stdlib.LoggerFactory(),
    wrapper_class=stdlib.BoundLogger,
    processors=[
        stdlib.filter_by_level,
        stdlib.add_logger_name,
        stdlib.add_log_level,
        stdlib.PositionalArgumentsFormatter(),
        processors.TimeStamper(fmt="iso"),
        processors.StackInfoRenderer(),
        processors.format_exc_info,
        processors.UnicodeDecoder(),
        stdlib.render_to_log_kwargs,
    ],
)

log = structlog.getLogger(__name__)
log.info('Log content', input='some input')

This fails in the case of my celery standalone application.Basically the pythonjsonlogger configuration is not taking an effect. The logs are coming with default logger settings. Am I missing something. Any help is appreciated, Thanks

2
  • 1
    If your problem is that the celery application is ignoring your logging configuration, your problem is unrelated to structlog and you're unnecessarily limiting the audience of your question. Maybe stackoverflow.com/questions/48289809/… can help? Commented Mar 20, 2020 at 8:29
  • @hynek You are right, this was not a structlog issue, at the time my question was framed I had no idea what caused the issue, have made the appropriate changes in the question. Thanks for your comment Commented Mar 20, 2020 at 9:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.