Fix `logger_formatter` about `msg` by making templates linear before split
I have encountered a somewhat strange behavior of logger_formatter about msg in templates. This pull request attempts to remedy it.
The behavior is exemplified by the following application:
- https://github.com/gfngfn/a_strange_behavior_of_logger_formatter
In summary, msgs occurring at conditional branching {metakey(), template(), template()} in templates will not be formatted as intended.
Looking into the implementation of logger_formatter:format, I have found that the implementation presumably assumes that given templates are of the form [Elem_1, …, Elem_{i - 1}, msg, Elem_{i + 1}, …, Elem_n] or do not contain msg. According to the definition of logger_formatter:template(), this assumption is not documented. Therefore, one of the following amendments seems to be needed:
- State in the manual that
msgmust occur as a top level element of templates and at most once; - Fix the implementation of
logger_formatter:formatso thatmsgs can occur under conditional branching but at most once for every “path”; or - Fix the implementation of
logger_formatter:formatso thatmsgs can occur everywhere in templates possibly more than once.
The present pull request suggests an amendment based on the second approach. This is because using msg more than once in a “path” does not seem so usual and also its support will require a bit complicated implementation due to the chars_limit option.
I would appreciate it if you could give any comments or suggestions (especially since this is my first pull request to this repository).
CT Test Results
2 files 65 suites 53m 58s :stopwatch: 1 321 tests 1 181 :heavy_check_mark: 140 :zzz: 0 :x: 1 476 runs 1 305 :heavy_check_mark: 171 :zzz: 0 :x:
Results for commit fe36d8b1.
:recycle: This comment has been updated with latest results.
To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.
See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.
Artifacts
// Erlang/OTP Github Action Bot
Rebased the branch onto maint and pushed it with --force (because the CI workflow had failed probably due to some other cause than this pull request). The workflow seems passing in this time on the forked repository: https://github.com/gfngfn/otp/actions/runs/2429845241
Thanks! I think the change looks good and makes sense. Putting it into testing to make sure it works on all OSs and configurations.
thanks!
Thank you for the review!