Skip to content

Commit 963586d

Browse files
filtering non-WDT messages from being published by the Summary Handler (#1329)
* filtering non-WDT messages from being published by the Summary Handler * removing unused constants * removing unused imports
1 parent 6e9c011 commit 963586d

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

core/src/main/java/oracle/weblogic/deploy/logging/SummaryHandler.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.logging.LogManager;
1414
import java.util.logging.LogRecord;
1515
import java.util.logging.MemoryHandler;
16+
import java.util.regex.Matcher;
17+
import java.util.regex.Pattern;
1618

1719
import oracle.weblogic.deploy.util.StringUtils;
1820
import oracle.weblogic.deploy.util.WLSDeployContext;
@@ -33,18 +35,13 @@ public class SummaryHandler extends WLSDeployLogEndHandler {
3335
private static final String CLASS = SummaryHandler.class.getName();
3436
private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.exit");
3537

38+
private static final Pattern MSG_ID_PATTERN = Pattern.compile("^WLSDPLY-\\d{5}$");
3639
private static final String LEVEL_PROPERTY = ".level";
3740
private static final String TARGET_PROPERTY = ".target";
3841
private static final String SIZE_PROPERTY = ".size";
3942
private static final int DEFAULT_MEMORY_BUFFER_SIZE = 3000;
4043
private static final String DEFAULT_SIZE_PROPERTY_VALUE = Integer.toString(DEFAULT_MEMORY_BUFFER_SIZE);
4144

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-
4845
private final int bufferSize;
4946
private WLSDeployContext context;
5047
private boolean suppressOutput = false;
@@ -269,7 +266,8 @@ public synchronized String format(LogRecord logRecord) {
269266
}
270267

271268
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();
273271
private final String internal = System.lineSeparator() + "%s" + System.lineSeparator() + System.lineSeparator();
274272
private int sequence = 0;
275273
private final Level level;
@@ -280,15 +278,15 @@ public SummaryFormatter(Level level) {
280278

281279
@Override
282280
public synchronized String format(LogRecord logRecord) {
283-
String message = "";
281+
String message;
284282
String msgId = logRecord.getMessage();
285-
if (msgId.indexOf('{') >= 0) {
286-
msgId = null;
287-
}
288283
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);
292290
}
293291
return message;
294292
}
@@ -310,9 +308,21 @@ private class LevelHandler extends MemoryHandler {
310308
@Override
311309
public synchronized void publish(LogRecord logRecord) {
312310
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.
316326
//
317327
return;
318328
}
@@ -324,14 +334,5 @@ public synchronized void publish(LogRecord logRecord) {
324334
int getTotalRecords() {
325335
return totalRecords;
326336
}
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-
}
336337
}
337338
}

core/src/main/java/oracle/weblogic/deploy/util/XPathUtil.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import java.nio.file.Paths;
1313
import java.util.ArrayList;
1414
import java.util.Collections;
15-
import java.util.HashMap;
1615
import java.util.List;
17-
import java.util.Map;
1816
import java.util.regex.Matcher;
1917
import java.util.regex.Pattern;
2018

@@ -198,8 +196,8 @@ public List<String> findPatchFiles() {
198196
for (Path path : stream) {
199197
patchFiles.add(path.toString());
200198
}
201-
} catch (IOException ieo) {
202-
LOGGER.info("Unable to locate the patch files at {0}", patchesHome);
199+
} catch (IOException ioe) {
200+
LOGGER.info("WLSDPLY-01053", ioe, patchesHome, ioe.getLocalizedMessage());
203201
}
204202
return patchFiles;
205203
}
@@ -219,7 +217,7 @@ public Document readXmlFile(String path) {
219217
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
220218
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
221219
} catch (ParserConfigurationException pce) {
222-
LOGGER.warning("Unable to set feature in DocumentBuilderFactory : {0}");
220+
LOGGER.warning("WLSDPLY-01054", pce, pce.getLocalizedMessage());
223221
}
224222

225223
Document doc = null;
@@ -230,7 +228,7 @@ public Document readXmlFile(String path) {
230228
doc = db.parse(new File(path));
231229

232230
} catch (ParserConfigurationException | SAXException | IOException ioe) {
233-
LOGGER.info("Unable to parse the xml file {0}", path);
231+
LOGGER.info("WLSDPLY-01055", ioe, path, ioe.getLocalizedMessage());
234232
}
235233
return doc;
236234
}
@@ -246,7 +244,7 @@ private String description(Node node, String expression) {
246244
try {
247245
return (String) xpath.evaluate(expression, node, XPathConstants.STRING);
248246
} catch (XPathExpressionException xpe) {
249-
LOGGER.info("Unable to apply the expression {0}", expression);
247+
LOGGER.info("WLSDPLY-01056", xpe, expression, xpe.getLocalizedMessage());
250248
}
251249
return null;
252250
}

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ WLSDPLY-01000=Password was truncated to {0} characters
124124
WLSDPLY-01050=WebLogic version for aliases is {0}
125125
WLSDPLY-01051=WebLogic PSU description has an unexpected number of matching groups {0}: {1}
126126
WLSDPLY-01052=WebLogic PSU description is an exception but the PSU number {0} length {1} was unexpected: {2}
127+
WLSDPLY-01053=Unable to locate the patch files at {0}: {1}
128+
WLSDPLY-01054=Unable to set feature in DocumentBuilderFactory : {0}
129+
WLSDPLY-01055=Unable to parse the xml file {0}: {1}
130+
WLSDPLY-01056=Unable to apply the expression {0}: {1}
127131

128132
# oracle.weblogic.deploy.util.FileUtils.java
129133
WLSDPLY-01100=Failed to get the canonical file for {0} so falling back to absolute file instead: {1}

0 commit comments

Comments
 (0)