Skip to main content

logginger

Logginger is a simple logging library that includes tools to extend the logging module.

image image image image image

Description

A python package that provides logging tools such as handlers and formatter for logging. This allows developers to use these tools to use in their python logging, and they have more control over the logging.

Additional features include:

  1. Logging to Slack (via webhook or token)
  2. Logging to File

Installation

pip install logginger

Arguments

  • slack_token (str): The Slack API token if not using webhook_url Generate a key at https://api.slack.com/
  • channel (str): The Slack channel to post to if not using webhook_url
  • webhook_url (str): The Slack webhook URL if using webhook_url
  • is_webhook (bool): Whether to use webhook_url or not (Defaults to True)
  • is_debug (bool): Doesn't send Slack messages if True (Defaults to False)
  • stack_trace (bool): Whether to include the stacktrace in the Slack message (Defaults to True)
  • username (str): The username to use for the Slack message (Not usable if using webhook_url)
  • icon_url (str): The icon URL to use for the Slack message (Not usable if using webhook_url)
  • icon_emoji (str): The icon emoji to use for the Slack message (Not usable if using webhook_url)
  • msg_len (int): The maximum length of the Slack message (Defaults to 1300)
  • traceback_len (int): The maximum length of the stack_trace (Defaults to 700)
  • fail_silent (bool): Whether to fail silently if the Slack API returns an error (Defaults to False) Defaults to False. If your API key is invalid or for some other reason the API call returns an error, this option will silently ignore the API error. If you enable this setting, make sure you have another log handler that will also handle the same log events, or they may be lost entirely.

Example Python logging handler

This is how you use log_to_slack as a regular Python logging handler. This example will send a error message to a slack channel.

import logging
import os

from logginger import SlackLogHandler
from logginger.formatters import NoStacktraceFormatter, DefaultFormatter

WEBHOOK_URL = os.getenv("WEBHOOK_URL")

logger = logging.getLogger("debug_application")
logger.setLevel(logging.DEBUG)

default_formatter = DefaultFormatter("%(levelprefix)s %(asctime)s (%(name)s) %(message)s")
no_stacktrace_formatter = NoStacktraceFormatter("%(levelprefix)s %(asctime)s (%(name)s) %(message)s")

default_handler = logging.StreamHandler()
default_handler.setFormatter(default_formatter)
logger.addHandler(default_handler)

slack_handler = SlackLogHandler(webhook_url=WEBHOOK_URL, stack_trace=True)
slack_handler.setFormatter(no_stacktrace_formatter)
slack_handler.setLevel(logging.ERROR)
logger.addHandler(slack_handler)

# Main code
logger.debug("Test DEBUG")
logger.info("Test INFO")
logger.warning("Test WARNING")
logger.error("Test ERROR")
logger.fatal("Test FATAL")
logger.critical("Test CRITICAL")

try:
    raise Exception("Test exception")
except Exception as e:
    logger.exception(e)

Slack message formatting

This example use a subclass that will send a formatted message to a Slack channel. Learn More

class CustomLogHandler(SlackLogHandler):
    def build_msg(self, record):
        message = "> New message :\n" + record.getMessage()
        return message

License

Apache 2.0

See also:

Metadata

Release files for logginger 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logginger 0.0.5
File Size Uploaded Provenance
logginger-0.0.5.tar.gz 11.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for logginger 0.0.5
File Interpreter ABI Platform
logginger-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 23.1 kB

Release files / logginger-0.0.5.tar.gz

Download URL logginger-0.0.5.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e40c0c6bd73ede5153a3ce01f061e79ed4e336d0297a28bc20c64f9c69c7faad
BLAKE2b-256 checksum
How to use checksums
65f55c438854571af6d37e99401f40269ecb71c6c58eb735ca2fed559237a339
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0

Release files / logginger-0.0.5-py3-none-any.whl

Download URL logginger-0.0.5-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41353ded00c286eaa3a27da863b0651d65794bacb6c51552b6fadbe31541a9f0
BLAKE2b-256 checksum
How to use checksums
76c0cc9dd2e7c3ba4e4a00e8820be22236065e7205b24fa5d258150703fe7cf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0

Security for logginger 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page