Last active
September 23, 2016 12:40
-
-
Save rafaelhenrique/de005ce61ee66ef77fd9f9c643214b50 to your computer and use it in GitHub Desktop.
Implement log filter to use on Django to "by-pass" log when run tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ..... ommited lines | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': True, | |
'filters': { | |
'require_debug_false': { | |
'()': 'django.utils.log.RequireDebugFalse' | |
}, | |
'disable_on_test': { | |
'()': 'logfilter.RequireTestingFalse' | |
} | |
}, | |
'formatters': { | |
'verbose': { | |
'format': '%(levelname)s %(asctime)s %(name)s %(module)s %(process)d %(thread)d %(message)s' # noqa | |
}, | |
'simple': { | |
'format': '%(levelname)s %(name)s %(message)s' | |
}, | |
}, | |
'handlers': { | |
'logstash_handler': { | |
'level': 'DEBUG', | |
'filters': ['require_debug_false', 'disable_on_test'], | |
'class': 'logstash.LogstashHandler', | |
'version': 1, | |
'host': 'X.X.X.X', | |
'port': 5959, | |
}, | |
# ..... ommited lines | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
class RequireTestingFalse(logging.Filter): | |
def filter(self, record): | |
if 'test' in sys.argv: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment