GreyZmeem/python-logging-loki

Use 'level' instead of 'severity'

Opened this issue · 4 comments

Loki and Grafana use level as label to show the logging severity/verbose/levelname. It would be useful to replace the current severity label with level, as all queries and visualizations in Grafana would automatically pick up the log level.
I can create a pull request if you like, but let me know if the current has a special purpose.

That would be a very simple and useful change.

Grafana Loki output with and without level=error:
image

It seems the level tag can be easily changed with the following code:

import logging

from logging_loki import LokiHandler, emitter

emitter.LokiEmitter.level_tag = "level"

handler = LokiHandler(
    url="<url>", 
    tags={"app": "<appname>"},
    version="1",
)

logger = logging.getLogger("<loggername>")
logger.addHandler(handler)
logger.error(
    "Something happened", 
    extra={"tags": {"service": "my-service"}},
)

Hi, the logger only supports error I can send logs to Loki but I perform logger.info he does not write it to Loki

Hi @edeno1

If it is still a problem for you, this article solves the problem:

In short, you need to set the default level to a lower level, for example to DEBUG. This is done with logger.setLevel(logging.DEBUG)