11/*
2- * Copyright (c) 2019, 2022 , Oracle Corporation and/or its affiliates.
2+ * Copyright (c) 2019, 2023 , Oracle and/or its affiliates.
33 * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44 */
55package oracle .weblogic .deploy .logging ;
66
77import java .util .logging .Formatter ;
8+ import java .util .logging .Level ;
9+ import java .util .logging .LogManager ;
810import java .util .logging .LogRecord ;
911
12+ import static oracle .weblogic .deploy .logging .WLSDeployLoggingConfig .HANDLER_LEVEL_PROP ;
13+ import static oracle .weblogic .deploy .logging .WLSDeployLoggingConfig .WLSDEPLOY_STDOUT_CONSOLE_HANDLER ;
14+
1015/**
1116 * This class removes the Exception record from the LogRecord before formatting so that a
1217 * stack trace will not print to the Console. The WLSDeployLogFormatter is by default called to
@@ -17,10 +22,22 @@ public class ConsoleFormatter extends Formatter {
1722
1823 // Default Formatter if another is not injected
1924 private Formatter formatter = new WLSDeployLogFormatter ();
25+ private boolean suppressExceptions = true ;
26+
27+ public ConsoleFormatter () {
28+ String stdoutHandlerLevel =
29+ LogManager .getLogManager ().getProperty (WLSDEPLOY_STDOUT_CONSOLE_HANDLER + HANDLER_LEVEL_PROP );
30+ if (stdoutHandlerLevel != null && stdoutHandlerLevel .equalsIgnoreCase (Level .ALL .toString ())) {
31+ suppressExceptions = false ;
32+ }
33+ }
2034
2135 public String format (LogRecord logRecord ) {
22- LogRecord cloned = LoggingUtils .cloneRecordWithoutException (logRecord );
23- return formatter .format (cloned );
36+ LogRecord recordToPublish = logRecord ;
37+ if (suppressExceptions ) {
38+ recordToPublish = LoggingUtils .cloneRecordWithoutException (logRecord );
39+ }
40+ return formatter .format (recordToPublish );
2441 }
2542
2643 @ SuppressWarnings ("unused" )
0 commit comments