Log request bodies at nginx and view logs in Dozzle
Test and deploy / deploy (push) Has been cancelled
Test and deploy / test (push) Has been cancelled

nginx writes one JSON line per request, body included, to
logs/nginx/payloads.log (nginx/payload_log.conf). Bodies mentioning a
password, token or secret are logged as [redacted]. A `traffic` container
tails the file so it shows up as its own stream in Dozzle, which is served
at /dozzle/ behind the admin auth_request.

Dozzle replaces the admin panel's Diagnostics tab, so that tab and the
/admin/logs endpoint behind it are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-15 15:46:26 +01:00
co-authored by Claude Opus 5.5
parent 604ac32028
commit 58880a4e07
16 changed files with 182 additions and 289 deletions
+1 -1
View File
@@ -125,7 +125,7 @@ the Vite proxy in dev).
The backend's REST routes go through `src/api.js`, the same idea for plain JSON:
```js
const body = await api.get("/admin/logs", { fallback: "Failed to load logs" });
const songs = await api.get("/radio/songs", { fallback: "Failed to load songs" });
await api.post("/radio/upload", formData, { fallback: "Upload failed" });
```
+1 -1
View File
@@ -4,7 +4,7 @@
* OAuth starts — everything backend/README.md lists as "not GraphQL").
*
* It does two things a bare axios call does not:
* - prefixes `/api`, so callers name the route (`api.get("/admin/logs")`);
* - prefixes `/api`, so callers name the route (`api.get("/radio/songs")`);
* - turns a failure into an ApiError whose `message` is the backend's
* `{"error": "..."}` body when there is one. Every handler reports errors
* in that shape, and each view used to dig it out of `err.response` itself.
+10 -2
View File
@@ -19,7 +19,6 @@ import CreatePlace from "./CreatePlace.vue";
import ManagePages from "./ManagePages.vue";
import ManageUsers from "./ManageUsers.vue";
import ManageRadio from "./ManageRadio.vue";
import Diagnostics from "./Diagnostics.vue";
const auth = useAuthStore();
@@ -34,7 +33,6 @@ const sections = [
{ id: "pages", label: "Pages", component: ManagePages },
{ id: "users", label: "Manage Users", component: ManageUsers },
{ id: "radio", label: "Manage Radio", component: ManageRadio },
{ id: "diagnostics", label: "Diagnostics", component: Diagnostics },
];
const active = ref("place");
@@ -71,6 +69,16 @@ function handleLogout() {
>
{{ section.label }}
</button>
<!-- Logs and incoming request bodies live in Dozzle, outside the
SPA (nginx serves it at /dozzle/ behind the admin check). -->
<a
class="admin-nav-link no-underline"
href="/dozzle/"
target="_blank"
rel="noopener"
>
Logs ↗
</a>
</nav>
<section class="admin-panel bdr-2 bg-surface">
-110
View File
@@ -1,110 +0,0 @@
<script setup>
/**
* Admin panel: tail of the backend log.
*
* GET /api/admin/logs returns JSON read from the filesystem, not GraphQL —
* it is not part of the site's data model.
*
* An admin who remounts the component via tab switches re-triggers
* onMounted, which is the desired "refresh on tab change" behaviour.
*/
import { ref, onMounted, computed } from "vue";
import { api } from "@/api";
import Button from "@/components/input/Button.vue";
const lines = ref([]);
const logsError = ref("");
const loadingLogs = ref(false);
async function fetchLogs() {
loadingLogs.value = true;
try {
const res = await api.get("/admin/logs", {
fallback: "Failed to load logs",
});
lines.value = res.lines;
logsError.value = "";
} catch (err) {
logsError.value = err.message;
} finally {
loadingLogs.value = false;
}
}
// Traffic view: a filter over the log tail for "who is using my site" —
// lines with a client IP (the formatter appends it only for real visitors
// and error statuses). Skips the standard line numbers of JSON-array output.
const trafficOnly = ref(true);
const shownLines = computed(() => {
if (!trafficOnly.value) return lines.value;
return lines.value.filter((l) => /\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(l.trim()) || l.includes("!!! SERVER ERROR") || l.includes(" !!"));
});
onMounted(fetchLogs);
</script>
<template>
<div class="diagnostics">
<h1>Logs</h1>
<p class="hint">
Tail of the backend log (up to 500 lines): HTTP traffic and application
messages, newest last.
</p>
<div class="log-controls">
<label class="hint toggle">
<input type="checkbox" v-model="trafficOnly" /> visitors only
</label>
<Button :disabled="loadingLogs" @click="fetchLogs">
{{ loadingLogs ? "Loading…" : "Refresh" }}
</Button>
</div>
<p v-if="logsError" class="error">{{ logsError }}</p>
<p v-else-if="shownLines.length === 0" class="hint">
No {{ trafficOnly ? "visitor" : "" }} lines in the current tail.
</p>
<pre v-else class="log-output">{{ shownLines.join("\n") }}</pre>
</div>
</template>
<style scoped>
.diagnostics {
display: flex;
flex-direction: column;
gap: 8px;
}
.error {
color: var(--color-error, #b91c1c);
}
.hint {
font-size: 0.85rem;
opacity: 0.75;
}
.log-controls {
display: flex;
justify-content: flex-end;
gap: 12px;
align-items: center;
}
.toggle {
display: flex;
gap: 4px;
align-items: center;
cursor: pointer;
}
.log-output {
max-height: 400px;
overflow-y: auto;
padding: 8px;
background: var(--color-surface-tint, #111);
color: var(--color-primary);
font-size: 0.75rem;
line-height: 1.4;
white-space: pre-wrap;
word-break: break-all;
border: 1px solid var(--color-quaternary);
}
</style>