fluent/fluentd · error · Fluent::ConfigError
format should be Regexp, need //, in #{key}: '#{format}'
Error message
format should be Regexp, need //, in #{key}: '#{format}' What it means
MultilineParser#check_format_regexp (lib/fluent/plugin/parser_multiline.rb:147) requires every formatN and format_firstline value to be a Ruby regexp literal wrapped in slashes; anything else raises Fluent::ConfigError. The parser strips the first and last characters and compiles the middle, so an unslashed pattern (which may even be valid text) is treated as malformed input rather than a regex.
Source
Thrown at lib/fluent/plugin/parser_multiline.rb:147
def check_format_range(conf)
invalid_formats = conf.keys.select { |k|
m = k.match(/^format(\d+)$/)
m ? !((1..FORMAT_MAX_NUM).include?(m[1].to_i)) : false
}
unless invalid_formats.empty?
raise Fluent::ConfigError, "Invalid formatN found. N should be 1 - #{FORMAT_MAX_NUM}: " + invalid_formats.join(",")
end
end
def check_format_regexp(format, key)
if format[0] == '/' && format[-1] == '/'
begin
Regexp.new(format[1..-2], Regexp::MULTILINE)
rescue => e
raise Fluent::ConfigError, "Invalid regexp in #{key}: #{e}"
end
else
raise Fluent::ConfigError, "format should be Regexp, need //, in #{key}: '#{format}'"
end
end
end
end
end
View on GitHub (pinned to dd45c6e18d)
Solutions
- Wrap each formatN / format_firstline value in '/.../', e.g. format1 /^\\d{4}-/.
- Trim stray whitespace after the closing slash.
- Run fluentd --dry-run to verify before restart.
Example fix
# before
format1 ^\d{4}-\d{2}-\d{2}
# after
format1 /^\d{4}-\d{2}-\d{2}/ Defensive patterns
Strategy: validation
Validate before calling
conf.each do |k, v|
next unless k.start_with?('format') || k == 'format_firstline'
abort "#{k} lacks // delimiters" unless v.start_with?('/') && v.end_with?('/')
end Type guard
def slashed_regexp_literal?(s)
s.is_a?(String) && s.length >= 2 && s.start_with?('/') && s.end_with?('/')
end Prevention
- Always author format values as '/.../' literals.
- Trim whitespace around the value so the final char really is '/'.
- Include delimiter checks in config linters.
When it happens
Trigger: format1 ^\d{4}- (pattern without surrounding '/'); format_firstline ^\[\d{4}\]; quoting a plain string like format1 '[INFO]'; trailing whitespace after the closing slash leaving the last char as a space.
Common situations: Users pasting raw patterns from docs into fluent.conf; transitioning from v0 formats where some directives accepted bare strings; configs where the trailing '/' was dropped during YAML-to-v1 conversion or templating.
Related errors
- Invalid regexp '#{formats}': #{e}
- Jump of format index found. format#{i - 1} is missing.
- Invalid formatN found. N should be 1 - #{FORMAT_MAX_NUM}: #{
- Invalid regexp in #{key}: #{e}
- unknown value conversion for key:'#{field_name}', type:'#{ty
AI-assisted analysis of fluent/fluentd@dd45c6e18d (2026-08-21).
Data as JSON: /api/errors/0b07433843952617.
Report an issue: GitHub.