Skip to main content

A custom logger with Redis integration

Project description

arb_logger

Introduction

arb_logger is a Python package that provides advanced logging capabilities, including file logging, console logging with colors, and Redis integration. This package aims to simplify and standardize logging for Python applications by offering an easy-to-use interface and configurable options.

Features

  • Colored console logging
  • Logging to file with optional log rotation
  • Logging to Redis using streams
  • Custom log level for STDOUT
  • Uncaught exceptions logging
  • Customizable log format
  • Unit tests for key functionality
  • arb_alerts program to listen to Redis streams and send alerts on MacOS

Installation

To install the arb_logger package from PyPI, simply run the following command:

pip install arb_logger

To install the arb_logger package from source, simply clone the repository and install it using pip:

git clone https://github.com/acid3croco/arb_logger.git
cd arb_logger
pip install .

Usage

Basic Usage

Here's an example of how to create a logger with default settings:

from arb_logger import get_logger

# The name of the logger will be the name of the calling module
# if you call the logger from the main module (i.e. __name__ == "__main__")
# you have to specify the name of the logger, if you call it from a module
# the name of the logger will be the name of the module automatically
logger = get_logger('basic_logger')

logger.debug("Debug message")
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")
logger.critical("Critical message")

Advanced Usage

In this example, we create a logger with custom settings:

from pathlib import Path
from arb_logger import get_logger

custom_path = Path("custom_logs")
logger = get_logger(name="my_logger", level=logging.DEBUG, path=custom_path,
                    log_in_file=True, short=False, redis_handler=True)

logger.debug("Debug message")
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")
logger.critical("Critical message")

Code documentation

get_logger

get_logger is the main function used to create a logger with custom settings.

def get_logger(name: str = None,
               level: int = logging.DEBUG,
               path: Path = None,
               log_in_file: bool = True,
               short: bool = False,
               redis_handler: bool = True,
               custom_redis_client: Redis = None) -> logging.Logger:

Parameters

  • name: The name of the logger. Defaults to the name of the calling module.
  • level: The minimum log level to log messages. Defaults to logging.DEBUG.
  • path: The directory where log files will be saved. Defaults to None, which means the default log directory will be used.
  • log_in_file: Whether to log messages to a file. Defaults to True.
  • short: Whether to use a short log filename without the process ID. Defaults to False.
  • redis_handler: Whether to use a Redis handler for logging. Defaults to True.
  • custom_redis_client: A custom Redis client to use for logging. Defaults to None, which means a new Redis client will be created using the get_redis_log_client() method inside logger.py.

Returns

A logger with the specified settings.


arb_alerts

arb_alerts is a script that listens for log messages from a Redis channel and processes them. It logs the messages to a local logger and sends macOS notifications for messages with log level ERROR or higher.

Features

arb_alerts
  • Listens for log messages on a Redis channel.
  • Logs the messages to a local logger.
  • Sends macOS notifications for messages with log level ERROR or higher.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arb_logger-2.2.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

arb_logger-2.2.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file arb_logger-2.2.1.tar.gz.

File metadata

  • Download URL: arb_logger-2.2.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for arb_logger-2.2.1.tar.gz
Algorithm Hash digest
SHA256 4779f9e9f77fb0f072e67775ce55b89c1fb6d5aeb04384692ea480c806865cb5
MD5 731c1c740b980718e2a385d8f4500e95
BLAKE2b-256 58c0b828e1c111fef08f84415e1428cfc6bcd303642c994d2477b13d42434e63

See more details on using hashes here.

File details

Details for the file arb_logger-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: arb_logger-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for arb_logger-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9b589d08e84a79a0a1efed54ee1b02fc765307124a874253a91d02f67446500
MD5 a00410b9c322c4acd5476efb61cb2c62
BLAKE2b-256 9e794bb1f155303c42e59bb51221d0071e4b163e5092cd0c80b4981b4d0745ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page