Use of external modules in a logging configuration file

99封情书 提交于 2019-12-05 21:40:27

Well this is quite an old question, but if anyone is still looking for an answer, I post this (available for both python2 and python3).

Short answer

According to the documentation, you can write something like:

class=ext://logstash.LogstashHandler

I'm not sure whether it's necessary or not to import logstash in the script parsing the logging configuration file (as logstash does not belong to the standard library).

Alternative answer

But I must add that this mechanism hasn't always worked very well for me in old-style logging configuration files... so if this doesn't work, I would recommend to turn your configuration file into a yaml one and use this very same feature in it:

handlers:
    remote:
        class: ext://logstash.LogstashHandler
        level: NOTSET
        formatter: standard

For the other args, I don't know how to write them since I can't find a documentation about logstash. If they are positional arguments, this should be OK (though I'm not sure about the use of int in a logging configuration file):

        args: [os.environ['hostname'], int(os.environ['port'])]

But if they are keyword arguments, this should be written another way:

        kw1: os.environ['hostname']
        kw2: int(os.environ['port'])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!