Skip to main content

fxc-logger

Install


pip install fxc-logger

Configure


# main.py
from fxc_logger 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] | | 9fd8… | Uma mensagem http qualquer | [STATUSCODE 200] | {"name": "Um nome qualquer", "age": 22}

Correlation ID (Contexto)

Cada requisição ou mensagem pode ter um identificador único para facilitar filtros de log. A biblioteca gera um UUID v4 automaticamente no primeiro log, mas você pode controlar isso manualmente.

from fxc_logger import PyLogger, correlation_scope, with_new_correlation_id

logger = PyLogger(appname="consumer")

# 1) Definindo manualmente
auto_id = correlation_scope()      # context-manager
with correlation_scope():          # gera novo UUID
    logger.info("log dentro do bloco")

# 2) Decorando callback do RabbitMQ / Kafka
@with_new_correlation_id
def callback(ch, method, props, body):
    logger.info("mensagem recebida", data=body)

Todos os logs emitidos dentro do bloco ou função decorada carregam o mesmo Correlation ID, permitindo rastrear todo o fluxo.

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 fxc_logger 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

settings.py:

MIDDLEWARE = [
    ...,
    'app.utils.httpLogger.HTTPLoggerMiddleware'
]

Flask

from flask import Flask, request, Response
from fxc_logger 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

from fxc_logger import PyLogger

logger = PyLogger(appname="my_app", group="warehouse")

# envia alerta (ENV=PRD)
logger.error("Falhou o checkout", status_code=500, data={"order_id": 123})

# não envia alerta
logger.error("Falhou o checkout de novo", status_code=500, alert=False)

Metadata

Release files for fxc-logger 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fxc-logger 1.0.2
File Size Uploaded Provenance Actions
fxc_logger-1.0.2.tar.gz 6.5 kB Without provenance Details for fxc_logger-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fxc-logger 1.0.2
File Interpreter ABI Platform Actions
fxc_logger-1.0.2-py3-none-any.whl Python 3 none any Details for fxc_logger-1.0.2-py3-none-any.whl

Total release size: 12.4 kB

Release files / fxc_logger-1.0.2.tar.gz

Download URL fxc_logger-1.0.2.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7ff9a4dd6ccc80c622473218bb38f3779424465d62f1a85b99fa20a832a750d2
BLAKE2b-256 checksum
How to use checksums
2b9eeeacd9bc8f5d1e237fe1c1430800ced0208f3b1979921376d2df677bf08d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Release files / fxc_logger-1.0.2-py3-none-any.whl

Download URL fxc_logger-1.0.2-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7107c2e22f7d023c3473b0f0c31990c499d09f6f987e7a767d333d18654b2f62
BLAKE2b-256 checksum
How to use checksums
3a4564e9735813fdfca1a3338c9aec7465ff67dec87c5fddad600a7476a05755
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Security for fxc-logger 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page