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 neologger 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 neologger 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 neologger 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.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: neologger-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 0aa02a8272934a5a95f557c2c1d731b93bb368bd9409486299241d9a3bba5d02
MD5 b94d28085a793ae58b20559b77a8a7f5
BLAKE2b-256 17f3c9965dd5d99e082386a2e696503a71d9642567b1979a6d962a118aa392c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: neologger-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 769a562d0be809b09a402a67cbbf42b3cfd0573a357fec9970dafa6cadf5f47f
MD5 fd65d3e4528df074345710f8f4625a69
BLAKE2b-256 6e6ef563c65ece595051754ae4a45adba23e8df59e4720b9399b13320e31138c

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