initialiseAgent initialises the configuration manager and logger
()
| 64 | |
| 65 | // initialiseAgent initialises the configuration manager and logger |
| 66 | func initialiseAgent() { |
| 67 | // Initialise logger |
| 68 | logger = logrus.New() |
| 69 | // Get timezone for log timestamps |
| 70 | // Note: logrus TextFormatter doesn't directly support timezone |
| 71 | // The timestamp will use the system timezone, but we can configure |
| 72 | // the TZ environment variable to control this |
| 73 | tzLoc := utils.GetTimezoneLocation() |
| 74 | logger.SetFormatter(&logrus.TextFormatter{ |
| 75 | DisableTimestamp: false, |
| 76 | FullTimestamp: true, |
| 77 | TimestampFormat: "2006-01-02T15:04:05", |
| 78 | }) |
| 79 | // Store timezone location for future use if needed |
| 80 | _ = tzLoc |
| 81 | |
| 82 | // Initialise configuration manager |
| 83 | cfgManager = config.New() |
| 84 | cfgManager.SetConfigFile(configFile) |
| 85 | |
| 86 | // Load config early to determine log file path |
| 87 | _ = cfgManager.LoadConfig() |
| 88 | logFile := cfgManager.GetConfig().LogFile |
| 89 | if logFile == "" { |
| 90 | logFile = config.DefaultLogFilePath() |
| 91 | } |
| 92 | // SECURITY: Use 0750 for log directory (no world access) |
| 93 | _ = os.MkdirAll(filepath.Dir(logFile), 0750) |
| 94 | logger.SetOutput(&lumberjack.Logger{Filename: logFile, MaxSize: 10, MaxBackups: 5, MaxAge: 14, Compress: true}) |
| 95 | } |
| 96 | |
| 97 | // updateLogLevel sets the logger level based on the flag value |
| 98 | func updateLogLevel(cmd *cobra.Command) { |
no test coverage detected