https://github.com/herzog0/best_python_logger
https://github.com/herzog0/best_python_logger
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/herzog0/best_python_logger
- Owner: herzog0
- License: mit
- Archived: true
- Created: 2020-04-30T21:11:02.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-06T05:38:50.000Z (almost 5 years ago)
- Last Synced: 2024-08-13T07:08:16.122Z (8 months ago)
- Language: Python
- Size: 29.3 KB
- Stars: 17
- Watchers: 0
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - herzog0/best_python_logger - (Python)
README
# Best Python logger
(For the record, I discovered [loguru](https://github.com/Delgan/loguru) and if it fulfill my needs I'm gonna abandon this project)
This is the best python logger.
It doesn't require additional packages.
It is so great that deserved its own repo.Stolen and modified from [here](https://stackoverflow.com/a/56944256/12603421) and [here](https://github.com/cybergrind/safe_logger)
# Usage
### Simplest usage
```python
from best_python_logger import get_logger
logger = get_logger(__name__)
# Use the variable __name__ so the logger will print the file's name alsologger.debug("")
logger.info("Awesome!")
logger.error("Ok, we are in trouble.")
logger.critical("Damn blinks that doesn't work on most IDEs built-in terminals..")
```### Master usage
```python
import time
from best_python_logger import get_logger
import loggingtest_logger = get_logger(name=__name__,
filename="logs/test/dirs/test.log",
when="S",
interval=3,
backup_count=3,
visible_stream=True,
compress=True,
auto_colorized=True,
custom_format=None,
only_visible_stream_auto_colorized=True,
level=logging.INFO)count = 0
while True:
count += 1
time.sleep(0.001)
test_logger.debug("hi, " + str(count))
```## README of one of the sources
(I though it would be useful for some people to read the comments of the owner of safe_logger package, from which I got the concurrency fix part)
```
## DescriptionThis handler is designed to provide correct log files rotation when multiple processes writing to file.
Heavilly tested on production systems with up to 50 writers.
**Caveat**: this logger has been extracted from other system, so can have issues cause by copy-pasting
## Pitfalls
* Naive aproach fails because concurrent processes do independent rollovers and finally you will have zero-lenght log file: so we need locking
* Naive locking fails when you have some processes that not write often and them can rotate you file in case you archive old, or etc.: so we need check file that want to move by compare inodes
* Naive approach to start handler have issues, when you open file that in rollover - you can write data to rotated file: so we need locking on open file
```