Skip to content

Commit 39387df

Browse files
committed
Added method to directly get logs dir
1 parent 46ff1ea commit 39387df

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ func getDataDir() *paths.Path {
3636
return dataDir
3737
}
3838

39+
// getLogsDir return the directory where logs are saved
40+
func getLogsDir() *paths.Path {
41+
logsDir := getDataDir().Join("logs")
42+
if err := logsDir.MkdirAll(); err != nil {
43+
log.Panicf("Can't create logs dir: %s", err)
44+
}
45+
return logsDir
46+
}
47+
3948
// getDefaultConfigDir returns the full path to the default Arduino Create Agent configuration directory.
4049
func getDefaultConfigDir() *paths.Path {
4150
// UserConfigDir returns the default root directory to use

main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,7 @@ func loop() {
343343
if *crashreport {
344344
logFilename := "crashreport_" + time.Now().Format("20060102150405") + ".log"
345345
// handle logs directory creation
346-
logsDir := agentDir.Join("logs")
347-
if logsDir.NotExist() {
348-
logsDir.Mkdir()
349-
}
346+
logsDir := getLogsDir()
350347
logFile, err := os.OpenFile(logsDir.Join(logFilename).String(), os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0644)
351348
if err != nil {
352349
log.Print("Cannot create file used for crash-report")

0 commit comments

Comments
 (0)