Fixed issue with initializing logs

This commit is contained in:
tyler 2023-12-26 11:30:29 -05:00
parent 3592349fd3
commit c04850fa6c
2 changed files with 16 additions and 9 deletions

7
app.go
View file

@ -57,12 +57,7 @@ func (a *App) startup(ctx context.Context) {
}
func (a *App) initLog() error {
fp, err := config.LogFile()
if err != nil {
return fmt.Errorf("error getting filepath for log file: %v", err)
}
f, err := os.OpenFile(fp, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
f, err := config.LogFile()
if err != nil {
return fmt.Errorf("error opening log file: %v", err)
}

View file

@ -21,13 +21,25 @@ const (
logFile = "logs.txt"
)
func LogFile() (string, error) {
func LogFile() (*os.File, error) {
dir, err := buildConfigDir()
if err != nil {
return "", fmt.Errorf("config: error getting config directory: %v", err)
return nil, fmt.Errorf("config: error getting config directory: %v", err)
}
return filepath.Join(dir, logFile), nil
err = os.MkdirAll(dir, 0750)
if err != nil {
return nil, fmt.Errorf("config: error making config directory: %v", err)
}
fp := filepath.Join(dir, logFile)
f, err := os.OpenFile(fp, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
return nil, fmt.Errorf("config: error opening log file: %v", err)
}
return f, nil
}
func buildConfigDir() (string, error) {