No project description provided
Project description
- Version
1.7
- 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(
service_name=settings.service_name,
service_version=settings.service_version,
env=environments.get(settings.run_env, 'test'),
)
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 example
{
"@timestamp": "2022-02-18T13:29:37.389Z",
"message": "Get tutor popular micro lessons from 2021-01-31 to 2022-06-12",
"correlation_id": "d794ef71-e9d6-45cf-992e-324a9bc49870",
"current_action": "GET /analytics/tutor/popular/microlesson",
"ecs": {
"version": "1.6.0"
},
"env": "local",
"ipv4": "127.0.1.1",
"root_action": "/analytics/tutor/popular/microlesson",
"service_name": "edu-user-analytics-service",
"service_version": "1.0",
"trace_id": "65e76724-d8a0-4e03-840e-fca72f672cae",
"user_id": "60b7588b2206860013e77aa8",
"transaction_id": "transaction_id",
"span_id": "span_id"
}
FastAPI integration:
Please use TraceIdProcessTimeMiddleware to create trace_id in request state.
from fastapi import FastAPI
from edu_py_logger.middlewares import TraceIdProcessTimeMiddleware
from app.config import settings
app = FastAPI()
app.add_middleware(TraceIdProcessTimeMiddleware, logger=settings.logger)
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
Update and publish package:
change package version in setup.py file
run command to build package:
python setup.py sdist
run command to upload new version on PyPI:
twine upload dist/edu-py-logger-0.4.tar.gz
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.7.tar.gz
(6.0 kB
view details)
File details
Details for the file edu-py-logger-1.7.tar.gz.
File metadata
- Download URL: edu-py-logger-1.7.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
073caeee8a9470b597c7fad0dbd6196c684a46a1bcd890c326ccdc27242bf036
|
|
| MD5 |
81f5db4d2efd180a687520da1c7492e8
|
|
| BLAKE2b-256 |
2af458a0c675f1a4d191020073cc7840dc95a431b3325292aabf89c6b86a8132
|