Skip to main content

NeoLogger is a Python library that wraps logging and notifications for Stomp and Slack in a simple and easy way.

Project description

NeoLogger

A collection of Python notification classes for enhanced logging, messaging, and Slack notifications.

Overview

NeoNotifications provides a set of tools to improve logging output with customizable styles, send messages over STOMP protocol, and send Slack notifications with rich formatting.

Features

  • NeoLogger: Advanced logging with customizable colors, styles, and templates.
  • StompBabbler: Send messages over STOMP protocol to a specified queue.
  • SlackNotification: Assemble and send richly formatted notifications to Slack channels via webhooks.

Installation

You can install NeoNotifications via pip:

pip install neologger

Requirements

Python 3.6 or higher

Dependencies:

stomp.py
requests

Usage

NeoLogger

Basic Usage

from neologger import NeoLogger

# Initialize the logger
neologger = NeoLogger("your_script.py")

# Log messages
neologger.log_this("This is a general information message.")
neologger.log_this_warning("This is a warning message.")
neologger.log_this_error("This is an error message.")

Customizing Styles and Templates

from neonotifications import NeoLogger, Template

# Initialize the logger
neologger = NeoLogger("your_script.py")

# Set a predefined template
neologger.set_template(Template.DARK)

# Log messages with the new style
neologger.log_this("This message uses the DARK template.")

Measuring Elapsed Time

# Get a time mark
start_time = neologger.get_time_mark()

# ... perform some operations ...

# Log with elapsed time
neologger.log_with_elapsed_time("Operation completed.", start_time)

StompBabbler

from neonotifications import StompBabbler

# Initialize the babbler
stomp_babbler = StompBabbler(
    user_name="username",
    user_password="password",
    queue="/queue/destination",
    server="stomp.server.com",
    port=61613
)

# Send a message
message = {"key": "value"}
status, response = stomp_babbler.babble(message)

if status:
    print("Message sent successfully.")
else:
    print(f"Failed to send message: {response}")

SlackNotification

from neonotifications import SlackNotification
import os

# Initialize the notification
slack_notification = SlackNotification()

# Set the Slack webhook URL (ensure this is stored securely)
slack_notification.set_hook(os.getenv("SLACK_WEBHOOK_URL"))

# Add data fields
slack_notification.add_data("Environment", "Production")
slack_notification.add_data("Status", "Operational")
slack_notification.add_data("Version", "1.0.0")

# Assemble the notification
slack_notification.assemble_notification(
    title="System Status Update",
    summary="All systems are running smoothly.",
    icon="white_check_mark"  # Use Slack emoji code without colons
)

# Send the notification
status, response = slack_notification.send()

if status:
    print("Notification sent successfully.")
else:
    print(f"Failed to send notification: {response}")

Configuration

Environment Variables
SLACK_WEBHOOK_URL: The webhook URL for sending Slack notifications. It is recommended to store this securely, such as in environment variables or a configuration file not checked into version control.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss changes.

License

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

Acknowledgments

Inspired by the need for customizable logging and notification tools in Python applications.

Utilizes the stomp.py library for STOMP protocol messaging.
Utilizes the requests library for HTTP requests to Slack webhooks.

Contact

For questions or suggestions, please contact Pablo Martinez at neolink3891@gmail.com.

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

neologger-1.0.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

neologger-1.0.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file neologger-1.0.0.tar.gz.

File metadata

  • Download URL: neologger-1.0.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.18

File hashes

Hashes for neologger-1.0.0.tar.gz
Algorithm Hash digest
SHA256 56037f69618fd2038a38966c3093d2d90d5f74a01039e595294ba83705a3281f
MD5 4f82723adacb2a9d9d83a6118bf38f0f
BLAKE2b-256 b4007a639de07a96c29923e9df825546aa31ba7b769abec856e0cd33cc80fc86

See more details on using hashes here.

File details

Details for the file neologger-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: neologger-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.18

File hashes

Hashes for neologger-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8d921932a7cd6a38afed08b38d77728da721e09d3c89eb4858b2a7f4e64a7a2
MD5 94e93d92b3a056fd2e1e8ed61f9e9a6e
BLAKE2b-256 cec035cf4a7ea0fe86cb43997d560673a7a9a68aefdf11a7fd95d2b98647b145

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