Skip to main content

logwatch-ai

AI-powered Windows Event Log anomaly detection library using Isolation Forest.

This library provides a pre-trained machine learning model that analyzes Windows system logs and detects anomalous behavior in real time. It uses a 25-feature Isolation Forest model trained on real Windows Event Log data.


Installation

pip install logwatch-ai

Or install from source:

git clone https://github.com/mouayed-kordi/logwatch-ai.git
cd logwatch-ai
pip install .

Quick Start

from logwatch_ai import AnomalyDetector

# Initialize the detector (loads the pre-trained model)
detector = AnomalyDetector()

# Score a single log entry
result = detector.score_log(
    level="ERROR",
    message="FATAL: Database connection lost due to timeout",
    log_type="Database",
    cpu=85.2,
    ram=72.1,
)

print(result)
# Output:
# {
#     "is_anomaly": True,
#     "score": -0.1234,
#     "threshold": -0.09
# }

API Reference

AnomalyDetector(artifacts_path=None)

Creates a new detector instance and loads the pre-trained model.

Parameter Type Description
artifacts_path str or None Path to custom .pkl model files. If None, uses the bundled pre-trained model.

detector.score_log(...)

Scores a single log entry for anomaly detection.

Parameter Type Default Description
level str (required) Log severity: "INFO", "WARNING", "ERROR", "CRITICAL"
message str (required) Raw log message text
log_type str "Other" Category: "Database", "Authentication", "Network", "Security", "System", "Other"
cpu float 0.0 CPU usage % at the time of the log
ram float 0.0 RAM usage % at the time of the log
timestamp datetime now() When the log occurred
source_key str "default" Identifier to group logs from the same source

Returns a dict:

{
    "is_anomaly": True,    # True if anomaly detected
    "score": -0.1234,      # Raw Isolation Forest score
    "threshold": -0.09     # Calibrated threshold
}

detector.score_batch(logs)

Scores multiple log entries at once.

logs = [
    {"level": "ERROR", "message": "Connection refused", "log_type": "Network"},
    {"level": "INFO", "message": "Service started", "log_type": "System"},
    {"level": "CRITICAL", "message": "Disk full", "log_type": "System", "cpu": 95.0},
]

results = detector.score_batch(logs)
for r in results:
    print(r["is_anomaly"], r["score"])

How It Works

The detector builds a 25-feature vector for each log entry:

  • Temporal features: Rolling error counts (30s, 1m, 5m, 10m, 15m, 60m)
  • Statistical features: CUSUM drift tracking, error density, short/long ratios
  • Hardware features: CPU and RAM velocity (rate of change)
  • Cyclical time features: Hour and day encoded as sin/cos
  • NLP features: TF-IDF + SVD text encoding of the log message

The Isolation Forest model scores each log. If the score falls below the calibrated threshold (-0.09), the log is flagged as anomalous.


License

MIT License

Metadata

Release files for logwatch-ai 1.0.0

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

Source distribution (sdist)

Source distribution for logwatch-ai 1.0.0
File Size Uploaded Provenance Actions
logwatch_ai-1.0.0.tar.gz 694.2 kB Without provenance Details for logwatch_ai-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for logwatch-ai 1.0.0
File Interpreter ABI Platform Actions
logwatch_ai-1.0.0-py3-none-any.whl Python 3 none any Details for logwatch_ai-1.0.0-py3-none-any.whl

Total release size: 1.4 MB

Release files / logwatch_ai-1.0.0.tar.gz

Download URL logwatch_ai-1.0.0.tar.gz
Size 694.2 kB
Tags Source
SHA-256 checksum
How to use checksums
88e6c166ceadf92127dffb59768c314312438f7e6a8411351c00e922d8b1f6dc
BLAKE2b-256 checksum
How to use checksums
015cd365df6ef23effd7a1016b61bc07e2fba7428e244d7ad0b505608208c873
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / logwatch_ai-1.0.0-py3-none-any.whl

Download URL logwatch_ai-1.0.0-py3-none-any.whl
Size 704.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37ee3b7ea66d5206781e9d13cfa19b7162567075ee84731849c5f44c77809ca0
BLAKE2b-256 checksum
How to use checksums
c6bb9bc2ad979c7a1ad528d9a242bfafe49aa2261d2ffbca206d78b3b1435e28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for logwatch-ai 1.0.0

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

1.0.0 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