diff --git a/app.py b/app.py
index 6e79a8a..8fb992c 100644
--- a/app.py
+++ b/app.py
@@ -2623,12 +2623,14 @@ def api_log_stats():
stats = logger_handler.get_log_statistics(days=days)
print(f"📈 Retrieved stats: {stats}")
- # Ensure all expected keys exist
+ # Ensure all expected keys exist with updated categories
expected_stats = {
'total_events': stats.get('total_events', 0),
'security_events': stats.get('security_events', 0),
+ 'authentication_events': stats.get('authentication_events', 0),
+ 'qr_management_events': stats.get('qr_management_events', 0),
'database_errors': stats.get('database_errors', 0),
- 'user_activities': stats.get('user_activities', 0),
+ 'application_events': stats.get('application_events', 0),
'system_events': stats.get('system_events', 0)
}
@@ -2648,8 +2650,10 @@ def api_log_stats():
'stats': {
'total_events': 0,
'security_events': 0,
+ 'authentication_events': 0,
+ 'qr_management_events': 0,
'database_errors': 0,
- 'user_activities': 0,
+ 'application_events': 0,
'system_events': 0
}
}), 500
diff --git a/logger_handler.py b/logger_handler.py
index c574c16..d16cd29 100644
--- a/logger_handler.py
+++ b/logger_handler.py
@@ -608,15 +608,17 @@ class AppLogger:
def get_log_statistics(self, days=7):
"""Get logging statistics for the specified number of days"""
try:
- from datetime import datetime, timedelta # Import here as backup
+ from datetime import datetime, timedelta
cutoff_date = datetime.now() - timedelta(days=days)
- # Initialize default stats
+ # Initialize default stats with all categories
stats = {
'total_events': 0,
'security_events': 0,
+ 'authentication_events': 0,
+ 'qr_management_events': 0,
'database_errors': 0,
- 'user_activities': 0,
+ 'application_events': 0,
'system_events': 0
}
@@ -663,12 +665,17 @@ class AppLogger:
count = row.event_count
print(f"✅ Found {count} events in category: {category}")
+ # Map categories to stats keys
if category == 'security':
stats['security_events'] = count
+ elif category == 'authentication':
+ stats['authentication_events'] = count
+ elif category == 'qr_management':
+ stats['qr_management_events'] = count
elif category == 'database':
stats['database_errors'] = count
- elif category == 'user_activity':
- stats['user_activities'] = count
+ elif category == 'application':
+ stats['application_events'] = count
elif category == 'system':
stats['system_events'] = count
@@ -684,8 +691,10 @@ class AppLogger:
return {
'total_events': 0,
'security_events': 0,
+ 'authentication_events': 0,
+ 'qr_management_events': 0,
'database_errors': 0,
- 'user_activities': 0,
+ 'application_events': 0,
'system_events': 0
}
diff --git a/templates/admin_logs.html b/templates/admin_logs.html
index fed366a..48301d9 100644
--- a/templates/admin_logs.html
+++ b/templates/admin_logs.html
@@ -33,14 +33,14 @@ Management{% endblock %} {% block extra_head %}
-
-
+
+
{{ log_stats.total_events if log_stats else 0 }}
-
Total Events (7 days)
+
Total Events
@@ -56,9 +56,33 @@ Management{% endblock %} {% block extra_head %}
-
-
-
+
+
+
+
+
+
+ {{ log_stats.authentication_events if log_stats else 0 }}
+
+
Authentication
+
+
+
+
+
+
+
+
+
+ {{ log_stats.qr_management_events if log_stats else 0 }}
+
+
QR Management
+
+
+
+
+
+
@@ -68,15 +92,15 @@ Management{% endblock %} {% block extra_head %}
-
-
-
+
+
+
-
- {{ log_stats.user_activities if log_stats else 0 }}
+
+ {{ log_stats.application_events if log_stats else 0 }}
-
User Activities
+
Application Events
@@ -121,16 +145,18 @@ Management{% endblock %} {% block extra_head %}
@@ -559,18 +585,44 @@ Management{% endblock %} {% block extra_head %}
// Load log statistics
async function loadStats() {
try {
- const response = await fetch(
- `/api/logs/stats?days=${currentFilters.days}`
- );
- const data = await response.json();
+ console.log("📊 Loading statistics...");
+ const days = currentFilters.days;
- if (data.success && data.stats) {
- updateStatsDisplay(data.stats);
+ const response = await fetch(`/api/logs/stats?days=${days}`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+
+ const data = await response.json();
+ console.log("📈 Stats received:", data);
+
+ if (data.success) {
+ const stats = data.stats;
+
+ // Update stat cards with new categories
+ document.getElementById("totalEventsCount").textContent =
+ stats.total_events || 0;
+ document.getElementById("securityEventsCount").textContent =
+ stats.security_events || 0;
+ document.getElementById("authEventsCount").textContent =
+ stats.authentication_events || 0;
+ document.getElementById("qrEventsCount").textContent =
+ stats.qr_management_events || 0;
+ document.getElementById("databaseErrorsCount").textContent =
+ stats.database_errors || 0;
+ document.getElementById("applicationEventsCount").textContent =
+ stats.application_events || 0;
+
+ console.log("✅ Statistics updated successfully");
} else {
console.error("Failed to load stats:", data.error);
+ showError("Failed to load statistics: " + (data.error || "Unknown error"));
}
} catch (error) {
console.error("Error loading stats:", error);
+ showError("Failed to load statistics: " + error.message);
}
}
@@ -1325,6 +1377,21 @@ ${
box-shadow: var(--shadow-lg);
}
+ /* Auth stat card styling */
+ .stat-card.auth .stat-icon {
+ background: linear-gradient(135deg, #667eea, #764ba2);
+ }
+
+ /* QR Management stat card styling */
+ .stat-card.qr .stat-icon {
+ background: linear-gradient(135deg, #f093fb, #f5576c);
+ }
+
+ /* Application stat card styling */
+ .stat-card.application .stat-icon {
+ background: linear-gradient(135deg, #4facfe, #00f2fe);
+ }
+
.stat-icon {
width: 60px;
height: 60px;
@@ -1353,6 +1420,7 @@ ${
background: linear-gradient(135deg, var(--success-color), #059669);
}
+
.stat-info h3 {
font-size: var(--font-size-2xl);
font-weight: 700;