Skip to main content

A package integrating loguru and apprise for logging and notifications

Project description

Logprise

Logprise is a Python package that seamlessly integrates loguru and apprise to provide unified logging and notification capabilities. It allows you to automatically send notifications when specific log levels are triggered, making it perfect for monitoring applications and getting alerts when important events occur.

Features

  • Unified logging interface that captures both standard logging and loguru logs
  • Automatic notification delivery based on configurable log levels
  • Batched notifications to prevent notification spam
  • Flexible configuration through apprise's extensive notification service support
  • Periodic flushing of log messages at configurable intervals
  • Automatic capture of uncaught exceptions
  • Easy integration with existing Python applications

Installation

pip install logprise

Or if you're using Poetry:

poetry add logprise

Quick Start

Here's a simple example of how to use Logprise:

from logprise import logger

# Your logs will automatically trigger notifications
logger.info("This won't trigger a notification")
logger.warning("This won't trigger a notification")
logger.error("This will trigger a notification")  # Default is ERROR level

# Notifications are automatically sent when your program exits
# or periodically according to the flush interval

Configuration

Notification Services

Logprise uses Apprise for notifications, which supports a wide range of notification services. Create an .apprise file in one of the default configuration paths:

  • ~/.apprise
  • ~/.config/apprise

Example configuration:

mailto://user:pass@gmail.com
tgram://bot_token/chat_id
slack://tokenA/tokenB/tokenC/#channel

See Apprise's configuration guide for the full list of supported services and their configuration.

Notification Levels

You can set the minimum log level that triggers notifications:

from logprise import appriser, logger

# Using string level names
appriser.notification_level = "WARNING"  # or "DEBUG", "INFO", "ERROR", "CRITICAL"

# Using integer level numbers
appriser.notification_level = 30  # WARNING level

# Using loguru Level objects
appriser.notification_level = logger.level("ERROR")

Controlling Notification Timing

Logprise offers several ways to control when notifications are sent:

from logprise import appriser

# Set the flush interval for periodic notifications (in seconds)
appriser.flush_interval = 3600  # Default is hourly

# Manually send notifications immediately
appriser.send_notification()

# Clear the notification buffer
appriser.buffer.clear()

# Stop the periodic flush thread
appriser.stop_periodic_flush()

# Manually cleanup and flush pending notifications
appriser.cleanup()

Handling Uncaught Exceptions

Logprise automatically captures uncaught exceptions and sends notifications. This helps you detect and respond to unexpected application failures:

# This will be logged and trigger a notification
raise ValueError("Something went wrong")

Contributing

To contribute to the project:

# Clone the repository
git clone https://github.com/yourusername/logprise.git
cd logprise

# Install dependencies
poetry install

# Run tests
poetry run pytest

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

logprise-1.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logprise-1.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file logprise-1.1.1.tar.gz.

File metadata

  • Download URL: logprise-1.1.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for logprise-1.1.1.tar.gz
Algorithm Hash digest
SHA256 6a3085ce4f86d5063a1edde114a2b70bffd104d8e33f181ae108c4b9a9256416
MD5 757cc117e9b8f03f332fba313a0d3d03
BLAKE2b-256 b52f17e27970f5cdcd705b3c9fc51789c59ab34593c32a640078e8fec35e2550

See more details on using hashes here.

Provenance

The following attestation bundles were made for logprise-1.1.1.tar.gz:

Publisher: release.yml on svaningelgem/logprise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file logprise-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: logprise-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for logprise-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec009210bb62b7a5175355cfde78b31fb5b2582d69d1cb760c8aea0a1f0a7cbd
MD5 a1325438f45234564bd54cc3f9769315
BLAKE2b-256 a40d61be80bf4ef8bab306e5cd612d2395773d5f3c01c16d142f35a6b142b7e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for logprise-1.1.1-py3-none-any.whl:

Publisher: release.yml on svaningelgem/logprise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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