owasp-amass/amass · error
failed to create the log directory: %v
Error message
failed to create the log directory: %v
What it means
NewFileLogger creates the log directory with os.MkdirAll (mode 0640) when dir is non-empty. This error wraps MkdirAll failing, so the log directory could not be created — permissions, a non-directory in the path, or an invalid path.
Source
Thrown at internal/tools/log.go:43
return err
}
ctx := context.Background()
if l.Handler().Enabled(ctx, record.Level) {
return l.Handler().Handle(ctx, record)
}
return errors.New("logger handler is not enabled")
}
func NewFileLogger(dir, logfile string) (*slog.Logger, error) {
if logfile == "" {
return nil, fmt.Errorf("no log file specified")
}
if dir != "" {
if err := os.MkdirAll(dir, 0640); err != nil {
return nil, fmt.Errorf("failed to create the log directory: %v", err)
}
}
f, err := os.OpenFile(filepath.Join(dir, logfile), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, fmt.Errorf("failed to open the log file: %v", err)
}
return slog.New(slog.NewJSONHandler(f, nil)), nil
}
func NewSyslogLogger() (*slog.Logger, error) {
port := os.Getenv("SYSLOG_PORT")
host := strings.ToLower(os.Getenv("SYSLOG_HOST"))
transport := strings.ToLower(os.Getenv("SYSLOG_TRANSPORT"))
if host == "" {
return nil, fmt.Errorf("no syslog host specified")View on GitHub (pinned to 79299dce87)
Solutions
- Pre-create the directory with correct ownership (mkdir -p <dir> && chown) or choose a writable location such as /tmp or $HOME
- Verify each path component is a directory (ls -ld) and remove any blocking file
- Check the mount is not read-only (mount output) and disk space is available
- Pass an empty dir to write the log file relative to the current directory if a directory is not required
Example fix
// before
logger, err := tools.NewFileLogger("/var/log/amass", "amass.log") // EACCES
// after
logger, err := tools.NewFileLogger("/tmp/amass-logs", "amass.log") Defensive patterns
Strategy: validation
Validate before calling
if dir != "" {
if st, err := os.Stat(dir); err == nil && !st.IsDir() {
return fmt.Errorf("%s is a file, not a directory", dir)
}
if err := os.MkdirAll(dir, 0750); err != nil {
return fmt.Errorf("cannot prepare log dir: %v", err)
}
} Try / catch
logger, err := tools.NewFileLogger(dir, logfile)
if err != nil {
if strings.Contains(err.Error(), "failed to create the log directory") {
logger, err = tools.NewFileLogger("", logfile) // fall back to cwd
}
if err != nil { return err }
} Prevention
- Use user-writable locations ($HOME, /tmp) for log directories in containers
- Pre-create log directories in Dockerfile/entrypoint with correct ownership
- Avoid mounting log volumes read-only unless an alternative dir is configured
- Verify each path component of dir is not an existing regular file
When it happens
Trigger: Calling NewFileLogger with a dir whose parent is unwritable, a path component that is a regular file, a read-only filesystem, or dir containing invalid characters for the platform.
Common situations: LOG_DIR pointing to /var/log/foo without root or membership in the adm group; container volumes mounted read-only; a file named like the intended directory left behind by earlier tooling.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- mkdir failed for %s: %v
- failed to open the log file: %v
- logger handler is not enabled
- failed to set permissions to 0755 for %s: %v
- failed to create the output file %s: %v
AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06).
Data as JSON: /api/errors/316fedf2cf91b728.
Report an issue: GitHub.