{"record":{"id":"166a48a5cd43b7b4","repo":"owasp-amass/amass","slug":"no-log-file-specified","errorCode":null,"errorMessage":"no log file specified","messagePattern":"no log file specified","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/log.go","lineNumber":38,"sourceCode":")\n\nfunc WriteLogMessage(l *slog.Logger, message string) error {\n\trecord, err := afmt.JSONLogToRecord(message)\n\tif err != nil {\n\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\")","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/internal/tools/log.go#L20-L56","documentation":"NewFileLogger builds a JSON slog.Logger writing to a file. This error is returned when the logfile argument is an empty string, indicating the caller did not select a log file even though the file logger was chosen.","triggerScenarios":"Calling NewFileLogger(dir, \"\") directly, or the CLI/config resolves to file logging (via selectLogger) with an empty log-file setting (e.g. -logfile flag not provided).","commonSituations":"Configuring the logger type as \"file\" but forgetting the log file path; an empty environment variable or config key feeding logfile; a refactor that dropped the default log file name.","solutions":["Provide a non-empty logfile name, e.g. NewFileLogger(dir, \"amass.log\")","Set the log file path in the config file or pass the corresponding CLI flag","Verify the variable feeding the logfile argument is populated (print/inspect before the call)","Fall back to a sensible default filename when logfile is empty at the call site"],"exampleFix":"// before\nlogger, err := tools.NewFileLogger(dir, logfile) // logfile == \"\"\n// after\nif logfile == \"\" {\n\tlogfile = \"amass.log\"\n}\nlogger, err := tools.NewFileLogger(dir, logfile)","handlingStrategy":"validation","validationCode":"if logfile == \"\" {\n\treturn errors.New(\"file logging selected but no log file name provided\")\n}","typeGuard":null,"tryCatchPattern":"logger, err := tools.NewFileLogger(dir, logfile)\nif err != nil && strings.Contains(err.Error(), \"no log file specified\") {\n\tlogger, err = tools.NewFileLogger(dir, \"default.log\")\n}","preventionTips":["Make the log-file flag required when --log-type=file, failing fast at flag parsing","Provide a default log file name in the CLI layer","Validate that env/config keys feeding logfile are non-empty before calling","Add a unit test asserting NewFileLogger rejects empty names"],"tags":["go","logging","validation","arguments"],"backgroundTag":"missing-required-argument","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"}