otp icon indicating copy to clipboard operation
otp copied to clipboard

Fix `logger_formatter` about `msg` by making templates linear before split

Open gfngfn opened this issue 3 years ago • 3 comments

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:

  1. State in the manual that msg must occur as a top level element of templates and at most once;
  2. Fix the implementation of logger_formatter:format so that msgs can occur under conditional branching but at most once for every “path”; or
  3. Fix the implementation of logger_formatter:format so that msgs 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).

gfngfn avatar May 31 '22 03:05 gfngfn

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 31 '22 03:05 CLAassistant

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

github-actions[bot] avatar May 31 '22 03:05 github-actions[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

gfngfn avatar Jun 02 '22 19:06 gfngfn

Thanks! I think the change looks good and makes sense. Putting it into testing to make sure it works on all OSs and configurations.

garazdawi avatar Aug 19 '22 07:08 garazdawi

thanks!

garazdawi avatar Aug 26 '22 12:08 garazdawi

Thank you for the review!

gfngfn avatar Aug 27 '22 19:08 gfngfn