MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / initialiseAgent

Function initialiseAgent

agent-source-code/cmd/patchmon-agent/commands/root.go:66–95  ·  view source on GitHub ↗

initialiseAgent initialises the configuration manager and logger

()

Source from the content-addressed store, hash-verified

64
65// initialiseAgent initialises the configuration manager and logger
66func 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
98func updateLogLevel(cmd *cobra.Command) {

Callers 1

root.goFile · 0.85

Calls 3

SetConfigFileMethod · 0.80
LoadConfigMethod · 0.80
GetConfigMethod · 0.80

Tested by

no test coverage detected