I have setup the following configuration file for the logging module in python2.7 with logstash
[loggers]
keys=root,test
[handlers]
keys=remote
[formatters]
keys=standard
[logger_root]
level=NOTSET
handlers=remote
[logger_test]
level=DEBUG
handlers=remote
propagate=0
qualname=test
[handler_remote]
class=logstash.LogstashHandler
level=NOTSET
formatter=standard
args=(os.environ['hostname'], int(os.environ['port']))
[formatter_standard]
format=%(levelname)s - %(message)s
datefmt=
class=logging.Formatter
Unfortunately, this is about as short as I can make the file for this example. I use a module called logstash
which sends my logging messages out to be viewed remotely. If I try and load this configuration with logging.config.fileConfig
I get an error where it cannot find logstash. All I have to do is import logstash before loading and the problem goes away.
It would be nice if I could fit that import statement into the configuration file itself though, so that the loader of the file would not need to know or care. It would also be nice for things like urlparse
so I wouldn't need as many environment variables.
Is there a way to do this?