feat: Add raw log file viewing option in logs view
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -250,6 +250,27 @@ def logs_view(request):
|
||||
search_query = request.GET.get("q", "").strip()
|
||||
level_filter = request.GET.get("level", "").strip().upper()
|
||||
show_all = request.GET.get("all") == "1"
|
||||
raw_mode = request.GET.get("raw") == "1"
|
||||
|
||||
if raw_mode:
|
||||
if not os.path.exists(log_file_path):
|
||||
return HttpResponse(
|
||||
f"Log file not found at {log_file_path}\n",
|
||||
content_type="text/plain; charset=utf-8",
|
||||
status=404,
|
||||
)
|
||||
|
||||
try:
|
||||
with open(log_file_path, "r", encoding="utf-8", errors="ignore") as f:
|
||||
raw_content = f.read()
|
||||
except Exception as e:
|
||||
return HttpResponse(
|
||||
f"Error reading log file: {str(e)}\n",
|
||||
content_type="text/plain; charset=utf-8",
|
||||
status=500,
|
||||
)
|
||||
|
||||
return HttpResponse(raw_content, content_type="text/plain; charset=utf-8")
|
||||
|
||||
log_header_re = re.compile(
|
||||
r"^\[(?P<timestamp>[^\]]+)\]\s+(?P<level>[A-Z]+)\s+\[(?P<logger>[^:\]]+):(?P<line>\d+)\]\s+(?P<message>.*)$"
|
||||
@@ -365,6 +386,7 @@ def logs_view(request):
|
||||
"log_file_path": log_file_path,
|
||||
"show_all": show_all,
|
||||
"limit": limit,
|
||||
"raw_url": f"{reverse('logs_view')}?raw=1",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -80,6 +80,9 @@
|
||||
<a href="{% url 'logs_view' %}?q={{ search_query }}&level={{ level_filter }}&all=1" class="btn btn-outline-info">View all logs</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-12 col-md-auto">
|
||||
<a href="{{ raw_url }}" class="btn btn-outline-dark" target="_blank" rel="noopener">View raw file</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user