Skip to content

adding deprecation log level for deprecation messages to show up in the summary handler #1369

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 1 commit into from
Jan 27, 2023
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
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2023, Oracle Corporation and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
package oracle.weblogic.deploy.logging;

import java.util.logging.Level;

public class DeprecationLevel extends Level {
public static final Level DEPRECATION = new DeprecationLevel("DEPRECATION", 850);

protected DeprecationLevel(String name, int value) {
super(name, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public void config(String msg, Object... params) {
logger.logp(Level.CONFIG, details.clazz, details.method, msg, params);
}
}

public void deprecation(String msg, Object... params) {
if (isDeprecationEnabled()) {
CallerDetails details = inferCaller();
logger.logp(DeprecationLevel.DEPRECATION, details.clazz, details.method, msg, params);
}
}

/**
* Logs a method entry. The calling class and method names will be inferred.
Expand Down Expand Up @@ -303,16 +310,25 @@ public void info(String msg, Object... params) {
/**
* Checks if a message at CONFIG level would actually be logged.
*
* @return whether or not the CONFIG level is enabled
* @return whether the CONFIG level is enabled
*/
public boolean isConfigEnabled() {
return logger.isLoggable(Level.CONFIG);
}

/**
* Checks if a message at DEPRECATION level would actually be logged.
*
* @return whether the DEPRECATION level is enabled
*/
public boolean isDeprecationEnabled() {
return logger.isLoggable(DeprecationLevel.DEPRECATION);
}

/**
* Checks if a message at FINE level would actually be logged.
*
* @return whether or not the FINE level is enabled
* @return whether the FINE level is enabled
*/
public boolean isFineEnabled() {
return logger.isLoggable(Level.FINE);
Expand All @@ -321,7 +337,7 @@ public boolean isFineEnabled() {
/**
* Checks if a message at FINER level would actually be logged.
*
* @return whether or not the FINER level is enabled
* @return whether the FINER level is enabled
*/
public boolean isFinerEnabled() {
return logger.isLoggable(Level.FINER);
Expand All @@ -330,7 +346,7 @@ public boolean isFinerEnabled() {
/**
* Checks if a message at FINEST level would actually be logged.
*
* @return whether or not the FINEST level is enabled
* @return whether the FINEST level is enabled
*/
public boolean isFinestEnabled() {
return logger.isLoggable(Level.FINEST);
Expand All @@ -339,7 +355,7 @@ public boolean isFinestEnabled() {
/**
* Checks if a message at INFO level would actually be logged.
*
* @return whether or not the INFO level is enabled
* @return whether the INFO level is enabled
*/
@SuppressWarnings("unused")
public boolean isInfoEnabled() {
Expand All @@ -350,7 +366,7 @@ public boolean isInfoEnabled() {
* Checks if a message at the provided level would actually be logged.
*
* @param level the logging level to check
* @return whether or not the specified logging level is enabled
* @return whether the specified logging level is enabled
*/
public boolean isLoggable(Level level) {
return logger.isLoggable(level);
Expand All @@ -359,7 +375,7 @@ public boolean isLoggable(Level level) {
/**
* Checks if a message at SEVERE level would actually be logged.
*
* @return whether or not the SEVERE level is enabled
* @return whether the SEVERE level is enabled
*/
public boolean isSevereEnabled() {
return logger.isLoggable(Level.SEVERE);
Expand All @@ -368,7 +384,7 @@ public boolean isSevereEnabled() {
/**
* Checks if a message at WARNING level would actually be logged.
*
* @return whether or not the WARNING level is enabled
* @return whether the WARNING level is enabled
*/
@SuppressWarnings("unused")
public boolean isWarningEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class StderrFilter implements Filter {
public boolean isLoggable(LogRecord logRecord) {
boolean stdErr = false;
int level = logRecord.getLevel() == null ? 0 : logRecord.getLevel().intValue();
if (level == Level.WARNING.intValue() || level == Level.SEVERE.intValue()) {
if (level == DeprecationLevel.DEPRECATION.intValue() ||
level == Level.WARNING.intValue() ||
level == Level.SEVERE.intValue()) {
stdErr = true;
}
return stdErr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class StdoutFilter implements Filter {
public boolean isLoggable(LogRecord logRecord) {
boolean stdOut = true;
int level = logRecord.getLevel() == null ? 0 : logRecord.getLevel().intValue();
if (level == Level.WARNING.intValue() || level == Level.SEVERE.intValue()) {
if (level == DeprecationLevel.DEPRECATION.intValue() ||
level == Level.WARNING.intValue() ||
level == Level.SEVERE.intValue()) {
stdOut = false;
}
return stdOut;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public SummaryHandler() {

this.bufferSize = getMemoryBufferSize(CLASS + SIZE_PROPERTY);

addLevelHandler(DeprecationLevel.DEPRECATION);
addLevelHandler(Level.WARNING);
addLevelHandler(Level.SEVERE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ExitCode {
public static final int ARG_VALIDATION_ERROR = 98;
public static final int USAGE_ERROR = 99;
public static final int HELP = 100;
public static final int DEPRECATION = 101;
public static final int RESTART_REQUIRED = 103;
public static final int CANCEL_CHANGES_IF_RESTART = 104;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4410,7 +4410,7 @@ protected void extractWallet(File domainHome, String extractPath, List<String> z
File extractToLocation = domainHome;
if (!StringUtils.isEmpty(deprecationKey)) {
extractToLocation = new File(domainHome, WLSDPLY_ARCHIVE_BINARY_DIR);
LOGGER.warning(deprecationKey, getArchiveFileName(), zipEntry, extractPath);
LOGGER.deprecation(deprecationKey, getArchiveFileName(), zipEntry, extractPath);
}
if (StringUtils.isEmpty(fromDir) && StringUtils.isEmpty(toDir)) {
extractFileFromZip(zipEntry, extractToLocation);
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/python/wlsdeploy/logging/platform_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.logging.Logger as JLogger
import java.util.logging.LogRecord as JLogRecord

import oracle.weblogic.deploy.logging.DeprecationLevel as DeprecationLevel

import wlsdeploy.exception.exception_helper as exception_helper
import wlsdeploy.util.unicode_helper as str_helper

Expand Down Expand Up @@ -56,6 +58,9 @@ def is_config_enabled(self):
"""
return self.logger.isLoggable(JLevel.CONFIG)

def is_deprecation_enabled(self):
return self.logger.isLoggable(DeprecationLevel.DEPRECATION)

def is_severe_enabled(self):
"""
Is severe-level logging enabled?
Expand Down Expand Up @@ -119,6 +124,14 @@ def config(self, message, *args, **kwargs):
record = self._get_log_record(JLevel.CONFIG, clazz, method, message, error, *args)
self.logger.log(record)

def deprecation(self, message, *args, **kwargs):
method = kwargs.pop('method_name', None)
clazz = kwargs.pop('class_name', None)
error = kwargs.pop('error', None)
record = self._get_log_record(DeprecationLevel.DEPRECATION, clazz, method, message, error, *args)
self.logger.log(record)


def log(self, level, message, *args, **kwargs):
"""
Log a message at the specified level.
Expand Down
20 changes: 10 additions & 10 deletions core/src/main/python/wlsdeploy/tool/create/rcudbinfo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def get_atp_default_tablespace(self):
_method_name = 'get_atp_default_tablespace'
result = self._get_dictionary_element_value(ATP_DEFAULT_TABLESPACE)
if result is not None:
self._logger.warning('WLSDPLY-22000', ATP_DEFAULT_TABLESPACE, RCU_DEFAULT_TBLSPACE,
class_name=_class_name, method_name=_method_name)
self._logger.deprecation('WLSDPLY-22000', ATP_DEFAULT_TABLESPACE, RCU_DEFAULT_TBLSPACE,
class_name=_class_name, method_name=_method_name)
return result
elif self.get_rcu_default_tablespace() is not None:
return self.get_rcu_default_tablespace()
Expand All @@ -139,8 +139,8 @@ def get_atp_temporary_tablespace(self):
_method_name = 'get_atp_temp_tablespace'
result = self._get_dictionary_element_value(ATP_TEMPORARY_TABLESPACE)
if result is not None:
self._logger.warning('WLSDPLY-22000', ATP_TEMPORARY_TABLESPACE, RCU_TEMP_TBLSPACE,
class_name=_class_name, method_name=_method_name)
self._logger.deprecation('WLSDPLY-22000', ATP_TEMPORARY_TABLESPACE, RCU_TEMP_TBLSPACE,
class_name=_class_name, method_name=_method_name)
return result
elif self.get_rcu_temp_tablespace() is not None:
return self.get_rcu_temp_tablespace()
Expand All @@ -151,8 +151,8 @@ def get_atp_admin_user(self):
_method_name = 'get_atp_admin_user'
result = self._get_dictionary_element_value(ATP_ADMIN_USER)
if result is not None:
self._logger.warning('WLSDPLY-22000', ATP_ADMIN_USER, RCU_DB_USER,
class_name=_class_name, method_name=_method_name)
self._logger.deprecation('WLSDPLY-22000', ATP_ADMIN_USER, RCU_DB_USER,
class_name=_class_name, method_name=_method_name)
return result
elif self.get_rcu_db_user() is not None:
return self.get_rcu_db_user()
Expand Down Expand Up @@ -220,8 +220,8 @@ def is_use_atp(self):
_method_name = 'is_use_atp'
result = self._get_dictionary_element_value(USE_ATP)
if result is not None:
self._logger.warning('WLSDPLY-22000', USE_ATP, DATABASE_TYPE,
class_name=_class_name, method_name=_method_name)
self._logger.deprecation('WLSDPLY-22000', USE_ATP, DATABASE_TYPE,
class_name=_class_name, method_name=_method_name)
model_value = self.rcu_properties_map[USE_ATP]
value = alias_utils.convert_to_type('boolean', model_value)
return value == 'true'
Expand All @@ -236,8 +236,8 @@ def is_use_ssl(self):
_method_name = 'is_use_ssl'
result = self._get_dictionary_element_value(USE_SSL)
if result is not None:
self._logger.warning('WLSDPLY-22000', USE_ATP, DATABASE_TYPE,
class_name=_class_name, method_name=_method_name)
self._logger.deprecation('WLSDPLY-22000', USE_ATP, DATABASE_TYPE,
class_name=_class_name, method_name=_method_name)
model_value = self.rcu_properties_map[USE_SSL]
value = alias_utils.convert_to_type('boolean', model_value)
return value == 'true'
Expand Down
1 change: 1 addition & 0 deletions core/src/main/python/wlsdeploy/util/exit_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ class ExitCode(object):
USAGE_ERROR = JExitCode.USAGE_ERROR

HELP = JExitCode.HELP
DEPRECATION = JExitCode.DEPRECATION
RESTART_REQUIRED = JExitCode.RESTART_REQUIRED
CANCEL_CHANGES_IF_RESTART = JExitCode.CANCEL_CHANGES_IF_RESTART
9 changes: 9 additions & 0 deletions core/src/main/python/wlsdeploy/util/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
WLST_EDIT_LOCK_EXCLUSIVE_DEFAULT = 'false'
YAML_FILE_MAX_CODE_POINTS_PROP = 'yaml.max.file.size'
YAML_FILE_MAX_CODE_POINTS_DEFAULT = '0'
USE_DEPRECATION_EXIT_CODE_PROP="use.deprecation.exit.code"
USE_DEPRECATION_EXIT_CODE_DEFAULT="false"

# System Property overrides for WLST timeout properties
SYS_PROP_PREFIX = 'wdt.config.'
Expand Down Expand Up @@ -156,6 +158,13 @@ def get_yaml_file_max_code_points(self):
"""
return self._get_from_dict_as_long(YAML_FILE_MAX_CODE_POINTS_PROP, YAML_FILE_MAX_CODE_POINTS_DEFAULT)

def get_use_deprecation_exit_code(self):
"""
Returns the value to determine whether deprecation messages should trigger the use of a non-zero exit code
:return: the string 'true' or 'false' (default)
"""
return self._get_from_dict(USE_DEPRECATION_EXIT_CODE_PROP, USE_DEPRECATION_EXIT_CODE_DEFAULT)

def _get_from_dict(self, name, default_value=None):
_method_name = '_get_from_dict'
_logger.entering(name, default_value, class_name=_class_name, method_name=_method_name)
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/python/wlsdeploy/util/tool_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from java.lang import Exception as JException
from java.util.logging import Level as JLevel

from oracle.weblogic.deploy.logging import DeprecationLevel
from oracle.weblogic.deploy.logging import WLSDeployLoggingConfig
from oracle.weblogic.deploy.logging import WLSDeployLogEndHandler
from oracle.weblogic.deploy.util import CLAException
Expand Down Expand Up @@ -75,14 +76,16 @@ def __exit_tool(model_context, exit_code):
"""
program = None
version = None
use_deprecation_exit_code = None
tool_mode = JWLSTMode.OFFLINE
if model_context:
program = model_context.get_program_name()
version = model_context.get_target_wls_version()
use_deprecation_exit_code = model_context.get_model_config().get_use_deprecation_exit_code()
if model_context.get_target_wlst_mode() == WlstModes.ONLINE:
tool_mode = JWLSTMode.ONLINE

exit_code = __get_summary_handler_exit_code(exit_code)
exit_code = __get_summary_handler_exit_code(exit_code, use_deprecation_exit_code)

WLSDeployExit.exit(WLSDeployContext(program, version, tool_mode), exit_code)

Expand Down Expand Up @@ -115,13 +118,14 @@ def __handle_unexpected_exception(ex, model_context, class_name, method_name, lo
class_name=class_name, method_name=method_name, error=ex)


def __get_summary_handler_exit_code(program_exit_code):
def __get_summary_handler_exit_code(program_exit_code, use_deprecation_exit_code):
"""
Private method for use only within this module.

Helper method to get the proper tool exit code based on the exit code from the tool and the number
of errors and warnings from the summary log handler.
:param program_exit_code: the exit code from the tool
:param use_deprecation_exit_code: whether to use the non-zero exit code for deprecations
:return: the exit code to use
"""
if program_exit_code != ExitCode.OK:
Expand All @@ -134,4 +138,8 @@ def __get_summary_handler_exit_code(program_exit_code):
exit_code = ExitCode.ERROR
elif summary_handler.getMessageCount(JLevel.WARNING) > 0:
exit_code = ExitCode.WARNING
elif use_deprecation_exit_code == 'true' and \
summary_handler.getMessageCount(DeprecationLevel.DEPRECATION) > 0:
exit_code = ExitCode.DEPRECATION

return exit_code
7 changes: 6 additions & 1 deletion installer/src/main/bin/shared.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@rem **************************************************************************
@rem shared.cmd
@rem
@rem Copyright (c) 2020, 2022, Oracle and/or its affiliates.
@rem Copyright (c) 2020, 2023, Oracle and/or its affiliates.
@rem Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
@rem
@rem NAME
Expand Down Expand Up @@ -379,6 +379,11 @@ GOTO :EOF
ECHO %SCRIPT_NAME% completed successfully but the domain requires a restart for the changes to take effect ^(exit code = %RETURN_CODE%^)
EXIT /B %RETURN_CODE%
)
IF "%RETURN_CODE%" == "101" (
ECHO.
ECHO %SCRIPT_NAME% completed successfully but with deprecation messages ^(exit code = %RETURN_CODE%^)
EXIT /B %RETURN_CODE%
)
IF "%RETURN_CODE%" == "100" (
EXIT /B %RETURN_CODE%
)
Expand Down
5 changes: 4 additions & 1 deletion installer/src/main/bin/shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# *****************************************************************************
# shared.sh
#
# Copyright (c) 2020, 2022, Oracle Corporation and/or its affiliates.
# Copyright (c) 2020, 2023, Oracle Corporation and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
# NAME
Expand Down Expand Up @@ -346,6 +346,9 @@ checkExitCode() {
elif [ $returnCode -eq 103 ]; then
echo ""
echo "$scriptName completed successfully but the domain requires a restart for the changes to take effect (exit code = ${RETURN_CODE})"
elif [ $returnCode -eq 101 ]; then
echo ""
echo "$scriptName completed successfully but with deprecation messages (exit code = $returnCode)" >&2
elif [ $returnCode -eq 100 ]; then
usage `basename $0`
elif [ $returnCode -eq 99 ]; then
Expand Down
5 changes: 5 additions & 0 deletions installer/src/main/lib/tool.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ wlst.edit.lock.exclusive=false
# 0 means to accept the default value, which is 3145728 (i.e., 3 MB)
#
yaml.max.file.size=0
#
# If set to true, tools that have deprecation messages and
# no warnings/errors will exit with a non-zero exit code.
#
use.deprecation.exit.code=false