https://github.com/miskibin/easy_logs
https://github.com/miskibin/easy_logs
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/miskibin/easy_logs
- Owner: miskibin
- License: mit
- Created: 2022-10-30T21:48:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-04T22:10:35.000Z (almost 2 years ago)
- Last Synced: 2025-01-23T20:56:56.436Z (4 months ago)
- Language: Python
- Size: 228 KB
- Stars: 2
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README

[](https://badge.fury.io/py/easy_logs)
[](https://github.com/pre-commit/pre-commit)
# easy_logsDid you ever regret that logging in python is so complicated?
Have you ever wanted to have a logger that is easy to use and has colored logs? If so, this module is for you.
## installation:```bash
pip install easy_logs
```### Usage
`get_logger` returns highly configurable logger object.
- Every level has its own color. (If it is printed to terminal)
- Problems with logging messages from `ipynb` cells are resolved.
- Includes validation for file name and path.
- Has `disable_existing_loggers` param to disable all other loggers.
#### params:
- `logger_name` - name of the logger
- `lvl`: [logging level](https://docs.python.org/3/library/logging.html#logging-levels). Default is 10 (DEBUG).
- `file_name`: file that logs will be saved to. If None, logs will not be saved to file.
- `format`: [logging format](https://docs.python.org/3/library/logging.html#logrecord-attributes).
- `datefmt`: date format for logging formatter. Define only if `(asctime)` in format Default is "%H:%M:%S".
- `disable_existing_loggers`: if True, disable existing loggers.
- `predefined`: Choose predefined configuration. Will override all other arguments#### predefined_configuration:
- `default`: default configuration
- `simple`: simple logger that works like print() but with colors
- `profesionall`: saves logs to file, displays time, filename line number and lvl#### Example 1:
```python
from easy_logs.utils import get_logger
logger = get_logger(lvl = 10)
logger.debug("debug")
logger.info("info")
logger.warning("warning")
logger.error("error")
logger.critical("critical")
```#### output:
#### example 2:
```python
from easy_logs.utils import get_logger
logger = get_logger(
datefmt="%Y-%m-%d %H:%M:%S",
format="%(asctime)s %(levelname)s %(funcName)s %(message)s",
disable_existing_loggers=True,
logger_name="test2",
file_name = None,
lvl="INFO",
)def example_func():
logger.debug("debug")
logger.info("info")
logger.warning("warning")
logger.error("error")
logger.critical("critical")
example_func()
```#### output:
#### example 3:
```python
from easy_logs import get_loggerlogger = get_logger(predefined="profesionall")
logger.info("Everything is OK!")
logger.warning("I'm worried about something...")
logger.error("Something went wrong...")
logger.critical("Let's panic!")```
#### output:
![]()