Logging Wrapper for fastapi with Cloud Logging
Project description
Wrapper para trabalhar com a API do Cloud Logging
Procedimento para upload no Pypi
Pré requisitos
Instalar pacotes python
python3 -m pip install --upgrade setuptools build wheel twine
Build e enviar ao PYPI
python3 -m build
python3 -m twine upload dist/*
Instalar o pacote no projeto
pip install fastapi-logging
Utilização da biblioteca
Essa biblioteca espera que você passe o schema dos dados da tabela
Aconselho criar um arquivo de schema.py ou model.py onde seja definido a estrutura de dados da tabela.
Instanciar o Middleware
Com o schema definido, você deve instanciar um classe
from starlette.middleware import Middleware
from fastapi.middleware.cors import CORSMiddleware
from starlette_context.middleware.raw_middleware import RawContextMiddleware
from fastapi_logging.logging import LogMidddleware
from fastapi_logging.logging import logging
from fastapi_logging.logging import TracePlugin
from starlette_context import context, plugins
middlewares = [
Middleware(
RawContextMiddleware,
plugins=(
plugins.CorrelationIdPlugin(),
TracePlugin(),
plugins.RequestIdPlugin(),
),
),
Middleware(LogMidddleware),
Middleware(CORSMiddleware,
allow_origins=BACKEND_CORS_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],)
]
app = FastAPI(
title='Iris Typification',
openapi_url="/api/v1/openapi.json",
middleware=middlewares
)
Principais operações
Usando a classe, você pode executar algumas operações para auxiliar no densenvolvimento
Logging
logging.info({"key": "value"})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi-logging-0.0.3.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_logging-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80075e2b2f4cc0c23f4ea55b875f06d960b17e5ec386db3e7387edac9412bcab |
|
MD5 | eec4a0a7d411b60bd0a17a339e2b2300 |
|
BLAKE2b-256 | f65d2b119e4796c1893dbd3e625fbd218e7d49b4626b6d428b03402c3bc46b37 |