Skip to content

Adding new log levels and cleaning up the totals line #1391

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 5 commits into from
Feb 15, 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,14 @@
/*
* 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 NotificationLevel extends Level {
public static final Level NOTIFICATION = new NotificationLevel("NOTIFICATION", 840);
protected NotificationLevel(String name, int value) {
super(name, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,40 @@ public void config(String msg, Object... params) {
logger.logp(Level.CONFIG, details.clazz, details.method, msg, params);
}
}


/**
* Logs a message which requires parameters at the TODO level.
*
* @param msg the message
* @param params the objects to use to fill in the message
*/
@SuppressWarnings("java:S1135")
public void todo(String msg, Object... params) {
if (isToDoEnabled()) {
CallerDetails details = inferCaller();
logger.logp(ToDoLevel.TODO, details.clazz, details.method, msg, params);
}
}

/**
* Logs a message which requires parameters at the NOTIFICATION level.
*
* @param msg the message
* @param params the objects to use to fill in the message
*/
public void notification(String msg, Object... params) {
if (isNotificationEnabled()) {
CallerDetails details = inferCaller();
logger.logp(NotificationLevel.NOTIFICATION, details.clazz, details.method, msg, params);
}
}

/**
* Logs a message which requires parameters at the DEPRECATION level.
*
* @param msg the message
* @param params the objects to use to fill in the message
*/
public void deprecation(String msg, Object... params) {
if (isDeprecationEnabled()) {
CallerDetails details = inferCaller();
Expand Down Expand Up @@ -316,6 +349,25 @@ public boolean isConfigEnabled() {
return logger.isLoggable(Level.CONFIG);
}

/**
* Checks if a message at TODO level would actually be logged.
*
* @return whether the TODO level is enabled
*/
@SuppressWarnings("java:S1135")
public boolean isToDoEnabled() {
return logger.isLoggable(ToDoLevel.TODO);
}

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

/**
* Checks if a message at DEPRECATION level would actually be logged.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package oracle.weblogic.deploy.logging;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.logging.Formatter;
Expand Down Expand Up @@ -59,6 +60,8 @@ public SummaryHandler() {

this.bufferSize = getMemoryBufferSize(CLASS + SIZE_PROPERTY);

addLevelHandler(ToDoLevel.TODO);
addLevelHandler(NotificationLevel.NOTIFICATION);
addLevelHandler(DeprecationLevel.DEPRECATION);
addLevelHandler(Level.WARNING);
addLevelHandler(Level.SEVERE);
Expand Down Expand Up @@ -130,10 +133,16 @@ public synchronized void logEnd(WLSDeployContext modelContext) {
LOGGER.entering(modelContext, CLASS, METHOD);
this.context = modelContext;
summaryHead(outputTargetHandler);
LevelHandler todoHandler = null;
for (LevelHandler handler : handlers) {
handler.push();
if (handler.getLevel() != ToDoLevel.TODO) {
handler.push();
} else {
todoHandler = handler;
}
}
summaryTail(outputTargetHandler);
summaryToDo(outputTargetHandler, todoHandler);
LOGGER.exiting(CLASS, METHOD);
}

Expand Down Expand Up @@ -220,15 +229,33 @@ private void summaryHead(Handler handler) {
private void summaryTail(Handler handler) {
StringBuilder buffer = new StringBuilder();
try (java.util.Formatter fmt = new java.util.Formatter(buffer)) {
for (LevelHandler levelHandler : handlers) {
if (levelHandler.getTotalRecords() >= 0) {
fmt.format(" %1$s : %2$,5d", levelHandler.getLevel().getName(), levelHandler.getTotalRecords());
List<LevelHandler> priorityOrderHandlers = new ArrayList<>(handlers);
Collections.reverse(priorityOrderHandlers);

for (LevelHandler levelHandler : priorityOrderHandlers) {
Level handlerLevel = levelHandler.getLevel();

if (handlerLevel == Level.WARNING || handlerLevel == Level.SEVERE) {
if (levelHandler.getTotalRecords() >= 0) {
fmt.format(" %1$s : %2$,4d", levelHandler.getLevel().getName(), levelHandler.getTotalRecords());
}
} else if ((handlerLevel == DeprecationLevel.DEPRECATION ||
handlerLevel == NotificationLevel.NOTIFICATION) && levelHandler.getTotalRecords() > 0) {
fmt.format(" %1$s : %2$,4d", levelHandler.getLevel().getName(), levelHandler.getTotalRecords());
}
}
}
handler.publish(getLogRecord("WLSDPLY-21002", buffer));
}

private void summaryToDo(Handler handler, LevelHandler todoHandler) {
if (todoHandler == null || todoHandler.getTotalRecords() == 0) {
return;
}
handler.publish(getLogRecord("WLSDPLY-06031"));
todoHandler.push();
}

private int getMemoryBufferSize(String sizePropertyName) {
String sizePropertyValue = LogManager.getLogManager().getProperty(sizePropertyName);

Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/oracle/weblogic/deploy/logging/ToDoLevel.java
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 ToDoLevel extends Level {
public static final Level TODO = new ToDoLevel("TODO", 820);

protected ToDoLevel(String name, int value) {
super(name, value);
}
}
57 changes: 21 additions & 36 deletions core/src/main/python/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,48 +539,33 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
return model


def __remote_report(model_context):
def __generate_remote_report_json(model_context):
_method_name = '__remote_report'

if not model_context.is_remote():
if not model_context.is_remote() or not os.environ.has_key(_store_result_environment_variable):
return

remote_map = discoverer.remote_dict

# write JSON output if the __WLSDEPLOY_STORE_RESULT__ environment variable is set.
# write to the file before the stdout so any logging messages come first.
if os.environ.has_key(_store_result_environment_variable):
store_path = os.environ.get(_store_result_environment_variable)
__logger.info('WLSDPLY-06034', store_path, class_name=_class_name, method_name=_method_name)
missing_archive_entries = []
for key in remote_map:
archive_map = remote_map[key]
missing_archive_entries.append({
'sourceFile': key,
'path': archive_map[discoverer.REMOTE_ARCHIVE_PATH],
'type': archive_map[discoverer.REMOTE_TYPE]
})
result_root = PyOrderedDict()
result_root['missingArchiveEntries'] = missing_archive_entries
try:
json_translator.PythonToJson(result_root).write_to_json_file(store_path)
except JsonException, ex:
__logger.warning('WLSDPLY-06035', _store_result_environment_variable, ex.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)

# write to stdout
print('')
if len(remote_map) == 0:
message = exception_helper.get_message('WLSDPLY-06030')
else:
message = exception_helper.get_message('WLSDPLY-06031')
print(message)
print('')
remote_map = discoverer.remote_dict

store_path = os.environ.get(_store_result_environment_variable)
__logger.info('WLSDPLY-06034', store_path, class_name=_class_name, method_name=_method_name)
missing_archive_entries = []
for key in remote_map:
other_map = remote_map[key]
wls_archive = other_map[discoverer.REMOTE_ARCHIVE_PATH]
print(key, ' ', wls_archive)
print('')
archive_map = remote_map[key]
missing_archive_entries.append({
'sourceFile': key,
'path': archive_map[discoverer.REMOTE_ARCHIVE_PATH],
'type': archive_map[discoverer.REMOTE_TYPE]
})
result_root = PyOrderedDict()
result_root['missingArchiveEntries'] = missing_archive_entries
try:
json_translator.PythonToJson(result_root).write_to_json_file(store_path)
except JsonException, ex:
__logger.warning('WLSDPLY-06035', _store_result_environment_variable, ex.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)


def main(model_context):
Expand Down Expand Up @@ -623,7 +608,7 @@ def main(model_context):

model = __check_and_customize_model(model, model_context, aliases, credential_injector, extra_tokens)

__remote_report(model_context)
__generate_remote_report_json(model_context)
except DiscoverException, ex:
__logger.severe('WLSDPLY-06011', _program_name, model_context.get_domain_name(),
model_context.get_domain_home(), ex.getLocalizedMessage(),
Expand Down
22 changes: 22 additions & 0 deletions core/src/main/python/wlsdeploy/logging/platform_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.logging.LogRecord as JLogRecord

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

import wlsdeploy.exception.exception_helper as exception_helper
import wlsdeploy.util.unicode_helper as str_helper
Expand Down Expand Up @@ -58,6 +60,12 @@ def is_config_enabled(self):
"""
return self.logger.isLoggable(JLevel.CONFIG)

def is_todo_enabled(self):
return self.logger.isLoggable(ToDoLevel.TODO)

def is_notification_enabled(self):
return self.logger.isLoggable(NotificationLevel.NOTIFICATION)

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

Expand Down Expand Up @@ -124,6 +132,20 @@ def config(self, message, *args, **kwargs):
record = self._get_log_record(JLevel.CONFIG, clazz, method, message, error, *args)
self.logger.log(record)

def todo(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(ToDoLevel.TODO, clazz, method, message, error, *args)
self.logger.log(record)

def notification(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(NotificationLevel.NOTIFICATION, 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)
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/python/wlsdeploy/tool/discover/discoverer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def add_to_remote_map(self, local_name, archive_name, file_type):
remote_dict[local_name][REMOTE_TYPE] = file_type
remote_dict[local_name][REMOTE_ARCHIVE_PATH] = archive_name

if file_type == 'FILE_STORE' or file_type == 'COHERENCE_PERSISTENCE_DIR':
_logger.todo('WLSDPLY-06042', file_type, archive_name)
else:
_logger.todo('WLSDPLY-06041', file_type, local_name, archive_name)

def discover_domain_mbean(self, model_top_folder_name):
"""
Discover the domain specific MBean and its configuration attributes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ WLSDPLY-06037=Target directory for model file argument {0} does not exist
WLSDPLY-06038=Unable to determine if secure mode is enabled for the domain: {0}
WLSDPLY-06039=This model was created using the WebLogic Deploy Tooling {0} {1} tool
WLSDPLY-06040=running in {0} mode against a domain using WebLogic Server {1}.
WLSDPLY-06041=Please collect the {0} from the remote file system location {1} and place it into the archive file at {2}.
WLSDPLY-06042=Please create the {0} in the archive file at {1}.

# discoverer.py
WLSDPLY-06100=Find attributes at location {0}
Expand Down