Skip to main content

A operation log package

Project description

Operation Log

operation_log is used to record operation log for web api.

Features

  1. Non-intrusive to record operation log

Requirements

  1. Python 3.x

Getting started

  1. install operation log
pip install operation-log 
  1. 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()
  1. 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.

  1. 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

operation_log-0.2.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

operation_log-0.2.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

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

Hashes for operation_log-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4f99c5808c78976ba23f60c011d8ca3607929e0f619ee246fc0b973020181927
MD5 004492e06f3dd16ef524974939d0dd52
BLAKE2b-256 8bca9316484fc21971a70ce8d96b7ead5940229ffbaf86a4788f5a4c4bdf32d1

See more details on using hashes here.

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

Hashes for operation_log-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c7c48783ae21804ceaf6c54b679c4a8e215ee4f791aac18fd0f94d611e5abde
MD5 03de1457fbc1276b5c98c23ad556f6b8
BLAKE2b-256 9b40aec802f2dcbea059949fe5deba033b061c6693770de9c3cf0ca0fc3a7944

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page