Database & Migrations: - Add application_logs table migration for hybrid cloud logging - Add companies table migration and restructure vendor relationships Logging System: - Implement hybrid logging system (database + file) - Add log_service for centralized log management - Create admin logs page with filtering and viewing capabilities - Add init_log_settings.py script for log configuration - Enhance core logging with database integration Marketplace Integration: - Add marketplace admin page with product management - Create marketplace vendor page with product listings - Implement marketplace.js for both admin and vendor interfaces - Add marketplace integration documentation Admin Enhancements: - Add imports management page and functionality - Create settings page for admin configuration - Add vendor themes management page - Enhance vendor detail and edit pages - Improve code quality dashboard and violation details - Add logs viewing and management - Update icons guide and shared icon system Architecture & Documentation: - Document frontend structure and component architecture - Document models structure and relationships - Add vendor-in-token architecture documentation - Add vendor RBAC (role-based access control) documentation - Document marketplace integration patterns - Update architecture patterns documentation Infrastructure: - Add platform static files structure (css, img, js) - Move architecture_scan.py to proper models location - Update model imports and registrations - Enhance exception handling - Update dependency injection patterns UI/UX: - Improve vendor edit interface - Update admin user interface - Enhance page templates documentation - Add vendor marketplace interface
379 lines
19 KiB
HTML
379 lines
19 KiB
HTML
{# app/templates/admin/logs.html #}
|
|
{% extends "admin/base.html" %}
|
|
|
|
{% block title %}Application Logs{% endblock %}
|
|
|
|
{% block alpine_data %}adminLogs(){% endblock %}
|
|
|
|
{% block content %}
|
|
<!-- Page Header -->
|
|
<div class="flex items-center justify-between my-6">
|
|
<h2 class="text-2xl font-semibold text-gray-700 dark:text-gray-200">
|
|
Application Logs
|
|
</h2>
|
|
<div class="flex items-center space-x-3">
|
|
<button
|
|
@click="refresh()"
|
|
:disabled="loading"
|
|
class="flex items-center px-4 py-2 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-lg hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple disabled:opacity-50 disabled:cursor-not-allowed"
|
|
>
|
|
<span x-show="!loading" x-html="$icon('refresh', 'w-4 h-4 mr-2')"></span>
|
|
<span x-show="loading" x-html="$icon('spinner', 'w-4 h-4 mr-2')"></span>
|
|
<span x-text="loading ? 'Loading...' : 'Refresh'"></span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Success Message -->
|
|
<div x-show="successMessage" x-transition class="mb-6 p-4 bg-green-100 border border-green-400 text-green-700 rounded-lg flex items-start">
|
|
<span x-html="$icon('check-circle', 'w-5 h-5 mr-3 mt-0.5 flex-shrink-0')"></span>
|
|
<div>
|
|
<p class="font-semibold">Success</p>
|
|
<p class="text-sm" x-text="successMessage"></p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Error Message -->
|
|
<div x-show="error" x-transition class="mb-6 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg flex items-start">
|
|
<span x-html="$icon('exclamation', 'w-5 h-5 mr-3 mt-0.5 flex-shrink-0')"></span>
|
|
<div>
|
|
<p class="font-semibold">Error</p>
|
|
<p class="text-sm" x-text="error"></p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Statistics Cards -->
|
|
<div x-show="stats" class="grid gap-6 mb-8 md:grid-cols-2 xl:grid-cols-4">
|
|
<!-- Total Logs -->
|
|
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
|
|
<div class="p-3 mr-4 text-blue-500 bg-blue-100 rounded-full dark:text-blue-100 dark:bg-blue-500">
|
|
<span x-html="$icon('document-text', 'w-5 h-5')"></span>
|
|
</div>
|
|
<div>
|
|
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Total Logs (7d)</p>
|
|
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.total_count">0</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Warnings -->
|
|
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
|
|
<div class="p-3 mr-4 text-yellow-500 bg-yellow-100 rounded-full dark:text-yellow-100 dark:bg-yellow-500">
|
|
<span x-html="$icon('exclamation', 'w-5 h-5')"></span>
|
|
</div>
|
|
<div>
|
|
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Warnings</p>
|
|
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.warning_count">0</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Errors -->
|
|
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
|
|
<div class="p-3 mr-4 text-red-500 bg-red-100 rounded-full dark:text-white dark:bg-red-600">
|
|
<span x-html="$icon('x-circle', 'w-5 h-5')"></span>
|
|
</div>
|
|
<div>
|
|
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Errors</p>
|
|
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.error_count">0</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Critical -->
|
|
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
|
|
<div class="p-3 mr-4 text-purple-500 bg-purple-100 rounded-full dark:text-purple-100 dark:bg-purple-500">
|
|
<span x-html="$icon('lightning-bolt', 'w-5 h-5')"></span>
|
|
</div>
|
|
<div>
|
|
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Critical</p>
|
|
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.critical_count">0</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Log Source Tabs -->
|
|
<div class="mb-6">
|
|
<div class="border-b border-gray-200 dark:border-gray-700">
|
|
<nav class="-mb-px flex space-x-8">
|
|
<button
|
|
@click="logSource = 'database'; loadLogs()"
|
|
:class="logSource === 'database' ? 'border-purple-500 text-purple-600 dark:text-purple-400' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300'"
|
|
class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm transition-colors"
|
|
>
|
|
<span x-html="$icon('database', 'inline w-5 h-5 mr-2')"></span>
|
|
Database Logs
|
|
</button>
|
|
<button
|
|
@click="logSource = 'file'; loadFileLogs()"
|
|
:class="logSource === 'file' ? 'border-purple-500 text-purple-600 dark:text-purple-400' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300'"
|
|
class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm transition-colors"
|
|
>
|
|
<span x-html="$icon('document', 'inline w-5 h-5 mr-2')"></span>
|
|
File Logs
|
|
</button>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Database Logs Section -->
|
|
<div x-show="logSource === 'database'" x-transition>
|
|
<!-- Filters -->
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
|
|
<div class="flex items-center justify-between mb-4">
|
|
<h3 class="text-lg font-semibold text-gray-700 dark:text-gray-200">Filters</h3>
|
|
<button
|
|
@click="resetFilters()"
|
|
class="text-sm text-purple-600 hover:text-purple-700 dark:text-purple-400"
|
|
>
|
|
Reset Filters
|
|
</button>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
<!-- Log Level Filter -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Log Level</label>
|
|
<select
|
|
x-model="filters.level"
|
|
@change="loadLogs()"
|
|
class="block w-full px-3 py-2 text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-600"
|
|
>
|
|
<option value="">All Levels</option>
|
|
<option value="WARNING">WARNING</option>
|
|
<option value="ERROR">ERROR</option>
|
|
<option value="CRITICAL">CRITICAL</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Module Filter -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Module</label>
|
|
<input
|
|
type="text"
|
|
x-model="filters.module"
|
|
@keyup.enter="loadLogs()"
|
|
placeholder="Filter by module..."
|
|
class="block w-full px-3 py-2 text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-600"
|
|
/>
|
|
</div>
|
|
|
|
<!-- Search -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Search</label>
|
|
<input
|
|
type="text"
|
|
x-model="filters.search"
|
|
@keyup.enter="loadLogs()"
|
|
placeholder="Search in messages..."
|
|
class="block w-full px-3 py-2 text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-600"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Database Logs Table -->
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden">
|
|
<div class="overflow-x-auto">
|
|
<table class="w-full whitespace-no-wrap">
|
|
<thead>
|
|
<tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800">
|
|
<th class="px-4 py-3">Timestamp</th>
|
|
<th class="px-4 py-3">Level</th>
|
|
<th class="px-4 py-3">Module</th>
|
|
<th class="px-4 py-3">Message</th>
|
|
<th class="px-4 py-3">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
|
|
<template x-if="loading">
|
|
<tr>
|
|
<td colspan="5" class="px-4 py-8 text-center">
|
|
<span x-html="$icon('spinner', 'inline w-6 h-6 text-purple-600')"></span>
|
|
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Loading logs...</p>
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
|
|
<template x-if="!loading && logs.length === 0">
|
|
<tr>
|
|
<td colspan="5" class="px-4 py-8 text-center text-gray-500 dark:text-gray-400">
|
|
No logs found
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
|
|
<template x-for="log in logs" :key="log.id">
|
|
<tr class="text-gray-700 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-700">
|
|
<td class="px-4 py-3 text-sm">
|
|
<span x-text="formatTimestamp(log.timestamp)"></span>
|
|
</td>
|
|
<td class="px-4 py-3 text-xs">
|
|
<span
|
|
:class="{
|
|
'bg-yellow-100 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-100': log.level === 'WARNING',
|
|
'bg-red-100 text-red-800 dark:bg-red-800 dark:text-red-100': log.level === 'ERROR',
|
|
'bg-purple-100 text-purple-800 dark:bg-purple-800 dark:text-purple-100': log.level === 'CRITICAL'
|
|
}"
|
|
class="px-2 py-1 font-semibold leading-tight rounded-full"
|
|
x-text="log.level"
|
|
></span>
|
|
</td>
|
|
<td class="px-4 py-3 text-sm">
|
|
<span x-text="log.module || '-'"></span>
|
|
</td>
|
|
<td class="px-4 py-3 text-sm">
|
|
<div class="max-w-2xl truncate" x-text="log.message"></div>
|
|
</td>
|
|
<td class="px-4 py-3 text-sm">
|
|
<button
|
|
@click="showLogDetail(log)"
|
|
class="text-purple-600 hover:text-purple-700 dark:text-purple-400"
|
|
>
|
|
<span x-html="$icon('eye', 'w-5 h-5')"></span>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Pagination -->
|
|
<div x-show="!loading && logs.length > 0" class="px-4 py-3 border-t dark:border-gray-700 bg-gray-50 dark:bg-gray-800">
|
|
<div class="flex items-center justify-between">
|
|
<div class="text-sm text-gray-700 dark:text-gray-400">
|
|
Showing <span x-text="filters.skip + 1"></span> to <span x-text="Math.min(filters.skip + filters.limit, totalLogs)"></span> of <span x-text="totalLogs"></span>
|
|
</div>
|
|
<div class="flex space-x-2">
|
|
<button
|
|
@click="previousPage()"
|
|
:disabled="filters.skip === 0"
|
|
class="px-3 py-1 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600"
|
|
>
|
|
Previous
|
|
</button>
|
|
<button
|
|
@click="nextPage()"
|
|
:disabled="filters.skip + filters.limit >= totalLogs"
|
|
class="px-3 py-1 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600"
|
|
>
|
|
Next
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- File Logs Section -->
|
|
<div x-show="logSource === 'file'" x-transition>
|
|
<!-- File Selection -->
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
|
|
<div class="flex items-center justify-between mb-4">
|
|
<h3 class="text-lg font-semibold text-gray-700 dark:text-gray-200">Log Files</h3>
|
|
<button
|
|
@click="loadFileLogs()"
|
|
class="text-sm text-purple-600 hover:text-purple-700 dark:text-purple-400"
|
|
>
|
|
Refresh List
|
|
</button>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Select Log File</label>
|
|
<select
|
|
x-model="selectedFile"
|
|
@change="loadFileContent()"
|
|
class="block w-full px-3 py-2 text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-600"
|
|
>
|
|
<option value="">Select a file...</option>
|
|
<template x-for="file in logFiles" :key="file.filename">
|
|
<option :value="file.filename" x-text="`${file.filename} (${file.size_mb} MB)`"></option>
|
|
</template>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="flex items-end">
|
|
<button
|
|
@click="downloadLogFile()"
|
|
:disabled="!selectedFile"
|
|
class="px-4 py-2 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-green-600 border border-transparent rounded-lg hover:bg-green-700 focus:outline-none focus:shadow-outline-green disabled:opacity-50 disabled:cursor-not-allowed"
|
|
>
|
|
<span x-html="$icon('download', 'inline w-4 h-4 mr-2')"></span>
|
|
Download File
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- File Content -->
|
|
<div x-show="fileContent" class="bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden">
|
|
<div class="p-4 border-b dark:border-gray-700 flex items-center justify-between">
|
|
<div>
|
|
<h3 class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="selectedFile"></h3>
|
|
<p class="text-sm text-gray-600 dark:text-gray-400">
|
|
Showing last <span x-text="fileContent?.lines?.length || 0"></span> lines of <span x-text="fileContent?.total_lines || 0"></span> total
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class="p-4 bg-gray-900 overflow-x-auto">
|
|
<pre class="text-xs text-green-400 font-mono"><code x-text="fileContent?.lines?.join('\n')"></code></pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Log Detail Modal -->
|
|
<div x-show="selectedLog" x-transition class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50" @click.self="selectedLog = null">
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-4xl w-full mx-4 max-h-[90vh] overflow-hidden">
|
|
<div class="p-6 border-b dark:border-gray-700">
|
|
<div class="flex items-center justify-between">
|
|
<h3 class="text-xl font-semibold text-gray-700 dark:text-gray-200">Log Details</h3>
|
|
<button @click="selectedLog = null" class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300">
|
|
<span x-html="$icon('close', 'w-6 h-6')"></span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="p-6 overflow-y-auto max-h-[calc(90vh-120px)]">
|
|
<template x-if="selectedLog">
|
|
<div class="space-y-4">
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<p class="text-sm font-medium text-gray-600 dark:text-gray-400">Timestamp</p>
|
|
<p class="text-sm text-gray-800 dark:text-gray-200" x-text="formatTimestamp(selectedLog.timestamp)"></p>
|
|
</div>
|
|
<div>
|
|
<p class="text-sm font-medium text-gray-600 dark:text-gray-400">Level</p>
|
|
<p class="text-sm text-gray-800 dark:text-gray-200" x-text="selectedLog.level"></p>
|
|
</div>
|
|
<div>
|
|
<p class="text-sm font-medium text-gray-600 dark:text-gray-400">Logger</p>
|
|
<p class="text-sm text-gray-800 dark:text-gray-200" x-text="selectedLog.logger_name"></p>
|
|
</div>
|
|
<div>
|
|
<p class="text-sm font-medium text-gray-600 dark:text-gray-400">Module</p>
|
|
<p class="text-sm text-gray-800 dark:text-gray-200" x-text="selectedLog.module || '-'"></p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<p class="text-sm font-medium text-gray-600 dark:text-gray-400 mb-2">Message</p>
|
|
<p class="text-sm text-gray-800 dark:text-gray-200 bg-gray-50 dark:bg-gray-700 p-3 rounded" x-text="selectedLog.message"></p>
|
|
</div>
|
|
<div x-show="selectedLog.exception_message">
|
|
<p class="text-sm font-medium text-gray-600 dark:text-gray-400 mb-2">Exception</p>
|
|
<p class="text-sm text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-900 p-3 rounded" x-text="selectedLog.exception_type + ': ' + selectedLog.exception_message"></p>
|
|
</div>
|
|
<div x-show="selectedLog.stack_trace">
|
|
<p class="text-sm font-medium text-gray-600 dark:text-gray-400 mb-2">Stack Trace</p>
|
|
<pre class="text-xs text-gray-800 dark:text-gray-200 bg-gray-50 dark:bg-gray-700 p-3 rounded overflow-x-auto"><code x-text="selectedLog.stack_trace"></code></pre>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% endblock %}
|
|
|
|
{% block extra_scripts %}
|
|
<script src="{{ url_for('static', path='admin/js/logs.js') }}"></script>
|
|
{% endblock %}
|