A pluggable log shipper and alerting agent.
Project description
Markdown
Log Shipper & Alerting Agent
A highly pluggable, pattern-driven logging agent built in Python that dynamically routes log events to multiple third-party providers (like Slack, Email, and more) based on log severity thresholds.
This project serves as a practical blueprint for implementing clean, decoupled software architectures using classic Gang of Four (GoF) design patterns inside a modern, production-ready Python layout.
Architecture & Design Patterns
The core philosophy of this tool is Open-Closed Principle: the engine shouldn't know how notifications are sent, and individual alerting channels shouldn't know when or why a log event occurs.
[ Application Core ] │ ▼ (Triggers log events) [ LogShipEngine ] ──(Broadcasts)──► [ FilteringAlertObserver ] │ │ │ (Dynamic registration) ▼ (Matches Level?) ├─► SlackAlertObserver ─────────────► Calls SlackStrategy └─► EmailAlertObserver ─────────────► Calls EmailStrategy
Applied Patterns
- Strategy Pattern: Encapsulates the network payload execution details for each provider (
SlackNotificationStrategy,EmailNotificationStrategy) behind a uniformNotificationStrategyabstract base interface. - Observer Pattern: Implements pub-sub routing logic. The
LogShipperEngineacts as the Subject, passing all logs down to registeredLogObserverinstances, which filter entries before executing notification routines. - Factory Method Pattern: Isolates creation logic inside
NotificationFactory. It parses raw dictionary runtime profiles into functional code blocks, abstracting implementation dependencies away from client endpoints. - Singleton Pattern: Employs a custom
SingletonMetametaclass configured with a thread-safe execution lock (threading.Lock) to manage global configuration states safely across concurrent processing environments.
Getting Started
This repository leverages uv, an incredibly fast Python package installer and workspace manager.
Prerequisites
Make sure you have uv installed on your local environment:
pip install uv
Installation
- Clone this repository to your computer:
git clone https://github.com/khansohil530/ship-logs.git
cd ship-logs
- Sync the environment lockfile and compile requirements:
uv sync
Running the Test Suite
The codebase is built strictly around Test-Driven Development (TDD) principles. Run the unit test suite to verify your configuration structure matches:
uv run pytest
Usage Example
- Define a Configuration File: Create a profile containing an alerts declaration block. You can mix and match log filters across target endpoints. Save this file as config.json:
{
"alerts": [
{
"type": "slack",
"level": "CRITICAL",
"webhook_url": "[https://hooks.slack.com/services/mock-endpoint-string](https://hooks.slack.com/services/mock-endpoint-string)"
},
{
"type": "email",
"level": "ERROR",
"smtp": {
"host": "smtp.internal.net",
"port": 587,
"sender": "secops@company.internal"
}
}
]
}
- "Execute via the CLI Engine":Trigger the shipper instantly from your terminal environment using the registered executable command:
uv run ship-logs --config config.json --level CRITICAL --message "Production database partition out of memory space!"
How to Extend (Add a New Provider)
Adding a brand new delivery provider (like Discord or PagerDuty) requires zero modifications to the core logging pipeline engine.
1: Write a New Strategy Subclass
Open src/ship_logs/strategies.py and extend NotificationStrategy:
class DiscordNotificationStrategy(NotificationStrategy):
def __init__(self, webhook_url: str):
self.webhook_url = webhook_url
def send(self, message: str, context: dict) -> bool:
# Custom HTTP execution logic for Discord payloads goes here...
print(f"Dispatched to Discord: {message}")
return True
2: Register in the Factory
Update NotificationFactory.create_strategy inside src/ship_logs/factory.py to recognize the entry mapping string:
elif normalized_type == "discord":
return DiscordNotificationStrategy(webhook_url=config["webhook_url"])
Now, anyone can use your updated strategy simply by specifying "type": "discord" inside their config.json profile!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ship_logs-0.1.0.tar.gz.
File metadata
- Download URL: ship_logs-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2046015232de3603c55b120c54835596d937448b6a8bdca029faeff9da489151
|
|
| MD5 |
4224cfe0c6f71ca1e96f1368df76ff23
|
|
| BLAKE2b-256 |
3d71f34ee9d3ec7979356e9d41e2a523c4c531a84aab5c75e30a27fa5bd9e881
|
Provenance
The following attestation bundles were made for ship_logs-0.1.0.tar.gz:
Publisher:
python-publish.yml on khansohil530/logship
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ship_logs-0.1.0.tar.gz -
Subject digest:
2046015232de3603c55b120c54835596d937448b6a8bdca029faeff9da489151 - Sigstore transparency entry: 2194678225
- Sigstore integration time:
-
Permalink:
khansohil530/logship@ebf7523aaeefd7ca8da5a5feb12045d9435fc997 -
Branch / Tag:
refs/tags/beta3 - Owner: https://github.com/khansohil530
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@ebf7523aaeefd7ca8da5a5feb12045d9435fc997 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ship_logs-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ship_logs-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff6212304a30999f55105763f2700f29d98893129840e140ca57902c822559e2
|
|
| MD5 |
27fb6ee4c0009c35709787ea42bf5fb2
|
|
| BLAKE2b-256 |
c26d776ba39bb45fd52522ec00077daa42e33d8f92aa90338ca28c120a97b3fb
|
Provenance
The following attestation bundles were made for ship_logs-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on khansohil530/logship
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ship_logs-0.1.0-py3-none-any.whl -
Subject digest:
ff6212304a30999f55105763f2700f29d98893129840e140ca57902c822559e2 - Sigstore transparency entry: 2194678226
- Sigstore integration time:
-
Permalink:
khansohil530/logship@ebf7523aaeefd7ca8da5a5feb12045d9435fc997 -
Branch / Tag:
refs/tags/beta3 - Owner: https://github.com/khansohil530
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@ebf7523aaeefd7ca8da5a5feb12045d9435fc997 -
Trigger Event:
release
-
Statement type: