Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benjamin-croker/loggy
https://github.com/benjamin-croker/loggy
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/benjamin-croker/loggy
- Owner: benjamin-croker
- License: mit
- Created: 2014-12-20T01:32:20.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-07-18T05:37:59.000Z (over 4 years ago)
- Last Synced: 2024-06-25T11:42:59.223Z (5 months ago)
- Language: Python
- Size: 5.86 KB
- Stars: 68
- Watchers: 11
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
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: 192014-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: 1042014-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`