mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-23 01:27:13 +02:00
feat: enhance logging in service commands with consistent logger usage
- Add entry/exit logging to all ServiceCommand methods (start, stop, status, reload, restart, uninstall) - Replace mainLog.Load() calls with consistent logger variable usage throughout - Capitalize all logging messages for better readability - Add error context logging for service manager initialization failures - Add debug logging for key operations (restart sequence, cleanup, validation) - Improve error handling with proper error context in all service commands - Add completion logging to track command execution flow This improves debugging capabilities and provides better operational visibility for service management operations while maintaining clean user-facing messages.
This commit is contained in:
@@ -9,25 +9,33 @@ import (
|
||||
|
||||
// Status implements the logic from cmdStatus.Run
|
||||
func (sc *ServiceCommand) Status(cmd *cobra.Command, args []string) error {
|
||||
logger := mainLog.Load()
|
||||
logger.Debug().Msg("Service status command started")
|
||||
|
||||
s, _, err := sc.initializeServiceManager()
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("Failed to initialize service manager")
|
||||
return err
|
||||
}
|
||||
|
||||
status, err := s.Status()
|
||||
if err != nil {
|
||||
mainLog.Load().Error().Msg(err.Error())
|
||||
logger.Error().Msg(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
switch status {
|
||||
case service.StatusUnknown:
|
||||
mainLog.Load().Notice().Msg("Unknown status")
|
||||
logger.Notice().Msg("Unknown status")
|
||||
os.Exit(2)
|
||||
case service.StatusRunning:
|
||||
mainLog.Load().Notice().Msg("Service is running")
|
||||
logger.Notice().Msg("Service is running")
|
||||
os.Exit(0)
|
||||
case service.StatusStopped:
|
||||
mainLog.Load().Notice().Msg("Service is stopped")
|
||||
logger.Notice().Msg("Service is stopped")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger.Debug().Msg("Service status command completed")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user