RFR: 8271186: Add UL option to replace newline char [v4]

Ioi Lam iklam at openjdk.java.net
Tue Aug 24 18:24:28 UTC 2021


On Tue, 24 Aug 2021 12:42:05 GMT, Yasumasa Suenaga <ysuenaga at openjdk.org> wrote:

>> Most of UL entries would print log in one line, however some categories (e.g. `exceptions`) have multiline entries as following:
>> 
>> 
>> [0.157s][info][exceptions] Exception <a 'java/lang/NullPointerException'{0x000000008b918f70}: test>
>>  thrown in interpreter method <{method} {0x00007f8335000248} 'main' '([Ljava/lang/String;)V' in 'Test'>
>>  at bci 9 for thread 0x00007f8330017160 (main)
>> 
>> 
>> It is ease to parse with log shipper (Fluent Bit, Logstash, and more) if UL can print all logs in one line.
>> Famous log shippers support multiline logs of course, but its configuration tends to be complex, and also some input plugins (e.g. TCP on Fluent Bit) do not support multiline logs.
>> 
>> So I want to introduce new UL option `foldmultilines` to replace all of newline char (`\n`) in the log entry will be replaced to 2 chars `\\n`. In addition, all of backslashes (`\` in C) are also replaced to 2 chars `\\\`.
>> 
>> After this patch, we can get following logs with `foldmultilines=true`:
>> 
>> 
>> [0.166s][info][exceptions] Exception <a 'java/lang/NullPointerException'{0x000000008b918f70}: test>\n thrown in interpreter method <{method} {0x00007fbc81000248} 'main' '([Ljava/lang/String;)V' in 'Test'>\n at bci 9 for thread 0x00007fbc9c0171a0 (main)
>> 
>> 
>> I've also filed [CSR](https://bugs.openjdk.java.net/browse/JDK-8271188) for this issue, please review it.
>
> Yasumasa Suenaga has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:
> 
>  - Update UL help message and manpage
>  - Merge remote-tracking branch 'upstream/master' into JDK-8271186
>  - Fix test on Windows
>  - Implement as foldmultilines
>  - Merge remote-tracking branch 'upstream/master' into JDK-8271186
>  - add inclusion of os.hpp
>  - 8271186: Add UL option to replace newline char

I tested the latest version in our CI pipeline and all tests in tiers 1-2 passed.

src/hotspot/share/logging/logConfiguration.cpp line 577:

> 575:                                          " Escape newline (\\n) and backslash (\\) characters in the UL output"
> 576:                                          " if it is set to true."
> 577:                                          " Note that it works on file output only.");

How about this message?


out->print_cr("   foldmultilines=.. - If set to true, a log event that consists of multiple lines"
                                       " will be folded into a single line by escaping"
                                       " the newline (\\n) and backslash (\) characters"
                                       " in the output.")

I think there's no need to say "it works on file output only" because this is under the heading of "Additional output-options for file outputs".

src/hotspot/share/logging/logFileOutput.cpp line 204:

> 202:       success = LogFileStreamOutput::initialize(pos, errstream);
> 203:       *equals_pos = '\0';
> 204:       if (!success) {

I think the code can be simplified by parsing the value here:

bool fold_multilines = ....;
LogFileStreamOutput::set_fold_multilines(foldmultilines);

src/java.base/share/man/java.1 line 4427:

> 4425: \f[I]foldmultilines\f[R] enables to replace newline characters within
> 4426: a multiline log event with the character sequence '\\' and 'n'.
> 4427: Note that it works on file output only.

How about:

> When foldmultilines is true, a log event that consists of multiple lines will be folded into a single line by escaping the newline (\\n) and backslash (\) characters in the output. This option is available only for file outputs.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4885


More information about the hotspot-runtime-dev mailing list