logger.py/README.md

51 lines
1.5 KiB
Markdown
Raw Permalink Normal View History

2022-08-13 11:34:36 +02:00
# logger.py
2021-08-06 11:15:47 +02:00
2022-08-13 11:35:37 +02:00
[![Build Status](https://drone.pyas.de/api/badges/Kim/logger.py/status.svg)](https://drone.pyas.de/Kim/logger.py)
2021-08-06 13:40:53 +02:00
2022-08-13 12:37:57 +02:00
Simple logger function with colored LogLevel designed to run inside Docker container
## Possible values
Values can be set case insensitive (DEBUG, debug, Debug).
- debug
2022-08-13 12:37:57 +02:00
- info (default value)
- warn
- warning
- crit
- critical
## Requirements
- Python 3.10 or higher
2021-08-06 11:18:42 +02:00
## Usage example
2022-08-13 12:37:57 +02:00
> Use the environment variable `LOG_LEVEL` to set the log level.
>
> **LOG_LEVEL** = *debug*
2021-08-06 11:18:42 +02:00
```python
# Setting LOG_LEVEL with `os.environ` is only necessary if environment variable has not been set before (e.g. outside Docker)
2021-08-06 13:40:53 +02:00
import os
os.environ['LOG_LEVEL'] = 'DEBUG'
2021-08-06 13:27:36 +02:00
2021-08-06 13:40:53 +02:00
from loghandler import logger
2021-08-06 13:27:36 +02:00
def main():
logger.debug("This is a Debug Message")
logger.info("This is a Info Message")
logger.warning("This is a Warning Message")
logger.error("This is a Error Message")
logger.critical("This is a Critical Message")
2021-08-06 14:37:46 +02:00
2021-08-06 13:27:36 +02:00
main()
```
```
2021-08-06 13:40:53 +02:00
[Fri, 06 Aug 2021 13:36:09] DEBUG [test.py.main:7] This is a Debug Message
[Fri, 06 Aug 2021 13:36:09] INFO [test.py.main:8] This is a Info Message
[Fri, 06 Aug 2021 13:36:09] WARNING [test.py.main:9] This is a Warning Message
[Fri, 06 Aug 2021 13:36:09] ERROR [test.py.main:10] This is a Error Message
[Fri, 06 Aug 2021 13:36:09] CRITICAL [test.py.main:11] This is a Critical Message
2021-09-21 22:03:03 +02:00
```
## Credits
Repo Icon made by [Smartline](https://www.flaticon.com/authors/smartline "Smartline") from [www.flaticon.com](https://www.flaticon.com/ "Flaticon")