Skip to content

filtering non-WDT messages from being published by the Summary Handler #1329

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

Merged
merged 3 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.MemoryHandler;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

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

// In 12.2.1.0.0, cd(), runCmd(), ls() errors percolate up into this handler. Use these constants
// to filter out the errors so that they are not counted.
//
private static final String CIE_EXCEPTION_CLASS = "com.oracle.cie.domain.script.jython.CommandExceptionHandler";
private static final String CIE_EXCEPTION_METHOD = "handleException";

private final int bufferSize;
private WLSDeployContext context;
private boolean suppressOutput = false;
Expand Down Expand Up @@ -269,7 +266,8 @@ public synchronized String format(LogRecord logRecord) {
}

private class SummaryFormatter extends Formatter {
private final String msgFormat = " %1$5d. %2$s: %3$s" + System.lineSeparator();
private final String MSG_WITH_ID_FORMAT = " %1$5d. %2$s: %3$s" + System.lineSeparator();
private final String MSG_WITH_NO_ID_FORMAT = " %1$5d. %2$s" + System.lineSeparator();
private final String internal = System.lineSeparator() + "%s" + System.lineSeparator() + System.lineSeparator();
private int sequence = 0;
private final Level level;
Expand All @@ -280,15 +278,15 @@ public SummaryFormatter(Level level) {

@Override
public synchronized String format(LogRecord logRecord) {
String message = "";
String message;
String msgId = logRecord.getMessage();
if (msgId.indexOf('{') >= 0) {
msgId = null;
}
String formatted = formatMessage(logRecord);
if (msgId != null && !msgId.equals(formatted)) {
// this has a msg id. don't post any that don't have msg id.
message = String.format(msgFormat, ++sequence, msgId, formatted);

Matcher matcher = MSG_ID_PATTERN.matcher(msgId);
if (matcher.matches()) {
message = String.format(MSG_WITH_ID_FORMAT, ++sequence, msgId, formatted);
} else {
message = String.format(MSG_WITH_NO_ID_FORMAT, ++sequence, formatted);
}
return message;
}
Expand All @@ -310,9 +308,21 @@ private class LevelHandler extends MemoryHandler {
@Override
public synchronized void publish(LogRecord logRecord) {
if (logRecord.getLevel().equals(getLevel())) {
if (getLevel() == Level.SEVERE && isCieErrorLog(logRecord)) {
// Do not publish or count WLS 12.2.1.0 error logs from the CIE class
// related to cd(), runCmd(), ls(), etc.
String msgId = logRecord.getMessage();
if (StringUtils.isEmpty(msgId)) {
// Don't publish any log records with an empty message
return;
}
Matcher matcher = MSG_ID_PATTERN.matcher(msgId);
if (!matcher.matches()) {
// Don't publish any log records without a real i18n message ID.
//
// NOTE: We are relying on this mechanism to suppress WLS 12.2.1.0 error log messages
// from the com.oracle.cie.domain.script.jython.CommandExceptionHandler class'
// handleException() method related to cd(), runCmd(), ls(), etc. If we remove
// this Message ID only restriction, we still need to prevent these CIE error
// messages in 12.2.1.0 from polluting the Summary Handler since this will cause
// the exit code of the tool to be 2 even though everything is working properly.
//
return;
}
Expand All @@ -324,14 +334,5 @@ public synchronized void publish(LogRecord logRecord) {
int getTotalRecords() {
return totalRecords;
}

private boolean isCieErrorLog(LogRecord logRecord) {
if (logRecord.getLevel() == Level.SEVERE
&& CIE_EXCEPTION_CLASS.equals(logRecord.getSourceClassName())
&& CIE_EXCEPTION_METHOD.equals(logRecord.getSourceMethodName())) {
return true;
}
return false;
}
}
}
12 changes: 5 additions & 7 deletions core/src/main/java/oracle/weblogic/deploy/util/XPathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -198,8 +196,8 @@ public List<String> findPatchFiles() {
for (Path path : stream) {
patchFiles.add(path.toString());
}
} catch (IOException ieo) {
LOGGER.info("Unable to locate the patch files at {0}", patchesHome);
} catch (IOException ioe) {
LOGGER.info("WLSDPLY-01053", ioe, patchesHome, ioe.getLocalizedMessage());
}
return patchFiles;
}
Expand All @@ -219,7 +217,7 @@ public Document readXmlFile(String path) {
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (ParserConfigurationException pce) {
LOGGER.warning("Unable to set feature in DocumentBuilderFactory : {0}");
LOGGER.warning("WLSDPLY-01054", pce, pce.getLocalizedMessage());
}

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

} catch (ParserConfigurationException | SAXException | IOException ioe) {
LOGGER.info("Unable to parse the xml file {0}", path);
LOGGER.info("WLSDPLY-01055", ioe, path, ioe.getLocalizedMessage());
}
return doc;
}
Expand All @@ -246,7 +244,7 @@ private String description(Node node, String expression) {
try {
return (String) xpath.evaluate(expression, node, XPathConstants.STRING);
} catch (XPathExpressionException xpe) {
LOGGER.info("Unable to apply the expression {0}", expression);
LOGGER.info("WLSDPLY-01056", xpe, expression, xpe.getLocalizedMessage());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ WLSDPLY-01000=Password was truncated to {0} characters
WLSDPLY-01050=WebLogic version for aliases is {0}
WLSDPLY-01051=WebLogic PSU description has an unexpected number of matching groups {0}: {1}
WLSDPLY-01052=WebLogic PSU description is an exception but the PSU number {0} length {1} was unexpected: {2}
WLSDPLY-01053=Unable to locate the patch files at {0}: {1}
WLSDPLY-01054=Unable to set feature in DocumentBuilderFactory : {0}
WLSDPLY-01055=Unable to parse the xml file {0}: {1}
WLSDPLY-01056=Unable to apply the expression {0}: {1}

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