Skip to content

Commit 8ea9a54

Browse files
Wdt 537 minimize console output (#1073)
* slim down console output with environment variable * create separate stdout for summary console * copyright * intermediate checkin * simplifying the logging framework and its configuration * adding newlines at the end of the file * adding newlines at the end of the file Co-authored-by: Carolyn Rountree <[email protected]>
1 parent 7953bc7 commit 8ea9a54

23 files changed

+596
-596
lines changed

core/src/main/java/oracle/weblogic/deploy/logging/WLSDeployConsoleFormatter.java renamed to core/src/main/java/oracle/weblogic/deploy/logging/ConsoleFormatter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.logging;
@@ -13,7 +13,7 @@
1313
* format the LogRecord into a localized String. To select a different formatter, inject
1414
* that instance into the set formatter of this Instance.
1515
*/
16-
public class WLSDeployConsoleFormatter extends Formatter {
16+
public class ConsoleFormatter extends Formatter {
1717

1818
// Default Formatter if another is not injected
1919
private Formatter formatter = new WLSDeployLogFormatter();
@@ -23,10 +23,10 @@ public String format(LogRecord logRecord) {
2323
return formatter.format(cloned);
2424
}
2525

26+
@SuppressWarnings("unused")
2627
public void setFormatter(Formatter formatter) {
2728
if (formatter != null) {
2829
this.formatter = formatter;
2930
}
3031
}
31-
32-
}
32+
}
Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,39 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.logging;
66

7-
import java.text.MessageFormat;
87
import java.util.Properties;
9-
import java.util.logging.Handler;
108
import java.util.logging.LogRecord;
119

12-
import static oracle.weblogic.deploy.logging.WLSDeployLoggingConfig.ERROR_EXIT_CODE;
13-
10+
/**
11+
* Utility class with methods used by the logging framework.
12+
*/
1413
public class LoggingUtils {
1514

16-
public static <T extends Handler> Class<T> getHandlerClass(String handlerName) {
17-
Class<T> handler = null;
18-
try {
19-
Class<?> checkClass = Class.forName(handlerName);
20-
@SuppressWarnings("unchecked")
21-
Class<T> castHandler = (Class<T>)checkClass.asSubclass(Class.forName(handlerName));
22-
handler = castHandler;
23-
} catch(ClassNotFoundException | ClassCastException cnf) {
24-
exitWithError(
25-
MessageFormat.format("Unable to find handler class {0} so skipping logging configuration",
26-
handlerName));
27-
}
28-
return handler;
29-
}
30-
31-
public static <T extends Handler> T getHandlerInstance(Class<T> handlerClass) {
32-
T handler = null;
33-
try {
34-
handler = handlerClass.newInstance();
35-
} catch (InstantiationException | IllegalAccessException e){
36-
exitWithError(MessageFormat.format("Unable to instantiate Handler for Class {0}", handlerClass));
37-
}
38-
return handler;
39-
}
40-
41-
public static <T extends Handler> T getHandlerInstance(String handlerClassName) {
42-
return getHandlerInstance(LoggingUtils.<T>getHandlerClass(handlerClassName));
43-
}
44-
45-
public static void exitWithError(String message) {
46-
System.err.println(message);
47-
System.exit(ERROR_EXIT_CODE);
15+
private LoggingUtils() {
16+
// hide the constructor
4817
}
4918

50-
public static LogRecord cloneRecordWithoutException(LogRecord record) {
51-
LogRecord newRecord = new LogRecord(record.getLevel(), record.getMessage());
52-
53-
newRecord.setLoggerName(record.getLoggerName());
54-
newRecord.setMillis(record.getMillis());
55-
newRecord.setParameters(record.getParameters());
56-
newRecord.setResourceBundle(record.getResourceBundle());
57-
newRecord.setResourceBundleName(record.getResourceBundleName());
58-
newRecord.setSequenceNumber(record.getSequenceNumber());
59-
newRecord.setSourceClassName(record.getSourceClassName());
60-
newRecord.setSourceMethodName(record.getSourceMethodName());
61-
newRecord.setThreadID(record.getThreadID());
19+
/**
20+
* Make a copy of a log record without the exception.
21+
*
22+
* @param logRecord the log record to copy
23+
* @return the cloned log record without the exception
24+
*/
25+
public static LogRecord cloneRecordWithoutException(LogRecord logRecord) {
26+
LogRecord newRecord = new LogRecord(logRecord.getLevel(), logRecord.getMessage());
27+
28+
newRecord.setLoggerName(logRecord.getLoggerName());
29+
newRecord.setMillis(logRecord.getMillis());
30+
newRecord.setParameters(logRecord.getParameters());
31+
newRecord.setResourceBundle(logRecord.getResourceBundle());
32+
newRecord.setResourceBundleName(logRecord.getResourceBundleName());
33+
newRecord.setSequenceNumber(logRecord.getSequenceNumber());
34+
newRecord.setSourceClassName(logRecord.getSourceClassName());
35+
newRecord.setSourceMethodName(logRecord.getSourceMethodName());
36+
newRecord.setThreadID(logRecord.getThreadID());
6237
// Skip thrown
6338
return newRecord;
6439
}
@@ -70,5 +45,4 @@ public static void printLogProperties(Properties logProps, String prefix) {
7045
}
7146
}
7247
}
73-
74-
}
48+
}

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.logging;
@@ -341,6 +341,7 @@ public boolean isFinestEnabled() {
341341
*
342342
* @return whether or not the INFO level is enabled
343343
*/
344+
@SuppressWarnings("unused")
344345
public boolean isInfoEnabled() {
345346
return logger.isLoggable(Level.INFO);
346347
}
@@ -369,6 +370,7 @@ public boolean isSevereEnabled() {
369370
*
370371
* @return whether or not the WARNING level is enabled
371372
*/
373+
@SuppressWarnings("unused")
372374
public boolean isWarningEnabled() {
373375
return logger.isLoggable(Level.WARNING);
374376
}
@@ -535,6 +537,7 @@ public void warning(String msg, Throwable thrown) {
535537
*
536538
* @return List of Logger from the Log Manager
537539
*/
540+
@SuppressWarnings("unused")
538541
public static List<Logger> getLoggers() {
539542
LogManager manager = LogManager.getLogManager();
540543
Enumeration<String> e = manager.getLoggerNames();
@@ -577,18 +580,18 @@ CallerDetails inferCaller() {
577580
}
578581

579582
private LogRecord getLogRecord(Level level, CallerDetails details, String msg, Throwable error, Object... params) {
580-
LogRecord record = new LogRecord(level, msg);
581-
record.setLoggerName(this.getName());
582-
record.setMillis(System.currentTimeMillis());
583+
LogRecord logRecord = new LogRecord(level, msg);
584+
logRecord.setLoggerName(this.getName());
585+
logRecord.setMillis(System.currentTimeMillis());
583586
if (params != null && params.length != 0) {
584-
record.setParameters(params);
587+
logRecord.setParameters(params);
585588
}
586-
record.setResourceBundle(logger.getResourceBundle());
587-
record.setSourceClassName(details.clazz);
588-
record.setSourceMethodName(details.method);
589-
record.setThreadID((int)Thread.currentThread().getId());
590-
record.setThrown(error);
591-
return record;
589+
logRecord.setResourceBundle(logger.getResourceBundle());
590+
logRecord.setSourceClassName(details.clazz);
591+
logRecord.setSourceMethodName(details.method);
592+
logRecord.setThreadID((int)Thread.currentThread().getId());
593+
logRecord.setThrown(error);
594+
return logRecord;
592595
}
593596

594597
/**
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.logging;
@@ -12,16 +12,15 @@
1212
* This Class queries the information in the LogRecord to determine if it can be written to the OutputStream
1313
* associated with Error log record types.
1414
*/
15-
public class WLSDeployConsoleErrorFilter implements Filter {
16-
15+
@SuppressWarnings("unused")
16+
public class StderrFilter implements Filter {
1717
@Override
18-
public boolean isLoggable(LogRecord record) {
18+
public boolean isLoggable(LogRecord logRecord) {
1919
boolean stdErr = false;
20-
int level = record.getLevel() == null ? 0 : record.getLevel().intValue();
20+
int level = logRecord.getLevel() == null ? 0 : logRecord.getLevel().intValue();
2121
if (level == Level.WARNING.intValue() || level == Level.SEVERE.intValue()) {
2222
stdErr = true;
2323
}
2424
return stdErr;
2525
}
26-
27-
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.logging;
@@ -8,22 +8,19 @@
88
import java.util.logging.StreamHandler;
99

1010
/**
11-
* This Class extends the StreamHandler to write log records to STDERR. The "wlsdeploy" Logger
12-
* is configured with an instance of this Handler class and an instance of Class @WLSDeployStdoutHandler@
13-
* to log records to the STDOUT and STDERR output streams.
14-
* <p>
15-
* Attach a logger or filter to this Handler to direct log records to the STDERR output stream
11+
* This Class extends the StreamHandler to write log records to STDERR.
1612
*/
17-
public class WLSDeployLoggingStderrHandler extends StreamHandler {
13+
@SuppressWarnings("unused")
14+
public class StderrHandler extends StreamHandler {
1815

19-
public WLSDeployLoggingStderrHandler() {
16+
public StderrHandler() {
2017
super();
2118
setOutputStream(System.err);
2219
}
2320

2421
@Override
25-
public void publish(LogRecord record) {
26-
super.publish(record);
22+
public synchronized void publish(LogRecord logRecord) {
23+
super.publish(logRecord);
2724
flush();
2825
}
2926

@@ -33,8 +30,7 @@ public void publish(LogRecord record) {
3330
* close <tt>System.err</tt>.
3431
*/
3532
@Override
36-
public void close() {
33+
public synchronized void close() {
3734
flush();
3835
}
39-
40-
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.logging;
@@ -12,16 +12,14 @@
1212
* This Class queries the information in the LogRecord to determine if it can be written to the OutputStream
1313
* associated with standard console log record types.
1414
*/
15-
public class WLSDeployConsoleOutFilter implements Filter {
16-
15+
public class StdoutFilter implements Filter {
1716
@Override
18-
public boolean isLoggable(LogRecord record) {
17+
public boolean isLoggable(LogRecord logRecord) {
1918
boolean stdOut = true;
20-
int level = record.getLevel() == null ? 0 : record.getLevel().intValue();
19+
int level = logRecord.getLevel() == null ? 0 : logRecord.getLevel().intValue();
2120
if (level == Level.WARNING.intValue() || level == Level.SEVERE.intValue()) {
2221
stdOut = false;
2322
}
2423
return stdOut;
2524
}
26-
27-
}
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2019, 2022, Oracle Corporation and/or its affiliates.
3+
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
*/
5+
package oracle.weblogic.deploy.logging;
6+
7+
import java.util.logging.LogRecord;
8+
import java.util.logging.StreamHandler;
9+
10+
/**
11+
* This Class extends the StreamHandler to write log records to STDOUT.
12+
*/
13+
@SuppressWarnings("unused")
14+
public class StdoutHandler extends StreamHandler {
15+
16+
public StdoutHandler() {
17+
super();
18+
setOutputStream(System.out);
19+
}
20+
21+
@Override
22+
public synchronized void publish(LogRecord logRecord) {
23+
super.publish(logRecord);
24+
flush();
25+
}
26+
27+
/**
28+
* Override <tt>StreamHandler.close</tt> to do a flush but not
29+
* to close the output stream. That is, we do <b>not</b>
30+
* close <tt>System.out</tt>.
31+
*/
32+
@Override
33+
public synchronized void close() {
34+
flush();
35+
}
36+
}

0 commit comments

Comments
 (0)