-
Notifications
You must be signed in to change notification settings - Fork 45
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
#87 Grouping stack traces into single log statements for sub-processes #90
base: master
Are you sure you want to change the base?
Changes from 2 commits
3bd48e8
a52948b
828ee4f
534bb5c
fcb0007
80df3b6
2975b06
1d48789
fed0c7d
256d4f3
6e07c94
a3bfd27
12c800b
0516292
cc2ab93
e2a9c1b
0c00490
ed7a354
5c92779
c2873ae
9f257d7
1ea04f2
bbc143b
9ad8ac3
74be2fa
8a10cf9
2a1b9cc
4a4a465
85cfd53
4dc1ca1
6b8e6f4
6deffec
c8c1efa
df9445a
63c19a2
8e4a50f
d14e4da
ac89ad5
c796d56
399c3ed
c4d4ac1
0b0ebe6
308aec4
61d46ab
699ad4d
25f2849
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,16 @@ public final class VerboseProcess implements Closeable { | |
*/ | ||
private transient boolean closed; | ||
|
||
/** | ||
* Maximum number of log lines for a stack trace | ||
*/ | ||
public static final int DEFUALT_MAX_LENGTH = 1000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark |
||
|
||
/** | ||
* Maximum number of log lines for a stack trace | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark according to http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html, first sentence should alsways end with period |
||
*/ | ||
public static volatile int maxStackLength = DEFUALT_MAX_LENGTH; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark can we somehow avoid static mutable data that is visible for everyone? |
||
|
||
/** | ||
* Public ctor. | ||
* @param prc The process to work with | ||
|
@@ -281,7 +291,7 @@ private String stdout(final boolean check) { | |
this.process, result.code(), result.stdout().length(), | ||
System.currentTimeMillis() - start | ||
); | ||
if (check && result.code() != 0) { | ||
if (check && (result.code() != 0)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark why this change was needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto-formatting in my IDE. i'll back it out since it's just cosmetic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark right, please just address this comment |
||
throw new IllegalArgumentException( | ||
Logger.format( | ||
"Non-zero exit code %d: %[text]s", | ||
|
@@ -389,6 +399,20 @@ private static void close(final Closeable res) { | |
* Stream monitor. | ||
*/ | ||
private static final class Monitor implements Callable<Void> { | ||
|
||
/** | ||
* Prefix "at " | ||
*/ | ||
private static final String PREFIX_AT = "at "; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark this looks like http://www.yegor256.com/2015/09/01/redundant-variables-are-evil.html, can you inline all redundant variables? |
||
/** | ||
* Prefix "Caused by" | ||
*/ | ||
private static final String PREFIX_CB = "Caused by"; | ||
/** | ||
* Prefix "... " | ||
*/ | ||
private static final String PREFIX_DOTS = "... "; | ||
|
||
/** | ||
* Stream to read. | ||
*/ | ||
|
@@ -420,6 +444,34 @@ private static final class Monitor implements Callable<Void> { | |
this.output = out; | ||
this.level = lvl; | ||
} | ||
|
||
/** | ||
* Checks if line is part of a stack trace and should be appended. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark does it mean that stactraces can have just these 3 prefixes and otherwise they are not stacktraces? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas It's not what they start with, but it's what comes after the initial line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark OK, thanks for explaining |
||
* @param string String to check | ||
* @return boolean result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark |
||
*/ | ||
private static boolean shouldAppend(final String string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark can you come up with other name for the variable? |
||
final String leftStrip = stripStart(string); | ||
return leftStrip.startsWith(PREFIX_AT) || leftStrip.startsWith(PREFIX_CB) || leftStrip.startsWith(PREFIX_DOTS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark line cannot have more than 80 chars, please read http://www.yegor256.com/2014/04/27/typical-mistakes-in-java-code.html#indentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark I didn't mean to remove this logic. I just meant that when you had throws IOException, ClosedByInterruptException the second exception was unncecessary, as |
||
} | ||
|
||
/** | ||
* Strips whitespace at beginning of String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark I think string here could be lowercase :) |
||
* @param string String to strip | ||
* @return string Stripped String | ||
*/ | ||
private static String stripStart(final String string) { | ||
if ((string == null) || string.isEmpty()) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark |
||
} | ||
final int stringLength = string.length(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark this needs to be inlined, see http://www.yegor256.com/2015/09/01/redundant-variables-are-evil.html |
||
int start = 0; | ||
while ((start != stringLength) && Character.isWhitespace(string.charAt(start))) { | ||
start++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark here it doesn't matter, but generally I'd prefer |
||
} | ||
return string.substring(start); | ||
} | ||
|
||
@Override | ||
public Void call() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark this method has become massive, it needs to be split across many private ones |
||
final BufferedReader reader = new BufferedReader( | ||
|
@@ -433,6 +485,9 @@ public Void call() throws Exception { | |
new OutputStreamWriter(this.output, VerboseProcess.UTF_8) | ||
); | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark for so complex logic added in this PR I'd expect at least dozen of unit tests, but I don't see any 😞 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have you read this: http://www.yegor256.com/2017/03/24/tdd-that-works.html? What about writing unit tests only when bugs will appear? |
||
StringBuilder sb = new StringBuilder(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark local variables could be just one word like |
||
String previousLine = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark here as well, it should be just |
||
int lineCount = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
while (true) { | ||
if (Thread.interrupted()) { | ||
Logger.debug( | ||
|
@@ -441,16 +496,33 @@ public Void call() throws Exception { | |
); | ||
break; | ||
} | ||
if (previousLine != null) { | ||
sb.append(previousLine).append(System.getProperty("line.separator")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark |
||
previousLine = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark again, this PR cannot have |
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
final String line = reader.readLine(); | ||
if (line == null) { | ||
if (sb.length() > 0) { | ||
final String logText = sb.toString(); | ||
Logger.log(this.level, VerboseProcess.class, ">> %s", logText); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark |
||
writer.write(logText); | ||
} | ||
break; | ||
} | ||
Logger.log( | ||
this.level, VerboseProcess.class, | ||
">> %s", line | ||
); | ||
writer.write(line); | ||
writer.newLine(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark methods are not allowed to have any empty lines |
||
if (shouldAppend(line) && (++lineCount < maxStackLength)) { | ||
sb.append(line).append(System.getProperty("line.separator")); | ||
} else { | ||
if (sb.length() > 0) { | ||
final String logText = sb.toString(); | ||
Logger.log(this.level, VerboseProcess.class, ">> %s", logText); | ||
writer.write(logText); | ||
sb = new StringBuilder(); | ||
} | ||
lineCount = 1; | ||
previousLine = line; | ||
} | ||
} | ||
} catch (final ClosedByInterruptException ex) { | ||
Thread.interrupted(); | ||
|
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.
@dean-e-clark
static
fields should always go before non-static ones