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
8271186: Add UL option to replace newline char #4885
Conversation
/csr needed |
|
@YaSuenag this pull request will not be integrated until the CSR request JDK-8271188 for issue JDK-8271186 has been approved. |
Webrevs
|
Could you, please, consider adding a test for this issue? Or updating an existing test? |
CSR has been approved, and I pushed new commit to add testcase and to update help message & manpage. Could you review? |
I tested the latest version in our CI pipeline and all tests in tiers 1-2 passed.
*equals_pos = '='; | ||
success = LogFileStreamOutput::initialize(pos, errstream); | ||
*equals_pos = '\0'; | ||
if (!success) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code can be simplified by parsing the value here:
bool fold_multilines = ....;
LogFileStreamOutput::set_fold_multilines(foldmultilines);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foldmultilines
is a parameter which should be applied in initialization. LogOutput
and extended classes of it look like to have a rule to apply initialization parameter at initialize()
.
We can simplify the code as you said if we can apply foldmultiline
for LogFileStreamOutput
at LogFileOutput::initialize()
, but I concern it breaks the semantics for UL implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, your concern is _fold_multilines
is a property of LogFileStreamOutput
, so the parsing of this option should be done inside the LogFileStreamOutput
class. That way, (in the future) all subclasses of LogFileStreamOutput
will be able to handle foldmultiline=true
in their options by deferring to LogFileStreamOutput::initialize
.
I suppose this would be useful if we have support for sockets in the future, like
-Xlog:all=socket::address=10.1.1.1,port=1234,foldmultiline=true
However, I don't think your current implementation has the right abstraction -- FoldMultilinesOptionKey
is now checked both in LogFileStreamOutput::initialize()
and LogFileOutput::initialize()
. If we add a new LogSocketOutput
in the future, we would have to duplicated the code in LogSocketOutput::initialize()
as well.
I think we should defer the design of such an abstraction until we need it. Ideally, LogFileOutput
and LogSocketOutput
should not need to know what options are supported by their superclass, LogFileStreamOutput
For the time being, it's easier to parse all the file output options in LogFileOutput::initialize()
to keep the code simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think your current implementation has the right abstraction
Agree, I think we can (should) improve more. Its improvement is not for LogSocketStream
but also for LogStd{out,err}Output
.
As we discussed in CSR about stdout/err, we will work for them in next step. But they extend LogFileStreamOutput
directly. So I want to refactor it before next step.
Anyway I moved foldmultiline
handling into LogFileOutput
in new commit.
" with the character sequence." | ||
" Escape newline (\\n) and backslash (\\) characters in the UL output" | ||
" if it is set to true." | ||
" Note that it works on file output only."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not "escaping" newline characters here. We went through great pains in the CSR request to describe the actual process accurately. We are replacing newlines with the sequence \
and n
. We also have to replace \
with the sequence \\
so that the conversion can be reversed by a parser. Saying all this in the help output is awkward but necessary. We also need to warn that this may not be safe with character encodings other than UTF-8. So something like:
If set to true, a log event that consists of multiple lines will be folded into a single line by replacing newline characters with the sequence '\' and 'n' in the output. Existing single backslash characters will also be replaced with a sequence of two backslashes so that the conversion can be reversed. This option is safe to use with UTF-8 character encodings, but other encodings may not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this version is much better than mine :-)
src/java.base/share/man/java.1
Outdated
.PP | ||
\f[I]foldmultilines\f[R] enables to replace newline characters within | ||
a multiline log event with the character sequence '\\' and 'n'. | ||
Note that it works on file output only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be expanded similar to the help info. But you can elaborate on the character encoding limitation as per the CSR request.
Thanks @iklam and @dholmes-ora ! I was relieved to hear my PR passed your CI pipeline. I updated help message and manpage. I will update |
.RE | ||
.PP | ||
When \f[I]foldmultilines\f[R] is true, a log event that consists of multiple lines will be folded into a single line by replacing newline characters with the sequence '\\' and 'n' in the output. Existing single backslash characters will also be replaced with a sequence of two backslashes so that the conversion can be reversed. This option is safe to use with UTF-8 character encodings, but other encodings may not work. For example, it may happen inadvertently conversion in multi-byte sequences in Shift JIS and BIG5. | ||
This option is available only for file outputs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about: "For example, it may incorrectly convert multi-byte sequences in Shift JIS and BIG5."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Ioi! I updated manpage, and also I formatted the description - it was too long than other lines!
@YaSuenag This change now passes all automated pre-integration checks. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 25 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.
|
/integrate |
Going to push as commit b16a04e.
Your commit was automatically rebased without conflicts. |
Most of UL entries would print log in one line, however some categories (e.g.
exceptions
) have multiline entries as following: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
:I've also filed CSR for this issue, please review it.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4885/head:pull/4885
$ git checkout pull/4885
Update a local copy of the PR:
$ git checkout pull/4885
$ git pull https://git.openjdk.java.net/jdk pull/4885/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 4885
View PR using the GUI difftool:
$ git pr show -t 4885
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4885.diff