Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:fluentd [2015/05/08 10:26] alfred [Plugins] |
wiki2:fluentd [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| ====== Fluentd ====== | ====== Fluentd ====== | ||
| + | |||
| + | It is a service to manage system logs. It takes logs from software (MySQL, Apache, the system...) and unify their format and send them to the required place. | ||
| + | |||
| Also called td-agent. | Also called td-agent. | ||
| Línea 47: | Línea 50: | ||
| * [[https://pypi.python.org/pypi/fluent-logger/|fluent-logger]] | * [[https://pypi.python.org/pypi/fluent-logger/|fluent-logger]] | ||
| * [[https://pypi.python.org/pypi/pyfluent|pyfluent]] | * [[https://pypi.python.org/pypi/pyfluent|pyfluent]] | ||
| + | |||
| + | === Fluentd-logger === | ||
| + | <code python> | ||
| + | from fluent import sender, event | ||
| + | sender.setup('debug.test', host='127.0.0.1', port=24224) | ||
| + | event.Event('json', {"json":"message from python"}) | ||
| + | </code> | ||
| + | |||
| + | === pyfluent === | ||
| + | <code python> | ||
| + | import logging | ||
| + | from pyfluent.logging import SafeFluentHandler | ||
| + | handler = SafeFluentHandler('localhost', 24224, 'pyfluent') | ||
| + | handler.setLevel(logging.INFO) | ||
| + | logger = logging.getLogger() | ||
| + | logger.setLevel(logging.INFO) | ||
| + | logger.addHandler(handler) | ||
| + | logger.info('hello pyfluent!') | ||
| + | </code> | ||
| + | |||
| + | <code python> | ||
| + | import logging | ||
| + | import logging.config | ||
| + | |||
| + | logger = logging.getLogger(__name__) | ||
| + | |||
| + | logging.config.dictConfig({ | ||
| + | 'version': 1, | ||
| + | 'disable_existing_loggers': False, # this fixes the problem | ||
| + | |||
| + | 'handlers': { | ||
| + | 'fluentd': { | ||
| + | 'level': 'DEBUG', | ||
| + | 'class': 'pyfluent.logging.SafeFluentHandler', | ||
| + | 'tag': 'test.prueba', | ||
| + | }, | ||
| + | }, | ||
| + | 'loggers': { | ||
| + | '': { | ||
| + | 'handlers': ['fluentd'], | ||
| + | 'level': 'INFO' | ||
| + | } | ||
| + | } | ||
| + | }) | ||
| + | |||
| + | logger.info('It works!') | ||
| + | </code> | ||