feat: Enhance log inspection and querying capabilities for test environments

This commit is contained in:
2026-07-15 16:13:46 +08:00
parent 5a926e36fc
commit 708d779533
8 changed files with 147 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
---
name: inspect-shz-logs
description: Inspect and follow the SHZ backend's local and production logs through bounded, read-only commands. Use when Codex is working in the shz-backend project and needs to diagnose startup failures, exceptions, request behavior, scheduled jobs, or runtime incidents from local backend.log or the production backend, error, info, and user logs on the shz server.
description: Inspect and follow the SHZ backend's local, test, and production logs through bounded, read-only commands. Use when Codex is working in the shz-backend project and needs to diagnose startup failures, exceptions, request behavior, scheduled jobs, or runtime incidents from local backend.log or the test and production backend, error, info, and user logs.
---
# Inspect SHZ Logs
@@ -35,7 +35,25 @@ Read the current error log:
.codex/skills/inspect-shz-logs/scripts/view.sh online error 200
```
Choose only one production log type: `backend`, `error`, `info`, or `user`. Add `--follow` as the final argument only for an explicit live-monitoring request.
`online` is the existing production-environment name and remains supported. `production` is an equivalent alias.
Choose only one log type: `backend`, `error`, `info`, or `user`. Add `--follow` as the final argument only for an explicit live-monitoring request.
## Inspect test logs
Read the main test-environment application log:
```bash
.codex/skills/inspect-shz-logs/scripts/view.sh test backend 200
```
Read the current test-environment error log:
```bash
.codex/skills/inspect-shz-logs/scripts/view.sh test error 200
```
The test environment uses the same four log types as production. The default test server is `root@47.111.103.66` on SSH port `22`; the endpoint and log directory can be overridden with `SHZ_TEST_SSH_HOST`, `SHZ_TEST_SSH_PORT`, and `SHZ_TEST_LOG_DIR` when the server layout changes.
For keyword analysis, fetch a bounded window and filter locally, for example:
@@ -45,12 +63,12 @@ For keyword analysis, fetch a bounded window and filter locally, for example:
## Diagnose from logs
1. Establish whether the request concerns local or production behavior.
1. Establish whether the request concerns local, test, or production behavior.
2. Read 100300 recent lines from the relevant log.
3. Expand up to the script's 5,000-line cap only when timestamps or stack traces require more context.
4. Correlate timestamps, thread names, exception causes, and nearby requests.
5. Report the evidence and likely cause without exposing tokens, passwords, personal data, or unrelated log content.
Treat production access as read-only. Never restart services, edit files, deploy code, truncate logs, or run arbitrary remote commands through this skill.
Treat test and production access as read-only. Never restart services, edit files, deploy code, truncate logs, or run arbitrary remote commands through this skill.
Read [references/log-locations.md](references/log-locations.md) only when checking server identity, paths, or supported log types.

View File

@@ -1,4 +1,4 @@
interface:
display_name: "查看 SHZ 项目日志"
short_description: "安全查看并跟踪 SHZ 项目的本地与线上运行日志内容"
default_prompt: "Use $inspect-shz-logs to inspect recent local or production logs for the SHZ backend."
short_description: "安全查看并跟踪 SHZ 项目的本地、测试与线上日志内容"
default_prompt: "Use $inspect-shz-logs to inspect recent local, test, or production logs for the SHZ backend."

View File

@@ -16,4 +16,17 @@
- Current info log: `/opt/service/project/shz-backend/logs/sys-info.log`
- Current user log: `/opt/service/project/shz-backend/logs/sys-user.log`
## Test: shz-test
- SSH: `root@47.111.103.66:22`
- Application: `/data/code/shz-backend/ruoyi-admin/target/ruoyi-admin.jar`
- Profile: `test`
- HTTP port: `9091`
- Main process log: `/data/code/shz-backend/logs/backend.log`
- Current error log: `/data/code/shz-backend/logs/sys-error.log`
- Current info log: `/data/code/shz-backend/logs/sys-info.log`
- Current user log: `/data/code/shz-backend/logs/sys-user.log`
The test endpoint defaults can be overridden with `SHZ_TEST_SSH_HOST`, `SHZ_TEST_SSH_PORT`, and `SHZ_TEST_LOG_DIR`.
Use only the bundled read-only viewer. Rotated files use date suffixes but are intentionally not exposed by the default script.

View File

@@ -5,20 +5,26 @@ skill_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
project_dir="$(cd "${skill_dir}/../../.." && pwd)"
local_log="${project_dir}/.local/logs/backend.log"
ssh_host="root@39.98.44.136"
ssh_port="6022"
remote_log_dir="/opt/service/project/shz-backend/logs"
online_ssh_host="${SHZ_ONLINE_SSH_HOST:-root@39.98.44.136}"
online_ssh_port="${SHZ_ONLINE_SSH_PORT:-6022}"
online_remote_log_dir="${SHZ_ONLINE_LOG_DIR:-/opt/service/project/shz-backend/logs}"
test_ssh_host="${SHZ_TEST_SSH_HOST:-root@47.111.103.66}"
test_ssh_port="${SHZ_TEST_SSH_PORT:-22}"
test_remote_log_dir="${SHZ_TEST_LOG_DIR:-/data/code/shz-backend/logs}"
usage() {
cat <<'EOF'
Usage:
view.sh local [lines] [--follow]
view.sh online [backend|error|info|user] [lines] [--follow]
view.sh online|production [backend|error|info|user] [lines] [--follow]
view.sh test [backend|error|info|user] [lines] [--follow]
Examples:
view.sh local 200
view.sh local 100 --follow
view.sh online backend 200
view.sh test error 200
view.sh online error 500 --follow
EOF
}
@@ -59,11 +65,30 @@ view_local() {
fi
}
view_online() {
local kind="${1:-backend}"
local lines="${2:-200}"
local follow="${3:-}"
local remote_file
view_remote() {
local target="$1"
local kind="${2:-backend}"
local lines="${3:-200}"
local follow="${4:-}"
local ssh_host ssh_port remote_log_dir remote_file
case "${target}" in
online|production)
ssh_host="${online_ssh_host}"
ssh_port="${online_ssh_port}"
remote_log_dir="${online_remote_log_dir}"
;;
test)
ssh_host="${test_ssh_host}"
ssh_port="${test_ssh_port}"
remote_log_dir="${test_remote_log_dir}"
;;
*)
echo "Unknown remote environment: ${target}" >&2
usage >&2
exit 2
;;
esac
case "${kind}" in
backend) remote_file="${remote_log_dir}/backend.log" ;;
@@ -71,7 +96,7 @@ view_online() {
info) remote_file="${remote_log_dir}/sys-info.log" ;;
user) remote_file="${remote_log_dir}/sys-user.log" ;;
*)
echo "Unknown online log type: ${kind}" >&2
echo "Unknown log type: ${kind}" >&2
usage >&2
exit 2
;;
@@ -80,11 +105,16 @@ view_online() {
validate_lines "${lines}"
validate_follow "${follow}"
local -a ssh_args=(-o BatchMode=yes -o ConnectTimeout=10)
if [[ -n "${ssh_port}" ]]; then
ssh_args+=(-p "${ssh_port}")
fi
if [[ "${follow}" == "--follow" ]]; then
ssh -p "${ssh_port}" -o BatchMode=yes -o ConnectTimeout=10 "${ssh_host}" \
ssh "${ssh_args[@]}" "${ssh_host}" \
tail -n "${lines}" -F -- "${remote_file}"
else
ssh -p "${ssh_port}" -o BatchMode=yes -o ConnectTimeout=10 "${ssh_host}" \
ssh "${ssh_args[@]}" "${ssh_host}" \
tail -n "${lines}" -- "${remote_file}"
fi
}
@@ -95,9 +125,9 @@ case "${target}" in
[[ $# -le 3 ]] || { usage >&2; exit 2; }
view_local "${2:-200}" "${3:-}"
;;
online)
online|production|test)
[[ $# -le 4 ]] || { usage >&2; exit 2; }
view_online "${2:-backend}" "${3:-200}" "${4:-}"
view_remote "${target}" "${2:-backend}" "${3:-200}" "${4:-}"
;;
help|-h|--help)
usage