Operation Log 0.2.2 | Coderz Repository

operation-log 0.2.2

Last updated:

0 purchases

operation-log 0.2.2 Image
operation-log 0.2.2 Images

Free

Languages

Categories

Add to Cart

Description:

operationlog 0.2.2

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

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.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product: (if this is empty don't purchase this product)

Customer Reviews

There are no reviews.