Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logger initialization #4091

Merged
merged 9 commits into from
Mar 16, 2023
Merged

Conversation

daipom
Copy link
Contributor

@daipom daipom commented Mar 12, 2023

Which issue(s) this PR fixes:

What this PR does / why we need it:
This fix prevents the logger from outputting some initial log messages with some settings not applied, such as format. (Please see #4037).

In addition, the logic of initializing the logger is so difficult and has caused many bugs.
This fix simplifies it.

This fix consists of the following points.

  • All logger parameters are now set in the first initialization.
    • Previously, only parameters related to rotation were applied first, but it is preferable to apply all parameters on that point.
  • Remove LoggerInitializer
    • This class was a source of confusion because its role is difficult to understand.
  • Reflect this fix in tests.

Docs Changes:
Not needed.

Release Note:
Fix bug that the logger outputs some initial log messages with some settings not applied, such as format.

Additional Context

Currently, there is a bug in overwriting of build_system_config().
It must prefer the options explicitly specified in the command line.

So --log-rotate-age and --log-rotate-size should be merged into system_config in build_system_config()

def build_system_config(conf)
system_config = SystemConfig.create(conf, @cl_opt[:strict_config_value])
# Prefer the options explicitly specified in the command line
opt = {}
Fluent::SystemConfig::SYSTEM_CONFIG_PARAMETERS.each do |param|
if @cl_opt.key?(param) && !@cl_opt[param].nil?
opt[param] = @cl_opt[param]
end
end
system_config.overwrite_variables(**opt)
system_config
end

However, the log options in log directives are not in Fluent::SystemConfig::SYSTEM_CONFIG_PARAMETERS, so --rotate_age and --rotate_size are not merged into system_config.

So I have no choice but to give special treatment to the rotation parameters.
(I left comments for now)

@ashie ashie self-requested a review March 13, 2023 05:03
@ashie
Copy link
Member

ashie commented Mar 14, 2023

Basically it looks good to me. I'm still checking details.

@daipom
Copy link
Contributor Author

daipom commented Mar 14, 2023

Thanks!

Comment on lines 236 to 239
def reopen!
@logger.reopen! if @logger
@out.reopen(@path, "a") if @path && @path != "-"
nil
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daipom
Copy link
Contributor Author

daipom commented Mar 14, 2023

I'll rebase this to apply

lib/fluent/log.rb Outdated Show resolved Hide resolved
@daipom
Copy link
Contributor Author

daipom commented Mar 14, 2023

All tests on Windows succeed!! Yay!!
(Excluding with Ruby head)

The logic of initializing logger is so difficult and has caused
many bugs.

This fix simplifies it and prevents logger from outputting some
initial log messages with some settings not applied, such as
`format`.

This fix consists of the following 2 points.

* All logger parameters are now set in the first initialization.
  * Previously, only parameters related to rotation were applied
    first, but it is preferable to apply all parameters on that
    point.
* Remove LoggerInitializer
  * This class was a source of confusion because its role is
    difficult to understand.

TODO: Fix tests.

Signed-off-by: Daijiro Fukuda <[email protected]>
The previous one was almost testing nothing.

Signed-off-by: Daijiro Fukuda <[email protected]>
Signed-off-by: Daijiro Fukuda <[email protected]>
* Overwritten `DamonLogger#level=` is not used now, since Fluentd
  doesn't use ServerEngine's reloading feature.
* The parameters about rotate is in `Fluent::LogDeviceIO`, not in
  `ServerEngine::DaemonLogger`.

Signed-off-by: Daijiro Fukuda <[email protected]>
This test should be fixed more..., but it should be done in
another branch.

Currently, `TestSystemConfig` tests some Supervisor logic too.
This is not good, and it should be moved to SupervisorTest.
We should remove `FakeSupervisor` class.

Signed-off-by: Daijiro Fukuda <[email protected]>
Just add `sub_test_case "init logger"`.
Other all diff is re-indent.

Signed-off-by: Daijiro Fukuda <[email protected]>
Removed `rotate`, `rotate to max age` tests since
`LogTest::test_log_rotates_specified_size_with_logdevio` already
exists.

Signed-off-by: Daijiro Fukuda <[email protected]>
@ashie ashie added this to the v1.16.0 milestone Mar 15, 2023
Copy link
Member

@ashie ashie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ashie ashie merged commit d5df992 into fluent:master Mar 16, 2023
@ashie
Copy link
Member

ashie commented Mar 16, 2023

Thanks!

@daipom daipom deleted the fix-logger-initialization branch March 16, 2023 08:12
@daipom
Copy link
Contributor Author

daipom commented Mar 16, 2023

Thanks for your review!

daipom added a commit to daipom/fluentd that referenced this pull request May 29, 2023
Fix a bug of f8b73a5 (fluent#4091).

Before that fix, Fluentd can start if rotation is enabled but the log file path
is not specified.
After that fix, the logger setup starts to fail on Windows.

This fix solves it.

Signed-off-by: Daijiro Fukuda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants