package runtimelogs import ( "os" "path/filepath" "strings" ) // Config holds runtime log filesystem settings. type Config struct { // RootDir is the absolute path to runtime log files (empty disables FS API). RootDir string // ServiceName is EVOBGP_SERVICE (must be evobgp-all when set). ServiceName string } // ConfigFromEnv builds Config from EVOBGP_RUNTIME_LOGS_DIR and EVOBGP_SERVICE. func ConfigFromEnv() Config { root := strings.TrimSpace(os.Getenv("EVOBGP_RUNTIME_LOGS_DIR")) if root != "" { if abs, err := filepath.Abs(root); err == nil { root = abs } } svc := strings.TrimSpace(os.Getenv("EVOBGP_SERVICE")) return Config{RootDir: root, ServiceName: svc} } // Enabled reports whether runtime log FS operations are allowed in this process. func (c Config) Enabled() bool { if c.RootDir == "" || c.ServiceName != ServiceNameAll { return false } st, err := os.Stat(c.RootDir) return err == nil && st.IsDir() }