Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueueHandler not working with LokiHandler #27

Open
averri opened this issue Jul 20, 2022 · 1 comment
Open

QueueHandler not working with LokiHandler #27

averri opened this issue Jul 20, 2022 · 1 comment

Comments

@averri
Copy link

averri commented Jul 20, 2022

This code, gotten from the project examples, does not work. It does not produce any logs on Loki:

import logging.handlers
import logging_loki
from multiprocessing import Queue

queue = Queue(-1)

handler = logging.handlers.QueueHandler(queue)

handler_loki = logging_loki.LokiHandler(
    url="http://localhost:3100/loki/api/v1/push",
    tags={"app": "none", "job": "testing-loki", "env": "dev"},
    version="1",
)

logging.handlers.QueueListener(queue, handler_loki)

logger = logging.getLogger("my-logger")
logger.addHandler(handler)

if __name__ == '__main__':
    logger.info("Hello, world")
    logger.error("Something wrong...")

You may start Loki using Docker Compose docker-compose up -d in the same directory as the following docker-compose.ymlfile:

version: "3.7"
services:
  loki:
    image: grafana/loki:2.6.0
    ports:
      - "3100:3100"
@simosho
Copy link

simosho commented Sep 6, 2023

Explicitly starting the listener should do the trick:

logging.handlers.QueueListener(queue, handler_loki).start()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants