Fixed issue with initializing logs
This commit is contained in:
parent
3592349fd3
commit
c04850fa6c
7
app.go
7
app.go
|
@ -57,12 +57,7 @@ func (a *App) startup(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) initLog() error {
|
func (a *App) initLog() error {
|
||||||
fp, err := config.LogFile()
|
f, 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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error opening log file: %v", err)
|
return fmt.Errorf("error opening log file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,25 @@ const (
|
||||||
logFile = "logs.txt"
|
logFile = "logs.txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LogFile() (string, error) {
|
func LogFile() (*os.File, error) {
|
||||||
dir, err := buildConfigDir()
|
dir, err := buildConfigDir()
|
||||||
if err != nil {
|
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) {
|
func buildConfigDir() (string, error) {
|
||||||
|
|
Loading…
Reference in a new issue