13
13
import java .util .logging .LogManager ;
14
14
import java .util .logging .LogRecord ;
15
15
import java .util .logging .MemoryHandler ;
16
+ import java .util .regex .Matcher ;
17
+ import java .util .regex .Pattern ;
16
18
17
19
import oracle .weblogic .deploy .util .StringUtils ;
18
20
import oracle .weblogic .deploy .util .WLSDeployContext ;
@@ -33,18 +35,13 @@ public class SummaryHandler extends WLSDeployLogEndHandler {
33
35
private static final String CLASS = SummaryHandler .class .getName ();
34
36
private static final PlatformLogger LOGGER = WLSDeployLogFactory .getLogger ("wlsdeploy.exit" );
35
37
38
+ private static final Pattern MSG_ID_PATTERN = Pattern .compile ("^WLSDPLY-\\ d{5}$" );
36
39
private static final String LEVEL_PROPERTY = ".level" ;
37
40
private static final String TARGET_PROPERTY = ".target" ;
38
41
private static final String SIZE_PROPERTY = ".size" ;
39
42
private static final int DEFAULT_MEMORY_BUFFER_SIZE = 3000 ;
40
43
private static final String DEFAULT_SIZE_PROPERTY_VALUE = Integer .toString (DEFAULT_MEMORY_BUFFER_SIZE );
41
44
42
- // In 12.2.1.0.0, cd(), runCmd(), ls() errors percolate up into this handler. Use these constants
43
- // to filter out the errors so that they are not counted.
44
- //
45
- private static final String CIE_EXCEPTION_CLASS = "com.oracle.cie.domain.script.jython.CommandExceptionHandler" ;
46
- private static final String CIE_EXCEPTION_METHOD = "handleException" ;
47
-
48
45
private final int bufferSize ;
49
46
private WLSDeployContext context ;
50
47
private boolean suppressOutput = false ;
@@ -269,7 +266,8 @@ public synchronized String format(LogRecord logRecord) {
269
266
}
270
267
271
268
private class SummaryFormatter extends Formatter {
272
- private final String msgFormat = " %1$5d. %2$s: %3$s" + System .lineSeparator ();
269
+ private final String MSG_WITH_ID_FORMAT = " %1$5d. %2$s: %3$s" + System .lineSeparator ();
270
+ private final String MSG_WITH_NO_ID_FORMAT = " %1$5d. %2$s" + System .lineSeparator ();
273
271
private final String internal = System .lineSeparator () + "%s" + System .lineSeparator () + System .lineSeparator ();
274
272
private int sequence = 0 ;
275
273
private final Level level ;
@@ -280,15 +278,15 @@ public SummaryFormatter(Level level) {
280
278
281
279
@ Override
282
280
public synchronized String format (LogRecord logRecord ) {
283
- String message = "" ;
281
+ String message ;
284
282
String msgId = logRecord .getMessage ();
285
- if (msgId .indexOf ('{' ) >= 0 ) {
286
- msgId = null ;
287
- }
288
283
String formatted = formatMessage (logRecord );
289
- if (msgId != null && !msgId .equals (formatted )) {
290
- // this has a msg id. don't post any that don't have msg id.
291
- message = String .format (msgFormat , ++sequence , msgId , formatted );
284
+
285
+ Matcher matcher = MSG_ID_PATTERN .matcher (msgId );
286
+ if (matcher .matches ()) {
287
+ message = String .format (MSG_WITH_ID_FORMAT , ++sequence , msgId , formatted );
288
+ } else {
289
+ message = String .format (MSG_WITH_NO_ID_FORMAT , ++sequence , formatted );
292
290
}
293
291
return message ;
294
292
}
@@ -310,9 +308,21 @@ private class LevelHandler extends MemoryHandler {
310
308
@ Override
311
309
public synchronized void publish (LogRecord logRecord ) {
312
310
if (logRecord .getLevel ().equals (getLevel ())) {
313
- if (getLevel () == Level .SEVERE && isCieErrorLog (logRecord )) {
314
- // Do not publish or count WLS 12.2.1.0 error logs from the CIE class
315
- // related to cd(), runCmd(), ls(), etc.
311
+ String msgId = logRecord .getMessage ();
312
+ if (StringUtils .isEmpty (msgId )) {
313
+ // Don't publish any log records with an empty message
314
+ return ;
315
+ }
316
+ Matcher matcher = MSG_ID_PATTERN .matcher (msgId );
317
+ if (!matcher .matches ()) {
318
+ // Don't publish any log records without a real i18n message ID.
319
+ //
320
+ // NOTE: We are relying on this mechanism to suppress WLS 12.2.1.0 error log messages
321
+ // from the com.oracle.cie.domain.script.jython.CommandExceptionHandler class'
322
+ // handleException() method related to cd(), runCmd(), ls(), etc. If we remove
323
+ // this Message ID only restriction, we still need to prevent these CIE error
324
+ // messages in 12.2.1.0 from polluting the Summary Handler since this will cause
325
+ // the exit code of the tool to be 2 even though everything is working properly.
316
326
//
317
327
return ;
318
328
}
@@ -324,14 +334,5 @@ public synchronized void publish(LogRecord logRecord) {
324
334
int getTotalRecords () {
325
335
return totalRecords ;
326
336
}
327
-
328
- private boolean isCieErrorLog (LogRecord logRecord ) {
329
- if (logRecord .getLevel () == Level .SEVERE
330
- && CIE_EXCEPTION_CLASS .equals (logRecord .getSourceClassName ())
331
- && CIE_EXCEPTION_METHOD .equals (logRecord .getSourceMethodName ())) {
332
- return true ;
333
- }
334
- return false ;
335
- }
336
337
}
337
338
}
0 commit comments