owasp-amass/amass · warning
logger handler is not enabled
Error message
logger handler is not enabled
What it means
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.
Source
Thrown at internal/tools/log.go:33
"strings"
afmt "github.com/owasp-amass/amass/v5/internal/afmt"
slogcommon "github.com/samber/slog-common"
slogsyslog "github.com/samber/slog-syslog/v2"
)
func WriteLogMessage(l *slog.Logger, message string) error {
record, err := afmt.JSONLogToRecord(message)
if err != nil {
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)
}
View on GitHub (pinned to 79299dce87)
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.
Example fix
// before
logger := slog.New(slog.NewTextHandler(io.Discard, &slog.HandlerOptions{Level: slog.LevelError}))
tools.WriteLogMessage(logger, slog.LevelDebug, "msg") // error
// after
logger := slog.New(slog.NewTextHandler(w, &slog.HandlerOptions{Level: slog.LevelDebug}))
tools.WriteLogMessage(logger, slog.LevelDebug, "msg") Defensive patterns
Strategy: try-catch
Validate before calling
ctx := context.Background()
if !logger.Handler().Enabled(ctx, level) {
// skip or raise handler level first
} Try / catch
if err := tools.WriteLogMessage(logger, level, msg); err != nil {
if err.Error() == "logger handler is not enabled" {
// drop or buffer the message; optionally log to stderr
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- no log file specified
- failed to create the log directory: %v
- failed to open the log file: %v
- no syslog host specified
- failed to cast the DomainRecord
AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06).
Data as JSON: /api/errors/6aa780b77e13fcab.
Report an issue: GitHub.