{"record":{"id":"6aa780b77e13fcab","repo":"owasp-amass/amass","slug":"logger-handler-is-not-enabled","errorCode":null,"errorMessage":"logger handler is not enabled","messagePattern":"logger handler is not enabled","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/tools/log.go","lineNumber":33,"sourceCode":"\t\"strings\"\n\n\tafmt \"github.com/owasp-amass/amass/v5/internal/afmt\"\n\tslogcommon \"github.com/samber/slog-common\"\n\tslogsyslog \"github.com/samber/slog-syslog/v2\"\n)\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","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/internal/tools/log.go#L15-L51","documentation":"WriteLogMessage checks l.Handler().Enabled(ctx, record.Level) before dispatching a slog record. If the handler reports the level as not enabled, the message is not delivered and this error is returned instead of silently dropping the log line.","triggerScenarios":"Calling WriteLogMessage with a logger whose handler has the record's level filtered out (e.g. handler configured at LevelError while writing a Debug/Info message), or with a discarded/no-op handler.","commonSituations":"Application verbosity configured below the level used by callers (production builds with LevelWarn); using slog.DiscardHandler or a custom handler whose Enabled() returns false; writing debug logs in release binaries.","solutions":["Raise the handler's minimum level (e.g. slog.SetLogLoggerLevel or handler level option) so the message's level is enabled.","Verify the logger returned by NewFileLogger is actually installed (not a discarded handler).","Ignore the error if dropping low-level messages is intended; treat it as a signal, not a fault."],"exampleFix":"// before\nlogger := slog.New(slog.NewTextHandler(io.Discard, &slog.HandlerOptions{Level: slog.LevelError}))\ntools.WriteLogMessage(logger, slog.LevelDebug, \"msg\") // error\n// after\nlogger := slog.New(slog.NewTextHandler(w, &slog.HandlerOptions{Level: slog.LevelDebug}))\ntools.WriteLogMessage(logger, slog.LevelDebug, \"msg\")","handlingStrategy":"try-catch","validationCode":"ctx := context.Background()\nif !logger.Handler().Enabled(ctx, level) {\n    // skip or raise handler level first\n}","typeGuard":null,"tryCatchPattern":"if err := tools.WriteLogMessage(logger, level, msg); err != nil {\n    if err.Error() == \"logger handler is not enabled\" {\n        // drop or buffer the message; optionally log to stderr\n    }\n}","preventionTips":["Align the handler's minimum level with every level the code emits.","Don't install discard handlers in paths that must log.","Test logging setup at application startup with one message per level."],"tags":["logging","slog","go"],"backgroundTag":"logging-level-disabled","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"}