Last active
November 23, 2020 12:19
-
-
Save a-recknagel/c96e9d70892053c2362b30d2bc55814f to your computer and use it in GitHub Desktop.
log to a fluentd
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.config | |
workstation_IP = "?" | |
logging.config.dictConfig( | |
{ | |
"version": 1, | |
"disable_existing_loggers": False, | |
"formatters": { | |
"fluent_fmt": { | |
"()": "fluent.handler.FluentRecordFormatter", | |
"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s" | |
}, | |
}, | |
"handlers": { | |
"fluent": { | |
"class": "fluent.handler.FluentHandler", | |
"host": workstation_IP, | |
"port": 9880, | |
"tag": "my_notebook", | |
"formatter": "fluent_fmt", | |
"level": "DEBUG", | |
}, | |
}, | |
"loggers": { | |
"": { | |
"handlers": ["fluent"], | |
"level": "DEBUG", | |
"propagate": True, | |
}, | |
}, | |
} | |
) | |
log = logging.getLogger(__name__) | |
log.info("Logger configuration set up successfully.") |
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
# /tmp/fluentd.conf | |
<source> | |
@type forward | |
port 9880 | |
bind 0.0.0.0 | |
</source> | |
<match **> | |
@type stdout | |
</match> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pip-install
fluent-logger
and execute the logger code in the app that is creating the logs, and start a local fluentd server through docker by runningdocker run -p 9880:9880 -v path/to/test.conf:/fluentd/etc/test.conf -e FLUENTD_CONF=test.conf fluent/fluentd:latest
.Getting the correct
workstation_IP
might be tricky, as anything network-related usually is.