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

https://github.com/obervinov/logger-package

This module is designed to quickly initialize and configure readable and structured logging for my python projects.
https://github.com/obervinov/logger-package

log logger logging logs module poetry poetry-python python-module python-modules python3

Last synced: about 7 hours ago
JSON representation

This module is designed to quickly initialize and configure readable and structured logging for my python projects.

Awesome Lists containing this project

README

          

# Logger Package
[![Release](https://github.com/obervinov/logger-package/actions/workflows/release.yaml/badge.svg)](https://github.com/obervinov/logger-package/actions/workflows/release.yaml)
[![CodeQL](https://github.com/obervinov/logger-package/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/obervinov/logger-package/actions/workflows/github-code-scanning/codeql)
[![PR](https://github.com/obervinov/logger-package/actions/workflows/pr.yaml/badge.svg?branch=main&event=pull_request)](https://github.com/obervinov/logger-package/actions/workflows/pr.yaml)

![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/obervinov/logger-package?style=for-the-badge)
![GitHub last commit](https://img.shields.io/github/last-commit/obervinov/logger-package?style=for-the-badge)
![GitHub Release Date](https://img.shields.io/github/release-date/obervinov/logger-package?style=for-the-badge)
![GitHub issues](https://img.shields.io/github/issues/obervinov/logger-package?style=for-the-badge)
![GitHub repo size](https://img.shields.io/github/repo-size/obervinov/logger-package?style=for-the-badge)

## About this project
This is an additional implementation over the **logging** module.

This module is designed for fast initialization and configuration of readable and structured logging.

## Supported functions
- Color selection depending on the logging level
- Structured and formatted message for more informative
- Loading the logger configuration and format from a environment variables

## Installing with Poetry
```bash
tee -a pyproject.toml < Usage example
### Environment variables
| Name | Description | Default value |
| ------------------------ | ------------------------------------------------ | --------------------------------------------------------------------- |
| `LOGGER_FORMAT` | A string with the event logging format | `[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s` |
| `LOGGER_LEVEL` | Event logging level: DEBUG, INFO, WARNING, ERROR, CRITICAL or NOT SET | `INFO` |
| `LOGGER_DATE_FORMAT` | Date format in logging event output | `%d/%b/%Y %H:%M:%S` |

### Examples
#### Simple
```python
# Import module
from logger import log

# Examples
# error message
log.error(f"this error: {error}")
# warning message
log.warning(f"this warning: {warn}")
# info message
log.info(f"this info: {info}")
```

#### With using class
```python
# Import module
from logger import log

# Add logger to class
class myproject:
def __init__(self):
self.log = create_logger(__name__, self.__class__.__name__)
self.log.info("Init my class")

def warning(self):
self.log.warning("Warning")

def error(self):
self.log.error("Critical error")

def debug(self):
self.log.debug("Debug")

mp = myproject()
mp.warning()
mp.error()
mp.debug()
```

## GitHub Actions
| Name | Version |
| ------------------------ | ----------- |
| GitHub Actions Templates | [v2.1.1](https://github.com/obervinov/_templates/tree/v2.1.1) |