flipped-aurora/gin-vue-admin · error

日志目录不可读取

Error message

日志目录不可读取

What it means

ErrLogRootUnavailable is a sentinel error of the log viewer service meaning the configured log root directory itself cannot be opened, read, or stat'ed. It is returned by ListDates, ListFiles, configuredLogRoot, openConfiguredLogRoot, and countLogFiles, so virtually every log viewer listing operation fails when the root is inaccessible.

Source

Thrown at server/service/system/sys_log_viewer.go:34

	"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
	}
	defer logRoot.Close()

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Verify the log directory path in your config (system log settings) actually exists on disk and create it if missing (mkdir -p).
  2. Ensure the server process user has r+x on the directory (chmod/chown).
  3. If in Docker/K8s, confirm the log volume is mounted at the configured path.
  4. Re-run the operation after fixing; check server logs for the wrapped os error for the exact cause.

Example fix

// config.yaml (before)
// log-dir: /data/app/logs   # directory does not exist
// after
// sudo mkdir -p /data/app/logs
// sudo chown appuser:appuser /data/app/logs
Defensive patterns

Strategy: validation

Validate before calling

const cfg = require('./config.yaml').system.logDir
if (!fs.existsSync(cfg) || !fs.statSync(cfg).isDirectory()) {
  fs.mkdirSync(cfg, { recursive: true })
}
fs.accessSync(cfg, fs.constants.R_OK | fs.constants.X_OK)

Try / catch

try {
  const dates = await api.getLogDates(month)
} catch (e) {
  if (e.msg === '日志目录不可读取') {
    notifyOps('log root missing/unreadable — check config path and mount')
  } else throw e
}

Prevention

When it happens

Trigger: Any log viewer API call (list months/dates/files or read a file) when the directory configured as the log root does not exist, is not a directory, or the process lacks read/execute permission on it; countLogFiles also surfaces it when the root cannot be read during counting.

Common situations: Misconfigured log path in config.yaml pointing to a missing directory; logs directory deleted by cleanup scripts; wrong volume mount in containers; permission changes after deployment or user switch; running in Docker where the log dir was never mounted.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/ea708037e47961ed. Report an issue: GitHub.