I am trying to configure the Fluentd log handler from a Django project using the logger from the code:
def get_fluentd_logger(name): import logging from fluent import handler logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(name) logger.addHandler(handler.FluentHandler(name, host='localhost', port=24224)) return logger
handler.FluentHandler comes from the fluent-logger package, and I run fluent locally.
fluent.conf:
<source> type forward port 24224 </source> <match **> type copy <store> type stdout </store> <store> type forward send_timeout 60s recover_wait 10s heartbeat_interval 1s phi_threshold 8 hard_timeout 60s <server> name monitoring host 1.2.3.4 port 24224 weight 100 </server> </store> </match>
When I run this from a non-django python project, it works fine, but when called from django it just does nothing.
The question is: is there a way to see the currently installed registrars and their handlers so that I can debug this situation?
[EDIT]
When you do the django settings as follows:
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'simple': { 'format': '%(levelname)s: %(message)s' }, }, 'handlers': { 'fluentdebug':{ 'level':'DEBUG', 'class':'fluent.handler.FluentHandler', 'formatter': 'simple', 'tag':'foo.bar.baz', 'host':'localhost', 'port':24224, }, }, 'loggers': { 'foo.bar.baz': { 'handlers': ['fluentdebug'], 'level': 'DEBUG', 'propagate': True, }, } }
He works. I would like to be able to do this from code, because foo.bar.baz can take many values, and I do not want to pollute this file with 20 registrars and handlers that do the same.
Perhaps the real question is: why can't I add loggers from code to logging after Django has configured it?