Skip to content

Commit

Permalink
create the log file along with its parent directory if not present
Browse files Browse the repository at this point in the history
  • Loading branch information
bharath-123 committed Jul 31, 2023
1 parent db450f5 commit 8e84507
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion io/logs/logutil.go
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/prysmaticlabs/prysm/v4/config/params"
Expand All @@ -20,7 +21,10 @@ func addLogWriter(w io.Writer) {
// ConfigurePersistentLogging adds a log-to-file writer. File content is identical to stdout.
func ConfigurePersistentLogging(logFileName string) error {
logrus.WithField("logFileName", logFileName).Info("Logs will be made persistent")
f, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, params.BeaconIoConfig().ReadWritePermissions) // #nosec G304
if err := os.MkdirAll(filepath.Dir(logFileName), 0755); err != nil {
return err
}
f, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, params.BeaconIoConfig().ReadWriteExecutePermissions) // #nosec G304
if err != nil {
return err
}
Expand Down

0 comments on commit 8e84507

Please sign in to comment.