flipped-aurora/gin-vue-admin · error
日志文件不可读取
Error message
日志文件不可读取
What it means
ErrLogFileUnreadable is a sentinel error of the log viewer service indicating that a log file exists and passed path validation but could not be opened or read (e.g. permission denied or I/O error). It is returned by failLogViewerRequest, ReadContent, and openValidatedLogFile when os.Open/Read fails for a reason other than the file being missing.
Source
Thrown at server/service/system/sys_log_viewer.go:33
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
systemRes "github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
)
const (
DefaultLogChunkLines = 500
MaxLogChunkBytes = 2 * 1024 * 1024
logReadBlockSize = 64 * 1024
)
var (
ErrInvalidLogMonth = errors.New("日志月份格式不正确")
ErrInvalidLogDate = errors.New("日志日期格式不正确")
ErrInvalidLogPath = errors.New("日志文件路径不合法")
ErrLogFileNotFound = errors.New("日志文件不存在")
ErrLogFileUnreadable = errors.New("日志文件不可读取")
ErrLogRootUnavailable = errors.New("日志目录不可读取")
)
type LogViewerService struct{}
func (s *LogViewerService) ListDates(ctx context.Context, month string) (result systemRes.LogDateList, err error) {
result = systemRes.LogDateList{Month: month, Dates: make([]systemRes.LogDateItem, 0)}
if err = validateLogMonth(month); err != nil {
return result, err
}
logRoot, exists, err := openConfiguredLogRoot()
if err != nil {
return result, err
}
if !exists {
return result, nil
}View on GitHub (pinned to 3136500ef3)
Solutions
- Check the file permissions of files under the configured log directory (ls -l) and ensure the process user can read them (chmod/chown as needed).
- Confirm the server process user actually owns or has group access to the log directory and rotation-created files.
- Check container/SELinux context if running in Docker or with enforcing policies.
- Inspect server logs for the underlying os error returned alongside the sentinel to identify the exact cause.
Example fix
// before (root-owned rotated log, unreadable by app user) // -rw------- 1 root root app-2026-08-31.log // after // chown appuser:appuser app-2026-08-31.log // chmod 0640 app-2026-08-31.log
Defensive patterns
Strategy: fallback
Validate before calling
const stat = await fs.promises.stat(filePath).catch(() => null)
if (!stat || !stat.isFile()) throw new Error('log file not found')
await fs.promises.access(filePath, fs.constants.R_OK) // throws EACCES early if unreadable Try / catch
try {
await api.readLogContent({ month, date, fileName })
} catch (e) {
if (e.msg === '日志文件不可读取') {
// surface file-permission hint and fall back to server-side log tail via ops
} else throw e
} Prevention
- Run the server with a user that owns or has group-read on the log directory.
- Configure log rotation to preserve readable modes (e.g. 0640 with a shared group).
- Add a startup health check that opens a known log file to catch permission drift early.
When it happens
Trigger: Calling ReadContent for a log file whose path passes validation (correct month/date format, stays inside the log root) but the file cannot be opened: file mode disallows read for the running user, or an I/O error occurs during read. Returned via failLogViewerRequest for the API response.
Common situations: Log files written by root or another user while the gin-vue-admin server runs under a lower-privileged account; files with 0600 permissions after log rotation; disk/IO errors; SELinux or container volume mount permission restrictions on the log directory.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/9eee6ab0d4a1b64d.
Report an issue: GitHub.