Skip to content

Let php-fpm -tt dump info regardless of log_level #13256

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

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from

Conversation

dzuelke
Copy link
Contributor

@dzuelke dzuelke commented Jan 26, 2024

When using php-fpm -tt to dump the configuration, and the input config has a log_level of warning or error, then nothing will be printed.

This change temporarily changes the zlog level to notice, if necessary, to allow the output to be printed.

Notably, the "configuration file %s test is successful" output is not affected by this; it still obeys the configured log_level. That behavior can't be tested, however, as tester.inc's log helpers do not actually seem to work with the "invert" flag passed in.

Current behavior with log_level = notice:

$ php-fpm … -tt:
[26-Jan-2024 19:03:06] NOTICE: [global]
[26-Jan-2024 19:03:06] NOTICE: 	pid = …

[26-Jan-2024 19:03:06] NOTICE: 	log_level = NOTICE

[26-Jan-2024 19:03:06] NOTICE:  
[26-Jan-2024 19:03:06] NOTICE: [www]
[26-Jan-2024 19:03:06] NOTICE: 	prefix = undefined

[26-Jan-2024 19:03:06] NOTICE:  
[26-Jan-2024 19:03:06] NOTICE: configuration file … test is successful

Current behavior with log_level = warning:

$ php-fpm … -tt:

New behavior with log_level = warning:

$ php-fpm … -tt:
[26-Jan-2024 19:03:06] NOTICE: [global]
[26-Jan-2024 19:03:06] NOTICE: 	pid = …

[26-Jan-2024 19:03:06] NOTICE: 	log_level = WARNING

[26-Jan-2024 19:03:06] NOTICE:  
[26-Jan-2024 19:03:06] NOTICE: [www]
[26-Jan-2024 19:03:06] NOTICE: 	prefix = undefined

[26-Jan-2024 19:03:06] NOTICE:  
When using `php-fpm -tt` to dump the configuration, and the input config has a `log_level` of warning or error, then nothing will be printed.

This change temporarily changes the `zlog` level to notice, if necessary, to allow the output to be printed.

Notably, the "configuration file %s test is successful" output is not affected by this; it still obeys the configured `log_level`.

Can't be tested, however, as `tester.inc`'s log helpers do not actually seem to work with the "invert" flag passed in.

N.b.: the dump probably really should a) not occur with any log decoration applied, and b) be printed to stdout like most other programs do it...
@dzuelke dzuelke requested a review from bukka as a code owner January 26, 2024 19:54
@dzuelke
Copy link
Contributor Author

dzuelke commented Jan 26, 2024

@bukka related discussion, but probably not a change for a patch release: the dumped config really should not be written as log lines (with time and NOTICE prefixes), and not to stderr (but instead to stdout).

For example, nginx -T or httpd -S behave this way - their config check status messages go to stderr, and the dumped config info goes to stdout.

This allows capturing of the dumped config cleanly using pipelines or redirects.

With the current php-fpm -tt behavior, one has to parse the log lines, and also discard potential log messages, such as the "test successful" notice after the dump (that's also printed when only testing, not dumping, which is fine).

@dzuelke
Copy link
Contributor Author

dzuelke commented Jan 26, 2024

@bukka as you can see, an explicit test to verify that the status message does not show up (because it's not warning level, and printed after the config dump) is commented out - the $invert option of FPM\Tester::expectLogNotice() doesn't seem to work.

@bukka
Copy link
Member

bukka commented Feb 3, 2024

I don't think this can be classified as a bug. I see it more like something that needs to be improved / better documented but essentially it is a feature. So it needs to target master.

As it is a feature I would prefer to just introduce new mode that will print it directly rather than using logger. Maybe we could do it if user specify -ttt as we already count them. That would keep -tt for BC and would be just a minor acceptable when more that 2 t are specified.

@bukka bukka added the Feature label Feb 3, 2024
@dzuelke
Copy link
Contributor Author

dzuelke commented Feb 15, 2024

Hmh, yeah, that is an option. This discussion probably warrants a separate issue or PR; I'll see if I have time to whip up the changes sometime soon in a PR, otherwise, I'll make an issue at least to track it.

What do you think about just the change in this PR to ensure that a requested config dump is at least always visible, @bukka? That seems like a more straightforward "ergonomics" fix. Want me to target a different base branch?

Is it intentional, by the way, that in config test mode, the output goes to the main server error log file in addition to standard error?

@bukka
Copy link
Member

bukka commented Mar 8, 2024

I guess it was probably intentional but not sure what was the thinking to do that. I don't think we can change this as a bug fix though. And for master it would be safer to just use the new mode. I think that changing the log level in the way how it's done in this PR is a bit of a hack so I would rather not do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants