Automatically add function call logs and method call logs for Python code.
Project description
Auto-logger
Automatically add function call logs and method call logs for Python code.
Install
pip install -U auto-logger
Use
import logging
from dataclasses import dataclass
from auto_logger import Config, MethodLoggerMeta, logFuncCall,formatJson
logging.basicConfig(level=logging.INFO)
@logFuncCall
def add(a: int, b: int):
return a + b
add(1, 2) # INFO:auto_logger:CALL FUCNTION <add> WITH ARGS (1, 2) KWARGS {} RETURNS 3
add(a=1, b=2) # INFO:auto_logger:CALL FUCNTION <add> WITH ARGS () KWARGS {'a': 1, 'b': 2} RETURNS 3
@dataclass
class A(metaclass=MethodLoggerMeta):
a: int = 0
def add(self, n: int):
self.a += 1
def abs(self):
return abs(self.a)
A().add(1) # INFO:auto_logger:CALL METHOD <add> OF A(a=0) WITH ARGS (1,) KWARGS {} RETURNS None
Config.format = formatJson
A().add(1) # INFO:auto_logger:{"args": [1], "kwargs": {}, "ret": null, "method": "add", "object": "A(a=0)"}
Config.ignoreMethods[A] = {'abs'}
A().abs() # Log nothing
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
auto-logger-0.1.0.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for auto_logger-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e79639bac3161e34e7deb7ed610f5f3a9c78778cc09990165bbc75d42470d3cb |
|
MD5 | 9f35b8a0c22def40ba616a6451e6ff5f |
|
BLAKE2b-256 | 2b7b531d52c247db87f895ee1de6efe79e674bde4074930d676db03b4d6f4444 |