pythonpyramidpaster

How do I include a third-party logger formatter in a PasteDeploy ini file?


I am trying to utilize Pyramid and pyramid_exclog to send exceptions to a third-party system whenever an exception occurs in my web app. Unfortunately, I cannot seem to make my PasteDeploy development.ini to properly recognize the formatter.

I've tried several variations, including:

[formatter_exc_formatter]
class=JsonFormatter()

...

[formatter_exc_formatter]
class=jsonlogger.JsonFormatter()

...

[formatter_exc_formatter]
class=pythonjsonlogger.jsonlogger.JsonFormatter()

I have also tried specifying pythonjsonlogger as part of my pyramid_includes, as so:

pyramid.includes = pyramid_exclog, pythonjsonlogger.jsonlogger

as well as just:

pyramid.includes = pyramid_exclog, pythonjsonlogger

At this point I am pretty stumped. What am I missing? How do I include custom formatters into a PasteDeploy-managed app?


Solution

  • You need to drop the () from your class line.

    Instead of:

    [formatter_exc_formatter]
    class=pythonjsonlogger.jsonlogger.JsonFormatter()
    

    You need to do the following:

    [formatter_exc_formatter]
    class=pythonjsonlogger.jsonlogger.JsonFormatter
    

    pythonjsonlogger is not a Pyramid module and does not have an includeme() function which is called by Pyramid for all pyramid.includes.