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 {'old_msg': 'hello old world'}


def after_execute_context() -> typing.Dict:
    return {'new_msg': 'hello new world'}


@record_operation_log(
    get_operator,
    'hello {{ old_msg }} {{ new_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.0.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.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file operation_log-0.2.0.tar.gz.

File metadata

  • Download URL: operation_log-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 113ad462467e2fe7361c0aedaff4230cc3face02e437628964e65072bcd17736
MD5 ac5c91baa837fcf3464f99eaa5753cd0
BLAKE2b-256 5a5ae435dff774527247d9e5511861ca7ab693780b56ad139a599baa4b62ee6e

See more details on using hashes here.

File details

Details for the file operation_log-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: operation_log-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef9b1d197e79fb26f5f5b67029e2c89f909fda587f89ab2b0350f08ff271075b
MD5 2718c20b8777df7cf8845ebaaf296dab
BLAKE2b-256 70d82d12ec5100d4d685b183938d60b05a2146682cfade3837013e967a017049

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