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.1.2.tar.gz (4.8 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.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: operation_log-0.1.2.tar.gz
  • Upload date:
  • Size: 4.8 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.1.2.tar.gz
Algorithm Hash digest
SHA256 74f38620b8be0727f777151e9e1a2bfd663a2ecbe4f78c1935c0263e2445a1b1
MD5 0fc08b6bef5ed9c71bad6703f2611fd5
BLAKE2b-256 3a1b9229a46de0edf7412bd78a4a19b9f27b345bd0da41b91a626aac57f160b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: operation_log-0.1.2-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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e6238bd3adaec1c9974de78827ba5ceb69b5bcb9da2701cb9e71a7608ca68289
MD5 312cd14b5a6ff33b16ee88b4c89108ac
BLAKE2b-256 dd981681af6814c4ad3090c48f207b0969445ad5ce66afea8afee88b2fbf4e6a

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