[PR #7035] feat(logs): add a read-only Logs page with charts and a country map #6589

Open
opened 2026-11-02 04:09:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/7035
Author: @ahmadi-ali
Created: 10/31/2026
Status: 🔄 Open

Base: main ← Head: feat/logs-page


📝 Commits (1)

  • baabc4a feat(logs): add a read-only Logs page with charts and a country map

📊 Changes

61 files changed (+9726 additions, -25 deletions)

View changed files

📝 docs/architecture.md (+2 -0)
➕ docs/content/docs/en/reference/api/logs.mdx (+53 -0)
📝 docs/content/docs/en/reference/api/meta.json (+1 -0)
📝 docs/public/openapi.json (+903 -0)
📝 frontend/public/openapi.json (+903 -0)
➕ frontend/scripts/build-world-map.mjs (+79 -0)
➕ frontend/src/api/queries/useLogs.ts (+75 -0)
📝 frontend/src/api/queryKeys.ts (+6 -0)
📝 frontend/src/components/command-palette/CommandPalette.tsx (+1 -0)
📝 frontend/src/components/viz/Sparkline.css (+4 -0)
📝 frontend/src/components/viz/Sparkline.stories.tsx (+2 -0)
📝 frontend/src/components/viz/Sparkline.tsx (+12 -3)
📝 frontend/src/generated/examples.ts (+160 -0)
📝 frontend/src/generated/schemas.ts (+431 -0)
📝 frontend/src/generated/types.ts (+91 -0)
📝 frontend/src/generated/zod.ts (+101 -0)
➕ frontend/src/lib/logs/countryScale.ts (+17 -0)
➕ frontend/src/lib/logs/logQuery.ts (+126 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+113 -0)
➕ frontend/src/pages/logs/LogsFilterBar.tsx (+173 -0)

...and 41 more files

📄 Description

Summary

Adds a read-only Logs page to the panel (/panel/logs). It has an Overview tab with interactive charts and a world map of requests by country, and a raw-log tab with search and filters. All of it is served by three new GET endpoints that only read files inside XUI_LOG_FOLDER.

Why

To investigate traffic or errors today, an admin has to SSH into the server, or use the Overview log modal, which offers a line count and a text filter but no breakdowns. This page answers the common questions directly in the panel: which IPs, users and hosts are busiest, when errors spiked, and where requests come from. Clicking a chart filters the whole page down to the matching log lines.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

To try it

  1. Build and run the panel. In the Xray advanced config, set "log": { "access": "/var/log/x-ui/access.log" } (the access log is off by default and must be inside XUI_LOG_FOLDER), then restart Xray and send some traffic.
  2. Open Logs in the sidebar and select access.log.
  3. Click a country, a top-list row or a point on a chart. The page should filter, and the raw-log tab should show the same lines.
  4. Check the file restrictions: GET /panel/api/logs/read?file=../../etc/passwd is rejected, and a symlink placed in the log folder is neither listed nor readable.

Automated tests added

  • internal/web/service/logview: parsing, paging, gzip, oversized lines, symlinks, truncation during a read, the country cache, plus the FuzzParseLine fuzz test.
  • internal/web/controller/logs_test.go: routes are read-only, restricted tokens get 403, query binding, errors don't leak paths.
  • internal/xray/geodata/country_test.go: country lookup, including nested and adjacent ranges and the ends of the address space.
  • frontend/src/test/logs-page.test.tsx, logs-query.test.ts, sparkline-point-click.test.tsx.

I also removed behaviours one at a time to confirm the tests fail: 15 in the map UI and 14 in the backend.

Results

  • Go (1.27.3): golangci-lint clean, go test -shuffle=on ./... passes (53 packages), -race clean on geodata, logview and controller, fuzz smoke passes.
  • Frontend (Node 26): lint, format check, typecheck, build and build-storybook pass. npm test passes 2,078 of 2,079. The one failure, no-static-message.test.ts, is a timeout in a Linux container over a Windows bind mount; it also times out on untouched main in that setup and passes natively on Windows.
  • make gen output is clean, and the OpenAPI copies and API docs are regenerated.
  • Browser run against a real panel with the real geoip.dat and generated logs, in light and dark themes and at mobile width, with no console errors or horizontal overflow. Filtering to one country returned exactly the count the map showed.
  • Real server: installed this build from a tagged release on my fork and confirmed the Logs page works.

Not tested

  • make verify as a single command (each step was run separately), the live-Postgres job, make node-e2e, make vulncheck and the docs site's CI checks.

Screenshots / recordings

m1-overview-dark

Breaking changes

None. No database changes, no change to the default config, and the API changes only add endpoints.

Notes for reviewers

Security. Files are opened through os.Root after a filename allowlist, must be regular files, and are never read through a symlink. Nothing shells out to tail or grep.

Privacy. Countries come from the local geoip.dat. No IP address is sent to an external service.

Resource limits. Each request scans at most 64 MiB, with 4 concurrent scans and a 16 KiB limit per line. No new dependencies.

Measured with the real geoip.dat
Building the country table about 0.9 s, once
Memory held by the table about 12.5 MB, released after 10 idle minutes
Panel RSS on first load 117 MB to a 192 MB peak, about 157 MB afterwards
Lookup about 150 ns per IP
Stats scan overhead about 10%
Logs page bundle about 50 KB gzipped

Things I'd like your view on

  • Log history: the existing jobs empty the Xray logs daily and once they pass 64 MiB, so the page only covers the time since the last wipe. I left that unchanged.
  • Map borders: the shapes are Natural Earth's de facto borders, which may be sensitive for disputed regions. They can be changed by editing the data and regenerating with frontend/scripts/build-world-map.mjs; that script's dependencies are deliberately not in package.json.
  • Translations: the strings for all 14 locales were not reviewed by native speakers.
  • Sub-nodes: the page shows the local panel's logs only and does not collect logs from nodes.

Small changes to existing code. Sparkline gains optional onPointClick and rightPadding props. assetDir() now delegates to the new xray.AssetDir(), and cidrBytes in geodata/reader.go is split so the new parseCIDR can be reused.

Diff size. Of about 9,700 added lines, roughly 3,700 are source and map data. The rest is tests (2,270), generated files and OpenAPI (2,590) and translations (1,180).

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/7035 **Author:** [@ahmadi-ali](https://github.com/ahmadi-ali) **Created:** 10/31/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/logs-page` --- ### 📝 Commits (1) - [`baabc4a`](https://github.com/MHSanaei/3x-ui/commit/baabc4a2abfe2f2a60ee48df2b42b753341bb91a) feat(logs): add a read-only Logs page with charts and a country map ### 📊 Changes **61 files changed** (+9726 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `docs/architecture.md` (+2 -0) ➕ `docs/content/docs/en/reference/api/logs.mdx` (+53 -0) 📝 `docs/content/docs/en/reference/api/meta.json` (+1 -0) 📝 `docs/public/openapi.json` (+903 -0) 📝 `frontend/public/openapi.json` (+903 -0) ➕ `frontend/scripts/build-world-map.mjs` (+79 -0) ➕ `frontend/src/api/queries/useLogs.ts` (+75 -0) 📝 `frontend/src/api/queryKeys.ts` (+6 -0) 📝 `frontend/src/components/command-palette/CommandPalette.tsx` (+1 -0) 📝 `frontend/src/components/viz/Sparkline.css` (+4 -0) 📝 `frontend/src/components/viz/Sparkline.stories.tsx` (+2 -0) 📝 `frontend/src/components/viz/Sparkline.tsx` (+12 -3) 📝 `frontend/src/generated/examples.ts` (+160 -0) 📝 `frontend/src/generated/schemas.ts` (+431 -0) 📝 `frontend/src/generated/types.ts` (+91 -0) 📝 `frontend/src/generated/zod.ts` (+101 -0) ➕ `frontend/src/lib/logs/countryScale.ts` (+17 -0) ➕ `frontend/src/lib/logs/logQuery.ts` (+126 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+113 -0) ➕ `frontend/src/pages/logs/LogsFilterBar.tsx` (+173 -0) _...and 41 more files_ </details> ### 📄 Description ## Summary Adds a read-only **Logs** page to the panel (`/panel/logs`). It has an Overview tab with interactive charts and a world map of requests by country, and a raw-log tab with search and filters. All of it is served by three new `GET` endpoints that only read files inside `XUI_LOG_FOLDER`. ## Why To investigate traffic or errors today, an admin has to SSH into the server, or use the Overview log modal, which offers a line count and a text filter but no breakdowns. This page answers the common questions directly in the panel: which IPs, users and hosts are busiest, when errors spiked, and where requests come from. Clicking a chart filters the whole page down to the matching log lines. ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? **To try it** 1. Build and run the panel. In the Xray advanced config, set `"log": { "access": "/var/log/x-ui/access.log" }` (the access log is off by default and must be inside `XUI_LOG_FOLDER`), then restart Xray and send some traffic. 2. Open **Logs** in the sidebar and select `access.log`. 3. Click a country, a top-list row or a point on a chart. The page should filter, and the raw-log tab should show the same lines. 4. Check the file restrictions: `GET /panel/api/logs/read?file=../../etc/passwd` is rejected, and a symlink placed in the log folder is neither listed nor readable. **Automated tests added** - `internal/web/service/logview`: parsing, paging, gzip, oversized lines, symlinks, truncation during a read, the country cache, plus the `FuzzParseLine` fuzz test. - `internal/web/controller/logs_test.go`: routes are read-only, restricted tokens get 403, query binding, errors don't leak paths. - `internal/xray/geodata/country_test.go`: country lookup, including nested and adjacent ranges and the ends of the address space. - `frontend/src/test/logs-page.test.tsx`, `logs-query.test.ts`, `sparkline-point-click.test.tsx`. I also removed behaviours one at a time to confirm the tests fail: 15 in the map UI and 14 in the backend. **Results** - Go (1.27.3): `golangci-lint` clean, `go test -shuffle=on ./...` passes (53 packages), `-race` clean on `geodata`, `logview` and `controller`, fuzz smoke passes. - Frontend (Node 26): lint, format check, typecheck, `build` and `build-storybook` pass. `npm test` passes 2,078 of 2,079. The one failure, `no-static-message.test.ts`, is a timeout in a Linux container over a Windows bind mount; it also times out on untouched `main` in that setup and passes natively on Windows. - `make gen` output is clean, and the OpenAPI copies and API docs are regenerated. - Browser run against a real panel with the real `geoip.dat` and generated logs, in light and dark themes and at mobile width, with no console errors or horizontal overflow. Filtering to one country returned exactly the count the map showed. - Real server: installed this build from a tagged release on my fork and confirmed the Logs page works. **Not tested** - `make verify` as a single command (each step was run separately), the live-Postgres job, `make node-e2e`, `make vulncheck` and the docs site's CI checks. ## Screenshots / recordings <img width="1500" height="1914" alt="m1-overview-dark" src="https://github.com/user-attachments/assets/e08384e0-ae81-45cd-b758-21792fc4735b" /> ## Breaking changes None. No database changes, no change to the default config, and the API changes only add endpoints. ## Notes for reviewers **Security.** Files are opened through `os.Root` after a filename allowlist, must be regular files, and are never read through a symlink. Nothing shells out to `tail` or `grep`. **Privacy.** Countries come from the local `geoip.dat`. No IP address is sent to an external service. **Resource limits.** Each request scans at most 64 MiB, with 4 concurrent scans and a 16 KiB limit per line. No new dependencies. | Measured with the real `geoip.dat` | | |---|---| | Building the country table | about 0.9 s, once | | Memory held by the table | about 12.5 MB, released after 10 idle minutes | | Panel RSS on first load | 117 MB to a 192 MB peak, about 157 MB afterwards | | Lookup | about 150 ns per IP | | Stats scan overhead | about 10% | | Logs page bundle | about 50 KB gzipped | **Things I'd like your view on** - **Log history:** the existing jobs empty the Xray logs daily and once they pass 64 MiB, so the page only covers the time since the last wipe. I left that unchanged. - **Map borders:** the shapes are Natural Earth's de facto borders, which may be sensitive for disputed regions. They can be changed by editing the data and regenerating with `frontend/scripts/build-world-map.mjs`; that script's dependencies are deliberately not in `package.json`. - **Translations:** the strings for all 14 locales were not reviewed by native speakers. - **Sub-nodes:** the page shows the local panel's logs only and does not collect logs from nodes. **Small changes to existing code.** `Sparkline` gains optional `onPointClick` and `rightPadding` props. `assetDir()` now delegates to the new `xray.AssetDir()`, and `cidrBytes` in `geodata/reader.go` is split so the new `parseCIDR` can be reused. **Diff size.** Of about 9,700 added lines, roughly 3,700 are source and map data. The rest is tests (2,270), generated files and OpenAPI (2,590) and translations (1,180). ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6589
No description provided.