Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/benjamin-croker/loggy


https://github.com/benjamin-croker/loggy

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

loggy
=====

Use a Python decorator to automatically log function calls.

### Usage

The file `example.py` shows how loggy can be used

```python
# example.py
import logging
import loggy

# set the logging configuration as desired
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s')

# use a decorator to indicate the function should be logged
# loggy will log at a DEBUG level
@loggy.log
def foo(a, b, c=4, d=5, e=6):
return a+b+c+d+e

# each time foo is called, the input arguments and output is logged
foo(1, 3)
foo(1, 3, 5, e=90)

# loggy will print the calling function too
def bar():
return foo(1, 3)

bar()
```

The output of the above is

```
2014-12-20 19:35:11,982 function 'foo' called by '' with arguments:
{'b': 3, 'd': 5, 'a': 1, 'e': 6, 'c': 4}
2014-12-20 19:35:11,982 result: 19

2014-12-20 19:35:11,982 function 'foo' called by '' with arguments:
{'b': 3, 'd': 5, 'a': 1, 'e': 90, 'c': 5}
2014-12-20 19:35:11,982 result: 104

2014-12-20 19:35:11,983 function 'foo' called by 'bar' with arguments:
{'b': 3, 'd': 5, 'a': 1, 'e': 6, 'c': 4}
2014-12-20 19:35:11,983 result: 19
```

### License
Licensed under the terms of the MIT License. See `LICENSE.md`