An advanced, feature-rich logging utility with real-time monitoring, performance profiling, anomaly detection, and comprehensive analytics for Python applications.
Project description
InsightLogger
A comprehensive logging and monitoring library for Python applications with performance tracking, system monitoring, and analytics capabilities.
Installation
pip install insightlog
Quick Start
from insightlog import InsightLogger
# Basic setup
logger = InsightLogger(name="MyApp")
# Log messages
logger.log_types("INFO", "Application started")
logger.log_types("ERROR", "Something went wrong")
# Track function performance
@logger.log_function_time
def my_function():
# Your code here
pass
# View insights
logger.view_insights()
Features
Core Logging
- Multiple log levels (INFO, DEBUG, ERROR, SUCCESS, WARNING, CRITICAL, etc.)
- Colored console output
- File logging with rotation
- Contextual logging with metadata and tags
Performance Monitoring
- Function execution time tracking
- Memory usage monitoring
- System resource monitoring (CPU, memory, network)
- Custom metrics tracking
Analytics & Reporting
- Performance profiling and bottleneck identification
- Anomaly detection
- Health scoring
- HTML dashboard generation
- Data export (JSON, CSV)
Advanced Features
- Database logging (SQLite)
- Email alerts for critical events
- Security event logging
- Plugin system for extensibility
Configuration
Basic Configuration
logger = InsightLogger(
name="MyApp",
enable_monitoring=True, # Enable system monitoring
enable_database=True, # Enable database logging
enable_alerts=False # Disable email alerts
)
Customizable Tracking Options
You can selectively enable/disable specific tracking features:
logger = InsightLogger(
name="MyApp",
# Core settings
save_log="enabled", # File logging: "enabled" or "disabled"
log_level=logging.INFO, # Log level
# Monitoring options
enable_monitoring=True, # System resource monitoring
enable_database=True, # Database logging
enable_alerts=False, # Email alerts
# File settings
log_dir=".insight", # Log directory
max_bytes=1000000, # Max log file size
backup_count=3 # Number of backup files
)
Alert Configuration
# Enable email alerts
logger = InsightLogger(
name="MyApp",
enable_alerts=True,
alert_email="admin@company.com",
smtp_server="smtp.gmail.com",
smtp_port=587,
smtp_user="alerts@company.com",
smtp_password="your_password"
)
# Customize alert thresholds
logger.alert_thresholds = {
'cpu_usage': 80, # CPU percentage
'memory_usage': 85, # Memory percentage
'error_rate': 10, # Error rate percentage
'response_time': 5000 # Response time in ms
}
Usage Examples
Performance Tracking
# Method 1: Decorator
@logger.log_function_time
def process_data():
# Your code here
pass
# Method 2: Context manager
with logger.performance_profile("data_processing"):
# Your code here
pass
Custom Metrics
# Track application-specific metrics
logger.add_custom_metric("active_users", 150)
logger.add_custom_metric("cache_hit_rate", 0.95)
# Track API calls
logger.track_api_call("/api/users", "GET", response_time=234, status_code=200)
Security Logging
logger.log_security_event("LOGIN_ATTEMPT", "MEDIUM", "Failed login attempt")
Batch Logging
logs = [
{"level": "INFO", "message": "Processing item 1"},
{"level": "INFO", "message": "Processing item 2"},
("SUCCESS", "Batch completed")
]
logger.batch_log(logs)
Contextual Logging
logger.log_with_context(
"INFO",
"User action performed",
context={"user_id": 12345, "action": "file_upload"},
tags=["user_activity", "audit"]
)
Reports and Dashboards
Generate Reports
# View insights in console
logger.view_insights(detailed=True)
# Create HTML dashboard
logger.view_insights(create_dashboard=True)
# Export data
logger.export_data("json", include_raw_data=True)
logger.export_data("csv")
Output Files
InsightLogger creates files in the .insight directory:
.insight/
├── app.log # Log file
├── insights_[session].db # SQLite database
├── dashboard_[session].html # HTML dashboard
├── log_frequency_[timestamp].png # Charts
├── system_metrics_[timestamp].png
└── function_performance_[timestamp].png
Framework Integration
Flask Example
from flask import Flask
from insightlog import InsightLogger
app = Flask(__name__)
logger = InsightLogger("FlaskApp", enable_monitoring=True)
@app.route('/api/data')
@logger.log_function_time
def get_data():
logger.track_api_call("/api/data", "GET", response_time=150, status_code=200)
return {"data": "example"}
Documentation
For detailed documentation, examples, and advanced usage, see the docs directory.
License
MIT License. See LICENSE for details.
Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.
Support
- GitHub Issues: Report bugs
- Documentation: docs/
- PyPI: https://pypi.org/project/insightlog/
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 insightlog-1.5.tar.gz.
File metadata
- Download URL: insightlog-1.5.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca44fc17c9c1b2d975821e3b4174f7e3b758463a34c1e0c16d8701d5d39d45ce
|
|
| MD5 |
60bb43b1b0078af7f3b489b84361b110
|
|
| BLAKE2b-256 |
2da08642e37925f952bf65edf9ca4cd6b7791d2d1a740af0d662d88b98e803c0
|
File details
Details for the file insightlog-1.5-py3-none-any.whl.
File metadata
- Download URL: insightlog-1.5-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d74cecff509ca04e0e71dea4d9506c7d4c8c0a5504f2e6e78b53fe3db7b00141
|
|
| MD5 |
826ebfaa71c91bbbea9c3c5f39bfe98e
|
|
| BLAKE2b-256 |
fd642d76285eeced10542002dd242356676dc2e502f78d9c42409008c05940ba
|