From 2020531d98032332cae07f1f8db76efe39413958 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Thu, 2 May 2024 16:03:51 +0900 Subject: [PATCH] config: yaml_parser: Handle $log_level element for special case Backported from 236d87d07fea8b3396f33985247c96ad59911f3e. --- This is because `@log_level` is invalid for YAML. Instead, we should interpret $log_level as `@log_level` on YAML parser. Signed-off-by: Hiroshi Hatake --- lib/fluent/config/yaml_parser/parser.rb | 4 ++++ test/test_config.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/fluent/config/yaml_parser/parser.rb b/lib/fluent/config/yaml_parser/parser.rb index dc1caaf46d..862f774802 100644 --- a/lib/fluent/config/yaml_parser/parser.rb +++ b/lib/fluent/config/yaml_parser/parser.rb @@ -138,6 +138,10 @@ def section_build(name, config, indent: 0, arg: nil) sb.add_line('@id', v) end + if (v = config.delete('$log_level')) + sb.add_line('@log_level', v) + end + config.each do |key, val| if val.is_a?(Array) val.each do |v| diff --git a/test/test_config.rb b/test/test_config.rb index 24f63830d4..7533e6e16b 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -167,6 +167,7 @@ def test_included tag: tag.dummy - source: $type: tcp + $log_level: info tag: tag.tcp parse: $arg: @@ -176,6 +177,7 @@ def test_included - match: $tag: tag.* $type: stdout + $log_level: debug buffer: $type: memory flush_interval: 1s @@ -208,10 +210,12 @@ def test_included 'tag.dummy', 'tcp', 'tag.tcp', + 'info', 'none', 'why.parse.section.doesnot.have.arg,huh', 'stdout', 'tag.*', + 'debug', 'null', '**', '@FLUENT_LOG', @@ -224,10 +228,12 @@ def test_included dummy_source_conf['tag'], tcp_source_conf['@type'], tcp_source_conf['tag'], + tcp_source_conf['@log_level'], parse_tcp_conf['@type'], parse_tcp_conf.arg, match_conf['@type'], match_conf.arg, + match_conf['@log_level'], fluent_log_conf['@type'], fluent_log_conf.arg, label_conf.arg,