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(request) -> typing.Dict:
    return {'msg': 'hello old world'}


def after_execute_context(request) -> 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.2.tar.gz (5.0 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.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: operation_log-0.2.2.tar.gz
  • Upload date:
  • Size: 5.0 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.2.tar.gz
Algorithm Hash digest
SHA256 0be2191863f960c1b392a13bb8797c04f580fbd0d09d5b954426d303a227cef1
MD5 9a2bfc62792e701656f3875cd21912aa
BLAKE2b-256 de53e1bfcc5d8d67fbc8d3e46df9cf302819b6ccbf3bbf9124063435193dd862

See more details on using hashes here.

File details

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

File metadata

  • Download URL: operation_log-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a9df1089b21ca0a9ede67132f74cb2a5459e1673beefd7851a5a9a0aae72e155
MD5 60f37200da5aa5ef3c4ed2f06e0bd6a4
BLAKE2b-256 35e22d08df3a48fc54cbc9439dd84bcd1bdaeadae68c1a6b2d44ba9fef05bfef

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