Git Product home page Git Product logo

loguru-loki-handlers's Introduction

[Deprecated] loguru-loki-handlers

This repo has been deprecated please check : loki-logger-handler.

Handler created for Loguru that sends logs to Grafana Loki in JSON format

Features

  • Logs pushed in JSON format
  • Custom labels definition
  • Allows defining loguru and logger extra keys as labels
  • Logger extra keys added automatically as keys into pushed JSON

How to use

from loguru_loki_handler import loki_handler
from loguru import logger
import os 

os.environ["LOKI_URL"]="https://USER:[email protected]/loki/api/v1/push"

logger.configure(handlers=[{"sink":  loki_handler(os.environ["LOKI_URL"],{"application":"Test", "envornment":"Develop"}), "serialize": True}])
logger.info("Starting service")
logger.info("Response code {code} HTTP/1.1 GET {url}", code=200, url="https://loki_handler.io")

Loki messages samples

Without extra

{
  "message": "Starting service",
  "timestamp": 1681638266.542849,
  "process": 48906,
  "thread": 140704422327936,
  "function": "run",
  "module": "test",
  "name": "__main__"
}

With extra

{
  "message": "Request return 200 HTTP/1.1 GET https://loki_handler.io",
  "timestamp": 1681638225.877143,
  "process": 48870,
  "thread": 140704422327936,
  "function": "run",
  "module": "test",
  "name": "__main__",
  "code": 200,
  "url": "https://loki_handler.io"
}

Exceptions

{
  "message": "name 'plan' is not defined",
  "timestamp": 1681638284.358464,
  "process": 48906,
  "thread": 140704422327936,
  "function": "run",
  "module": "test",
  "name": "__main__",
  "file": "test.py",
  "path": "/test.py",
  "line": 39
}

Loki Query Sample

Loki query sample :

{envornment="Develop"} |= `` | json

Filter by level:

{envornment="Develop", level="INFO"} |= `` | json

Filter by extra:

{envornment="Develop", level="INFO"} |= `` | json | code=`200`

License

The MIT License

loguru-loki-handlers's People

Contributors

perestoronin avatar wnark avatar xente avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

loguru-loki-handlers's Issues

Requires package for installation using pipenv tool

Requires packaging your project in a Python package for installation. So that we can easily and legally use your work. Thanks for the work you've done!

In the case of pip install, it is possible to install from the github repository, but pipenv refuses to install. It's not difficult at all. In addition, githib already has a Workflow template for building and publishing a package in pipy. You just need to register on pipy and enter the received token into CI Workflow

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.