No project description provided
Project description
- Version
0.3
- Download
- Keywords
logging, fastapi, python
Installation
To install, please use pip:
pip install edu-py-logger
Connection and configuration
Logger connects in the settings with 2 strings:
dictConfig(get_config(settings.service_name, settings.logging_file_path)) settings.logger = LoggerService(settings.service_name, settings.run_env)
Add to settings new attribute logging_file_path to configure path for output file. The path for output is set up in env.
LOGGING_FILE_PATH=/home/dev/logging.log
Log format
( "%(service_name)s | " "%(ipv4)s | " "%(env)s | " "%(trace_id)s | " "%(correlation_id)s | " "%(user_id)s | " "%(levelprefix)s | " "%(asctime)s | " "%(message)s" )
FastAPI integration:
Please use TraceIdProcessTimeMiddleware to create trace_id in request state.
from fastapi import FastAPI from edu_py_logger.middlewares import TraceIdProcessTimeMiddleware app = FastAPI() app.add_middleware(TraceIdProcessTimeMiddleware)
To create extra from request, please use util get_request_extra_data.
Example:
from typing import Dict from edu_py_logger.utils import get_request_extra_data from fastapi import APIRouter, Depends from app.config import settings router = APIRouter() @router.get("/test") def test(extra: Dict = Depends(get_request_extra_data)): settings.logger.info('message', extra=extra)
Package tests
To run test:
pytest
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
edu-py-logger-1.1.tar.gz
(5.2 kB
view hashes)