A operation log package
Project description
Operation Log
operation_log is used to record operation log for web api.
Features
- Non-intrusive to record operation log
Requirements
- Python 3.x
Getting started
- install operation log
pip install operation-log
- use record_operation_log decorator to wrap api function
from operation_log import Operator, record_operation_log
def get_operator() -> Operator:
return Operator(1, 'test_user')
@record_operation_log(get_operator, 'hello world')
async def hello(request):
return Response()
- use record_operation_log decorator with context
import typing
from operation_log import Operator, record_operation_log
def get_operator() -> Operator:
return Operator(1, 'test_user')
def before_execute_context() -> typing.Dict:
return {'msg': 'hello old world'}
def after_execute_context() -> typing.Dict:
return {'msg': 'hello new world'}
@record_operation_log(
get_operator,
'hello {{ before_execute.msg }} {{ after_execute.msg }}',
before_execute_contexts=[before_execute_context],
after_execute_contexts=[after_execute_context]
)
async def hello(request):
return Response()
The context functions will receive params such as the execute function.
- custom log writer
import logging
from operation_log import Operator, OperationLogWriter, OperationLog, record_operation_log
def get_operator() -> Operator:
return Operator(1, 'test_user')
class CustomOperationLogWriter(OperationLogWriter):
def write(self, operation_log: OperationLog):
logging.info(f'this is custom log writer {operation_log.text}')
@record_operation_log(
get_operator,
'hello world',
writer=CustomOperationLogWriter()
)
async def hello(request):
return Response()
If you want to save the operation log to the database, you can subclass the OperationLogWriter class and implement
your own write method.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file operation_log-0.2.1.tar.gz.
File metadata
- Download URL: operation_log-0.2.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f99c5808c78976ba23f60c011d8ca3607929e0f619ee246fc0b973020181927
|
|
| MD5 |
004492e06f3dd16ef524974939d0dd52
|
|
| BLAKE2b-256 |
8bca9316484fc21971a70ce8d96b7ead5940229ffbaf86a4788f5a4c4bdf32d1
|
File details
Details for the file operation_log-0.2.1-py3-none-any.whl.
File metadata
- Download URL: operation_log-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c7c48783ae21804ceaf6c54b679c4a8e215ee4f791aac18fd0f94d611e5abde
|
|
| MD5 |
03de1457fbc1276b5c98c23ad556f6b8
|
|
| BLAKE2b-256 |
9b40aec802f2dcbea059949fe5deba033b061c6693770de9c3cf0ca0fc3a7944
|