Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request > option to add extra fields to records globally #37

Open
croepha opened this issue Aug 26, 2015 · 3 comments
Open

Feature Request > option to add extra fields to records globally #37

croepha opened this issue Aug 26, 2015 · 3 comments

Comments

@croepha
Copy link

croepha commented Aug 26, 2015

I find my self doing this:

class CustomUDPLogstashHandler(logstash.UDPLogstashHandler):
    def __init__(self, *a, **kw):
        self.global_extras = kw.pop('global_extras', {})
        super().__init__(*a, **kw)

    def emit(self, record):
        for key, value in self.global_extras.items():
            setattr(record, key, value)
        super().emit(record)

LOGGING={
...
        'logstash': {
            'level': 'DEBUG',
            'class': 'util.CustomUDPLogstashHandler',
            'host': 'logstash.service',
            'port': 5000,
            'version': 1,
            'tags': ['tag1', 'tag2'],
            'global_extras': {
                'product': "my_test_product",
                'instance': "my_test_instance",
                'site': 333
            }
        }
...

It would be cool if that functionality were included

@sumdog
Copy link

sumdog commented Mar 8, 2016

👍

@mkurek
Copy link

mkurek commented Jul 21, 2017

It's implemented (but not merged yet) in #42

@mrodm
Copy link

mrodm commented Apr 6, 2020

Hi ! It would be great to have this feature.

Being available to add extra fields globally just in one place in all the loggers defined in our code would be so helpful. So we can have those extra fields as keys in the json sent by this logstash handler.

Currently, we would need to create subclasses of LoggerAdapter for each logger defined to be adding all our needed extra fields in our logs. Furthermore, there will also be loggers that we cannot modify from other libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants