feat(cli): add -v debug flags to trace file writes and env path creations during deployment

This commit is contained in:
2026-03-24 17:16:58 +08:00
parent b1c7b9f8f7
commit 35bf24f0f3
3 changed files with 31 additions and 7 deletions

View File

@@ -3,11 +3,10 @@ package daemon
import (
"context"
"github.com/kardianos/service"
"smart-shutdown/pkg/config"
"smart-shutdown/pkg/logger"
"smart-shutdown/pkg/monitor"
"github.com/kardianos/service"
)
type program struct {
@@ -41,13 +40,17 @@ func (p *program) Stop(s service.Service) error {
return nil
}
func GetService(cfg *config.Config) (service.Service, error) {
func GetService(cfg *config.Config, execPath ...string) (service.Service, error) {
svcConfig := &service.Config{
Name: "SmartNetworkMonitor",
DisplayName: "Smart Network Shutdown Monitor",
Description: "A reliable daemon that periodically monitors network states and triggers node suspension logically.",
}
if len(execPath) > 0 && execPath[0] != "" {
svcConfig.Executable = execPath[0]
}
prg := &program{
cfg: cfg,
}

View File

@@ -12,6 +12,7 @@ import (
)
var fileLogger *lumberjack.Logger
var debugEnabled bool
func InitLogger() error {
logDir := config.GetLogDir()
@@ -33,6 +34,10 @@ func InitLogger() error {
return nil
}
func EnableDebug() {
debugEnabled = true
}
func writeLog(level, plainPrefix, format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...)
timestamp := time.Now().Format("2006/01/02 15:04:05")
@@ -63,11 +68,19 @@ func getPrefixColor(level string) func(a ...interface{}) string {
return color.New(color.FgRed).SprintFunc()
case "CRITICAL":
return color.New(color.FgHiRed).SprintFunc()
case "DEBUG":
return color.New(color.FgCyan).SprintFunc()
default:
return color.New(color.Reset).SprintFunc()
}
}
func Debug(format string, v ...interface{}) {
if debugEnabled {
writeLog("DEBUG", "[DEBUG]", format, v...)
}
}
func Info(format string, v ...interface{}) {
writeLog("INFO", "[INFO]", format, v...)
}