{"record":{"id":"316fedf2cf91b728","repo":"owasp-amass/amass","slug":"failed-to-create-the-log-directory-v","errorCode":null,"errorMessage":"failed to create the log directory: %v","messagePattern":"failed to create the log directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/log.go","lineNumber":43,"sourceCode":"\t\treturn err\n\t}\n\n\tctx := context.Background()\n\tif l.Handler().Enabled(ctx, record.Level) {\n\t\treturn l.Handler().Handle(ctx, record)\n\t}\n\n\treturn errors.New(\"logger handler is not enabled\")\n}\n\nfunc NewFileLogger(dir, logfile string) (*slog.Logger, error) {\n\tif logfile == \"\" {\n\t\treturn nil, fmt.Errorf(\"no log file specified\")\n\t}\n\n\tif dir != \"\" {\n\t\tif err := os.MkdirAll(dir, 0640); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create the log directory: %v\", err)\n\t\t}\n\t}\n\n\tf, err := os.OpenFile(filepath.Join(dir, logfile), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open the log file: %v\", err)\n\t}\n\n\treturn slog.New(slog.NewJSONHandler(f, nil)), nil\n}\n\nfunc NewSyslogLogger() (*slog.Logger, error) {\n\tport := os.Getenv(\"SYSLOG_PORT\")\n\thost := strings.ToLower(os.Getenv(\"SYSLOG_HOST\"))\n\ttransport := strings.ToLower(os.Getenv(\"SYSLOG_TRANSPORT\"))\n\n\tif host == \"\" {\n\t\treturn nil, fmt.Errorf(\"no syslog host specified\")","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/internal/tools/log.go#L25-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlogger, err := tools.NewFileLogger(\"/var/log/amass\", \"amass.log\") // EACCES\n// after\nlogger, err := tools.NewFileLogger(\"/tmp/amass-logs\", \"amass.log\")","handlingStrategy":"validation","validationCode":"if dir != \"\" {\n\tif st, err := os.Stat(dir); err == nil && !st.IsDir() {\n\t\treturn fmt.Errorf(\"%s is a file, not a directory\", dir)\n\t}\n\tif err := os.MkdirAll(dir, 0750); err != nil {\n\t\treturn fmt.Errorf(\"cannot prepare log dir: %v\", err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"logger, err := tools.NewFileLogger(dir, logfile)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed to create the log directory\") {\n\t\tlogger, err = tools.NewFileLogger(\"\", logfile) // fall back to cwd\n\t}\n\tif err != nil { return err }\n}","preventionTips":["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"],"tags":["go","logging","mkdir","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}