vklochan/python-logstash

Allow "tags" to be specified in "extra" for log messages.

exhuma opened this issue · 0 comments

I have an application which needs to send messages with different tags to logstash. The tags are used to classify messages and change over runtime. It seems wasteful to me to generate a new handler instance just to support tags.

For one execution I expect to be in the tens for tags (so not that many). But I can't say from the beginning which tags will be emitted so sending a message looks like this currently:

def send_message(tags, message):
    handler = TCPLogstashHandler([...], tags=tags)
    LOG.addHandler(handler)
    LOG.info(message)
    LOG.removeHandler(handler)

Having the tags exposed in the via the "extra" attribute would allow me to write this:

def send_message(tags, message):
    LOG.info(message, extra={'tags': tags}

which would even make the send_message function redundant.