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

Problem adding filters for django logging #79

Open
LingboTang opened this issue Sep 12, 2017 · 1 comment
Open

Problem adding filters for django logging #79

LingboTang opened this issue Sep 12, 2017 · 1 comment

Comments

@LingboTang
Copy link

I have the following settings for django in settings.py:

LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'simple': {
                'format': '%(levelname)s %(message)s'
            }
        },
        'filters': {
            'fields': {
                'env': 'test'
            }
        },
        'handlers': {
            'graypy': {
                'level': 'DEBUG',
                'class': 'graypy.GELFHandler',
                'host': 'graylog2.example.org',
                'port': 12201,
                'filters': ['fields']
            }
        },
        'loggers': {
            'testlogger': {
                'handlers': ['graypy'],
                'level': 'DEBUG',
                'propagate': True
            }
        }
    }

But I didn't see any filters setup for graylog in GUI, so I checked it locally with logging.getLogger('testlogger').handlers[0].filters[0].__dict__ and it returns {'name': '', 'nlen': 0}. Then I made a little change that I throw the filters out handlers and put that in loggers like:

'loggers': {
            'testlogger': {
                'handlers': ['graypy'],
                'filters': ['fields'],
                'level': 'DEBUG',
                'propagate': True
            }
        }

And it didn't work as well. The only way seems working for me is manually add a filter class just like the sample in README. So I don't know if dict config hasn't been supported by graylog or I did something in my config.

@LingboTang
Copy link
Author

If I add filters through a subclass that is inherited from logging.Filter, I should be able to log some message to graylog through manage.py shell with self-defined filters. However, I still couldn't get any messages log to graylog when I run my django server and sending resquest to django after I defined the loggers.

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

1 participant