Skip to content

Commit

Permalink
Avoid to crash on outputting log at the early stage config parser
Browse files Browse the repository at this point in the history
By #3352, an early stage config parser is introduced to enable setting
log rotation by system config. While this stage, the global logger
doesn't exist yet, so that it causes crash when the config parser try to
output log. This commit avoid the crash by checking $log. Same logs will
be output at the later stage so that it's not needed in the early stage.

See also: fluent/fluentd-kubernetes-daemonset#583

Signed-off-by: Takuro Ashie <ashie@clear-code.com>
  • Loading branch information
ashie committed Jul 8, 2021
1 parent c62dc31 commit f94fdb0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/fluent/config/v1_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def initialize(strscan, include_basepath, fname, eval_context)
super(strscan, eval_context)
@include_basepath = include_basepath
@fname = fname
@logger = defined?($log) ? $log : nil
end

def parse!
Expand Down Expand Up @@ -99,7 +100,7 @@ def parse_element(root_element, elem_name, attrs = {}, elems = [])

elsif root_element && skip(/(\@include|include)#{SPACING}/)
if !prev_match.start_with?('@')
$log.warn "'include' is deprecated. Use '@include' instead"
@logger.warn "'include' is deprecated. Use '@include' instead" if @logger
end
parse_include(attrs, elems)

Expand All @@ -123,7 +124,7 @@ def parse_element(root_element, elem_name, attrs = {}, elems = [])
parse_error! "'@' is the system reserved prefix. Don't use '@' prefix parameter in the configuration: #{k}"
else
# TODO: This is for backward compatibility. It will throw an error in the future.
$log.warn "'@' is the system reserved prefix. It works in the nested configuration for now but it will be rejected: #{k}"
@logger.warn "'@' is the system reserved prefix. It works in the nested configuration for now but it will be rejected: #{k}" if @logger
end
end

Expand Down

0 comments on commit f94fdb0

Please sign in to comment.