Skip to main content

Python library for logging with colors and http status code.

Project description

Frexco PyLogger

Install


pip install frexco_pylogger

Configure


# main.py
from frexco_pylogger.functions import PyLogger

logger = PyLogger(appname="my_app")
logger.http(message="Uma mensagem http qualquer", status_code=200, data={"name": "Um nome qualquer", "age": 22})

2022-09-02 14:05:59 | [HTTP ] | Uma mensagem http qualquer | [STATUSCODE 200] | {'name': 'Um nome qualquer', 'age': 22}

Log Types


Tipo Description
error Informar sobre exceptions tratadas
warning Informar eventos ou estados potencialmente prejudicias ao programa
debug Acompanhar eventos ou estados do programa
info Descrever infos detalhadas sobre o estado do programa
http Informar dados de requests e responses feitas via http

Middlewares


django

# httpLogger.py
from frexco_pylogger.functions import PyLogger
from django.utils.deprecation import MiddlewareMixin


class HTTPLoggerMiddleware(MiddlewareMixin):

    def process_response(self, request, response):
        logger = PyLogger(appname="my_django_app")
        logger.http(message=f'{request.META.get("REMOTE_ADDR")} {request.method} {request.META.get("PATH_INFO")}',
                    status_code=response.status_code)

        return response
# setting.py

MIDDLEWARE = [
    ...,
    'app.utils.httpLogger.HTTPLoggerMiddleware' # path to your middleware file
]

Flask

# Your app setup file
from flask import Flask, request, Response
from frexco_pylogger.functions import PyLogger

app = Flask(__name__)
logger = PyLogger(appname="my_flask_app")

@app.after_request
def log_response(response: Response):
    logger.http(message=f'{request.remote_addr} {request.method} {request.path}',
                status_code=response.status_code)
    return response

Alert

# Seu arquivo de configuração de logger
from frexco_pylogger.functions import PyLogger

logger = PyLogger(appname="my_app_name", group="nome_do_grupo") # Ex: group="warehouse", Ex: group="consumer"

logger.error(message="Uma messagem de error qualquer",
            status_code=500, data={"name": "Um error"}) # Enviar alerta

logger.error(message="Uma messagem de error qualquer repetida",
            status_code=500, data={"name": "Um error"}, alert=False) # Não enviar alerta

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

frexco_pylogger-0.2.4.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file frexco_pylogger-0.2.4.tar.gz.

File metadata

  • Download URL: frexco_pylogger-0.2.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for frexco_pylogger-0.2.4.tar.gz
Algorithm Hash digest
SHA256 06021b8babfe92acc1656e5eb953fe7d891741369aec32b3ad6d9543d08740e2
MD5 4f99ceaf304901bcb943da3d165ecc55
BLAKE2b-256 830811244994bae11d962ba13076f3784a990c3523984fabac0fffd91385f980

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page