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
Closed
+168
−14
Closed
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
af24c9f
8271186: Add UL option to replace newline char
YaSuenag 358fbe1
add inclusion of os.hpp
YaSuenag 189dd3b
Merge remote-tracking branch 'upstream/master' into JDK-8271186
YaSuenag f521450
Implement as foldmultilines
YaSuenag 03af43f
Fix test on Windows
YaSuenag 267ebd0
Merge remote-tracking branch 'upstream/master' into JDK-8271186
YaSuenag 55ee9cf
Update UL help message and manpage
YaSuenag 19bc58c
Update description in help message and in manpage
YaSuenag bb3f236
Remove initialize function from LogFileStreamOutput
YaSuenag 64122a4
Update manpage of java
YaSuenag File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2021 NTT DATA. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 8271186 | ||
* @library /test/lib | ||
* @run driver FoldMultilinesTest | ||
*/ | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import jdk.test.lib.process.OutputAnalyzer; | ||
import jdk.test.lib.process.ProcessTools; | ||
|
||
public class FoldMultilinesTest { | ||
|
||
private static Path EXCEPTION_LOG_FILE = Path.of("exceptions.log"); | ||
private static String XLOG_BASE = "-Xlog:exceptions=info:file=" + EXCEPTION_LOG_FILE.toString(); | ||
|
||
private static void analyzeFoldMultilinesOn(ProcessBuilder pb) throws Exception { | ||
OutputAnalyzer output = new OutputAnalyzer(pb.start()); | ||
output.shouldHaveExitValue(0); | ||
|
||
String logs = Files.readString(EXCEPTION_LOG_FILE); | ||
if (!logs.contains("line 1\\nline 2\\\\nstring")) { | ||
throw new RuntimeException("foldmultilines=true did not work."); | ||
} | ||
} | ||
|
||
private static void analyzeFoldMultilinesOff(ProcessBuilder pb) throws Exception { | ||
OutputAnalyzer output = new OutputAnalyzer(pb.start()); | ||
output.shouldHaveExitValue(0); | ||
|
||
String logs = Files.readString(EXCEPTION_LOG_FILE); | ||
if (!logs.contains("line 1" + System.lineSeparator() + "line 2\\nstring")) { | ||
throw new RuntimeException("foldmultilines=false did not work."); | ||
} | ||
} | ||
|
||
private static void analyzeFoldMultilinesInvalid(ProcessBuilder pb) throws Exception { | ||
OutputAnalyzer output = new OutputAnalyzer(pb.start()); | ||
output.shouldContain("Invalid option 'invalid' for foldmultilines."); | ||
output.shouldNotHaveExitValue(0); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
String Xlog; | ||
ProcessBuilder pb; | ||
|
||
Xlog = XLOG_BASE + "::foldmultilines=true"; | ||
pb = ProcessTools.createJavaProcessBuilder(Xlog, InternalClass.class.getName()); | ||
analyzeFoldMultilinesOn(pb); | ||
|
||
Xlog = XLOG_BASE + "::foldmultilines=false"; | ||
pb = ProcessTools.createJavaProcessBuilder(Xlog, InternalClass.class.getName()); | ||
analyzeFoldMultilinesOff(pb); | ||
|
||
Xlog = XLOG_BASE + "::foldmultilines=invalid"; | ||
pb = ProcessTools.createJavaProcessBuilder(Xlog, InternalClass.class.getName()); | ||
analyzeFoldMultilinesInvalid(pb); | ||
} | ||
|
||
public static class InternalClass { | ||
public static void main(String[] args) { | ||
try { | ||
throw new RuntimeException("line 1\nline 2\\nstring"); | ||
} catch (Exception e) { | ||
// Do nothing to return exit code 0 | ||
} | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
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:
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 atinitialize()
.We can simplify the code as you said if we can apply
foldmultiline
forLogFileStreamOutput
atLogFileOutput::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 ofLogFileStreamOutput
, so the parsing of this option should be done inside theLogFileStreamOutput
class. That way, (in the future) all subclasses ofLogFileStreamOutput
will be able to handlefoldmultiline=true
in their options by deferring toLogFileStreamOutput::initialize
.I suppose this would be useful if we have support for sockets in the future, like
However, I don't think your current implementation has the right abstraction --
FoldMultilinesOptionKey
is now checked both inLogFileStreamOutput::initialize()
andLogFileOutput::initialize()
. If we add a newLogSocketOutput
in the future, we would have to duplicated the code inLogSocketOutput::initialize()
as well.I think we should defer the design of such an abstraction until we need it. Ideally,
LogFileOutput
andLogSocketOutput
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.
Agree, I think we can (should) improve more. Its improvement is not for
LogSocketStream
but also forLogStd{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 intoLogFileOutput
in new commit.