#5: Re-adds gelf support

parent 7fe9f857
Pipeline #116257286 passed with stages
in 4 minutes and 1 second
......@@ -24,6 +24,8 @@ docker run --rm -it -p 9308:9308 \
| `HORIZON_URL` | `https://horizon.stellar.org/` | **NO** | The URL of the horizon server. For the Test network you can use `https://horizon-testnet.stellar.org/` |
| `LOGLEVEL` | `INFO` | **NO** | [Logging Level](https://docs.python.org/3/library/logging.html#levels) |
| `PORT` | `9188` | **NO** | The port for prometheus metrics |
| `GELF_HOST` | - | NO | If set, the exporter will also log to this [GELF](https://docs.graylog.org/en/3.0/pages/gelf.html) capable host on UDP |
| `GELF_PORT` | `12201` | NO | Ignored, if `GELF_HOST` is unset. The UDP port for GELF logging |
## Tags and Arch
......
......@@ -8,4 +8,8 @@ from .lib import log as logging
log = logging.setup_logger(
name=__package__,
level=os.environ.get('LOGLEVEL', 'INFO'),
gelf_host=os.environ.get('GELF_HOST'),
gelf_port=int(os.environ.get('GELF_PORT', 12201)),
_exchange='stellar',
_ix_id=__package__,
)
......@@ -3,9 +3,10 @@
""" Global logging configuration """
import logging
import pygelf
def setup_logger(name=__package__, level='INFO'):
def setup_logger(name, level='INFO', gelf_host=None, gelf_port=None, **kwargs):
""" sets up the logger """
logging.basicConfig(handlers=[logging.NullHandler()])
formatter = logging.Formatter(
......@@ -19,4 +20,14 @@ def setup_logger(name=__package__, level='INFO'):
handler.setFormatter(formatter)
logger.addHandler(handler)
if gelf_host and gelf_port:
handler = pygelf.GelfUdpHandler(
host=gelf_host,
port=gelf_port,
debug=True,
include_extra_fields=True,
**kwargs
)
logger.addHandler(handler)
return logger
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment