-
Notifications
You must be signed in to change notification settings - Fork 835
Date formulas are not valid in custom error logs #2884
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
Comments
Hi allegrox ! Thanks for the report I've reproduced the same strange behavior, looking on it. |
To understand more deeply, there are some explanation in the comment from log.c/sess_build_logline() here You can see the date, when you change this sample fetch to %t, because, when the connection's stream object doesn't exist accept_date is given from the session metadata here and it is just copied here to the building log line string (tmplog variable). So, when I've reproduced this problem I saw this with config: Instead of date with ms, you have just "-" due to the absence of a stream. Do you have the same output ? There is a hint in the doc with an example of quiet full error-log-format
|
Yes, date replaced by "-" in error-log, That is, in the error log, %t is not derived from the formula? |
By initial design we stop to process I've looked to the code again and come up with the patch below. As we always save the accept date, when we build a log line, in the case of error log, the accept time could be also fetched and formatted. You could apply this patch to the latest dev version and test it, if you are blocked with this:
Need to pass review and to discuss with collegues, if there is no any side effects by considering the session data in this sample fetch. |
Sample fetches %[accept_date] and %[request_date] with converters can be used in error-log-format string. But in the most error cases they fetches nothing, as error logs are produced on SSL handshake issues or when invalid PROXY protocol header is used. Stream object is never allocated in such cases and smp_fetch_accept_date() just simply returns 0. There is a need to have a custom date format (ISO8601) also in the error logs, along with normal logs. When sess_build_logline_orig() builds log line it always copies the accept date to strm_logs structure. When stream is absent, accept date is copied from the session object. So, if the steam object wasn't allocated, let's use the session date info in smp_fetch_accept_date(). This allows then, in sample_process(), to apply to the fetched date different converters and formats. This fixes the issue haproxy#2884.
Sample fetches %[accept_date] and %[request_date] with converters can be used in error-log-format string. But in the most error cases they fetches nothing, as error logs are produced on SSL handshake issues or when invalid PROXY protocol header is used. Stream object is never allocated in such cases and smp_fetch_accept_date() just simply returns 0. There is a need to have a custom date format (ISO8601) also in the error logs, along with normal logs. When sess_build_logline_orig() builds log line it always copies the accept date to strm_logs structure. When stream is absent, accept date is copied from the session object. So, if the steam object wasn't allocated, let's use the session date info in smp_fetch_accept_date(). This allows then, in sample_process(), to apply to t 7C3C he fetched date different converters and formats. This fixes the issue #2884.
Sample fetches %[accept_date] and %[request_date] with converters can be used in error-log-format string. But in the most error cases they fetches nothing, as error logs are produced on SSL handshake issues or when invalid PROXY protocol header is used. Stream object is never allocated in such cases and smp_fetch_accept_date() just simply returns 0. There is a need to have a custom date format (ISO8601) also in the error logs, along with normal logs. When sess_build_logline_orig() builds log line it always copies the accept date to strm_logs structure. When stream is absent, accept date is copied from the session object. So, if the steam object wasn't allocated, let's use the session date info in smp_fetch_accept_date(). This allows then, in sample_process(), to apply to the fetched date different converters and formats. This fixes the issue haproxy#2884.
Detailed Description of the Problem
When I use a date formula in a custom error log, the date field is not output in the log. But the output is correct when using date variable (%t). The date formula used here is the one that corresponds to the date variable in the official documentation (https://docs.haproxy.org/3.0/configuration.html#8.2.6).
Expected Behavior
date formulas are not valid in custom error logs
Steps to Reproduce the Behavior
Stable reproduction:
no date in log
There's date in the log.
Do you have any idea what may have caused this?
No response
Do you have an idea how to solve the issue?
No response
What is your configuration?
Output of
haproxy -vv
Last Outputs and Backtraces
Additional Information
No response
The text was updated successfully, but these errors were encountered: