Skip to content

Commit ea5725d

Browse files
Adding new log levels and cleaning up the totals line (#1391)
* adding new log levels and cleaning up the totals line * sonar cleanup * switching remote report to use logger
1 parent ad8be75 commit ea5725d

File tree

8 files changed

+163
-41
lines changed

8 files changed

+163
-41
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2023, 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.Level;
8+
9+
public class NotificationLevel extends Level {
10+
public static final Level NOTIFICATION = new NotificationLevel("NOTIFICATION", 840);
11+
protected NotificationLevel(String name, int value) {
12+
super(name, value);
13+
}
14+
}

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,40 @@ public void config(String msg, Object... params) {
6666
logger.logp(Level.CONFIG, details.clazz, details.method, msg, params);
6767
}
6868
}
69-
69+
70+
/**
71+
* Logs a message which requires parameters at the TODO level.
72+
*
73+
* @param msg the message
74+
* @param params the objects to use to fill in the message
75+
*/
76+
@SuppressWarnings("java:S1135")
77+
public void todo(String msg, Object... params) {
78+
if (isToDoEnabled()) {
79+
CallerDetails details = inferCaller();
80+
logger.logp(ToDoLevel.TODO, details.clazz, details.method, msg, params);
81+
}
82+
}
83+
84+
/**
85+
* Logs a message which requires parameters at the NOTIFICATION level.
86+
*
87+
* @param msg the message
88+
* @param params the objects to use to fill in the message
89+
*/
90+
public void notification(String msg, Object... params) {
91+
if (isNotificationEnabled()) {
92+
CallerDetails details = inferCaller();
93+
logger.logp(NotificationLevel.NOTIFICATION, details.clazz, details.method, msg, params);
94+
}
95+
}
96+
97+
/**
98+
* Logs a message which requires parameters at the DEPRECATION level.
99+
*
100+
* @param msg the message
101+
* @param params the objects to use to fill in the message
102+
*/
70103
public void deprecation(String msg, Object... params) {
71104
if (isDeprecationEnabled()) {
72105
CallerDetails details = inferCaller();
@@ -316,6 +349,25 @@ public boolean isConfigEnabled() {
316349
return logger.isLoggable(Level.CONFIG);
317350
}
318351

352+
/**
353+
* Checks if a message at TODO level would actually be logged.
354+
*
355+
* @return whether the TODO level is enabled
356+
*/
357+
@SuppressWarnings("java:S1135")
358+
public boolean isToDoEnabled() {
359+
return logger.isLoggable(ToDoLevel.TODO);
360+
}
361+
362+
/**
363+
* Checks if a message at NOTIFICATION level would actually be logged.
364+
*
365+
* @return whether the NOTIFICATION level is enabled
366+
*/
367+
public boolean isNotificationEnabled() {
368+
return logger.isLoggable(NotificationLevel.NOTIFICATION);
369+
}
370+
319371
/**
320372
* Checks if a message at DEPRECATION level would actually be logged.
321373
*

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package oracle.weblogic.deploy.logging;
66

77
import java.util.ArrayList;
8+
import java.util.Collections;
89
import java.util.List;
910
import java.util.Properties;
1011
import java.util.logging.Formatter;
@@ -59,6 +60,8 @@ public SummaryHandler() {
5960

6061
this.bufferSize = getMemoryBufferSize(CLASS + SIZE_PROPERTY);
6162

63+
addLevelHandler(ToDoLevel.TODO);
64+
addLevelHandler(NotificationLevel.NOTIFICATION);
6265
addLevelHandler(DeprecationLevel.DEPRECATION);
6366
addLevelHandler(Level.WARNING);
6467
addLevelHandler(Level.SEVERE);
@@ -130,10 +133,16 @@ public synchronized void logEnd(WLSDeployContext modelContext) {
130133
LOGGER.entering(modelContext, CLASS, METHOD);
131134
this.context = modelContext;
132135
summaryHead(outputTargetHandler);
136+
LevelHandler todoHandler = null;
133137
for (LevelHandler handler : handlers) {
134-
handler.push();
138+
if (handler.getLevel() != ToDoLevel.TODO) {
139+
handler.push();
140+
} else {
141+
todoHandler = handler;
142+
}
135143
}
136144
summaryTail(outputTargetHandler);
145+
summaryToDo(outputTargetHandler, todoHandler);
137146
LOGGER.exiting(CLASS, METHOD);
138147
}
139148

@@ -220,15 +229,33 @@ private void summaryHead(Handler handler) {
220229
private void summaryTail(Handler handler) {
221230
StringBuilder buffer = new StringBuilder();
222231
try (java.util.Formatter fmt = new java.util.Formatter(buffer)) {
223-
for (LevelHandler levelHandler : handlers) {
224-
if (levelHandler.getTotalRecords() >= 0) {
225-
fmt.format(" %1$s : %2$,5d", levelHandler.getLevel().getName(), levelHandler.getTotalRecords());
232+
List<LevelHandler> priorityOrderHandlers = new ArrayList<>(handlers);
233+
Collections.reverse(priorityOrderHandlers);
234+
235+
for (LevelHandler levelHandler : priorityOrderHandlers) {
236+
Level handlerLevel = levelHandler.getLevel();
237+
238+
if (handlerLevel == Level.WARNING || handlerLevel == Level.SEVERE) {
239+
if (levelHandler.getTotalRecords() >= 0) {
240+
fmt.format(" %1$s : %2$,4d", levelHandler.getLevel().getName(), levelHandler.getTotalRecords());
241+
}
242+
} else if ((handlerLevel == DeprecationLevel.DEPRECATION ||
243+
handlerLevel == NotificationLevel.NOTIFICATION) && levelHandler.getTotalRecords() > 0) {
244+
fmt.format(" %1$s : %2$,4d", levelHandler.getLevel().getName(), levelHandler.getTotalRecords());
226245
}
227246
}
228247
}
229248
handler.publish(getLogRecord("WLSDPLY-21002", buffer));
230249
}
231250

251+
private void summaryToDo(Handler handler, LevelHandler todoHandler) {
252+
if (todoHandler == null || todoHandler.getTotalRecords() == 0) {
253+
return;
254+
}
255+
handler.publish(getLogRecord("WLSDPLY-06031"));
256+
todoHandler.push();
257+
}
258+
232259
private int getMemoryBufferSize(String sizePropertyName) {
233260
String sizePropertyValue = LogManager.getLogManager().getProperty(sizePropertyName);
234261

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2023, 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.Level;
8+
9+
public class ToDoLevel extends Level {
10+
public static final Level TODO = new ToDoLevel("TODO", 820);
11+
12+
protected ToDoLevel(String name, int value) {
13+
super(name, value);
14+
}
15+
}

core/src/main/python/discover.py

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -539,48 +539,33 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
539539
return model
540540

541541

542-
def __remote_report(model_context):
542+
def __generate_remote_report_json(model_context):
543543
_method_name = '__remote_report'
544544

545-
if not model_context.is_remote():
545+
if not model_context.is_remote() or not os.environ.has_key(_store_result_environment_variable):
546546
return
547547

548-
remote_map = discoverer.remote_dict
549-
550548
# write JSON output if the __WLSDEPLOY_STORE_RESULT__ environment variable is set.
551549
# write to the file before the stdout so any logging messages come first.
552-
if os.environ.has_key(_store_result_environment_variable):
553-
store_path = os.environ.get(_store_result_environment_variable)
554-
__logger.info('WLSDPLY-06034', store_path, class_name=_class_name, method_name=_method_name)
555-
missing_archive_entries = []
556-
for key in remote_map:
557-
archive_map = remote_map[key]
558-
missing_archive_entries.append({
559-
'sourceFile': key,
560-
'path': archive_map[discoverer.REMOTE_ARCHIVE_PATH],
561-
'type': archive_map[discoverer.REMOTE_TYPE]
562-
})
563-
result_root = PyOrderedDict()
564-
result_root['missingArchiveEntries'] = missing_archive_entries
565-
try:
566-
json_translator.PythonToJson(result_root).write_to_json_file(store_path)
567-
except JsonException, ex:
568-
__logger.warning('WLSDPLY-06035', _store_result_environment_variable, ex.getLocalizedMessage(),
569-
class_name=_class_name, method_name=_method_name)
570-
571-
# write to stdout
572-
print('')
573-
if len(remote_map) == 0:
574-
message = exception_helper.get_message('WLSDPLY-06030')
575-
else:
576-
message = exception_helper.get_message('WLSDPLY-06031')
577-
print(message)
578-
print('')
550+
remote_map = discoverer.remote_dict
551+
552+
store_path = os.environ.get(_store_result_environment_variable)
553+
__logger.info('WLSDPLY-06034', store_path, class_name=_class_name, method_name=_method_name)
554+
missing_archive_entries = []
579555
for key in remote_map:
580-
other_map = remote_map[key]
581-
wls_archive = other_map[discoverer.REMOTE_ARCHIVE_PATH]
582-
print(key, ' ', wls_archive)
583-
print('')
556+
archive_map = remote_map[key]
557+
missing_archive_entries.append({
558+
'sourceFile': key,
559+
'path': archive_map[discoverer.REMOTE_ARCHIVE_PATH],
560+
'type': archive_map[discoverer.REMOTE_TYPE]
561+
})
562+
result_root = PyOrderedDict()
563+
result_root['missingArchiveEntries'] = missing_archive_entries
564+
try:
565+
json_translator.PythonToJson(result_root).write_to_json_file(store_path)
566+
except JsonException, ex:
567+
__logger.warning('WLSDPLY-06035', _store_result_environment_variable, ex.getLocalizedMessage(),
568+
class_name=_class_name, method_name=_method_name)
584569

585570

586571
def main(model_context):
@@ -623,7 +608,7 @@ def main(model_context):
623608

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

626-
__remote_report(model_context)
611+
__generate_remote_report_json(model_context)
627612
except DiscoverException, ex:
628613
__logger.severe('WLSDPLY-06011', _program_name, model_context.get_domain_name(),
629614
model_context.get_domain_home(), ex.getLocalizedMessage(),

core/src/main/python/wlsdeploy/logging/platform_logger.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.logging.LogRecord as JLogRecord
1313

1414
import oracle.weblogic.deploy.logging.DeprecationLevel as DeprecationLevel
15+
import oracle.weblogic.deploy.logging.NotificationLevel as NotificationLevel
16+
import oracle.weblogic.deploy.logging.ToDoLevel as ToDoLevel
1517

1618
import wlsdeploy.exception.exception_helper as exception_helper
1719
import wlsdeploy.util.unicode_helper as str_helper
@@ -58,6 +60,12 @@ def is_config_enabled(self):
5860
"""
5961
return self.logger.isLoggable(JLevel.CONFIG)
6062

63+
def is_todo_enabled(self):
64+
return self.logger.isLoggable(ToDoLevel.TODO)
65+
66+
def is_notification_enabled(self):
67+
return self.logger.isLoggable(NotificationLevel.NOTIFICATION)
68+
6169
def is_deprecation_enabled(self):
6270
return self.logger.isLoggable(DeprecationLevel.DEPRECATION)
6371

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

135+
def todo(self, message, *args, **kwargs):
136+
method = kwargs.pop('method_name', None)
137+
clazz = kwargs.pop('class_name', None)
138+
error = kwargs.pop('error', None)
139+
record = self._get_log_record(ToDoLevel.TODO, clazz, method, message, error, *args)
140+
self.logger.log(record)
141+
142+
def notification(self, message, *args, **kwargs):
143+
method = kwargs.pop('method_name', None)
144+
clazz = kwargs.pop('class_name', None)
145+
error = kwargs.pop('error', None)
146+
record = self._get_log_record(NotificationLevel.NOTIFICATION, clazz, method, message, error, *args)
147+
self.logger.log(record)
148+
127149
def deprecation(self, message, *args, **kwargs):
128150
method = kwargs.pop('method_name', None)
129151
clazz = kwargs.pop('class_name', None)

core/src/main/python/wlsdeploy/tool/discover/discoverer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ def add_to_remote_map(self, local_name, archive_name, file_type):
7575
remote_dict[local_name][REMOTE_TYPE] = file_type
7676
remote_dict[local_name][REMOTE_ARCHIVE_PATH] = archive_name
7777

78+
if file_type == 'FILE_STORE' or file_type == 'COHERENCE_PERSISTENCE_DIR':
79+
_logger.todo('WLSDPLY-06042', file_type, archive_name)
80+
else:
81+
_logger.todo('WLSDPLY-06041', file_type, local_name, archive_name)
82+
7883
def discover_domain_mbean(self, model_top_folder_name):
7984
"""
8085
Discover the domain specific MBean and its configuration attributes.

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ WLSDPLY-06037=Target directory for model file argument {0} does not exist
633633
WLSDPLY-06038=Unable to determine if secure mode is enabled for the domain: {0}
634634
WLSDPLY-06039=This model was created using the WebLogic Deploy Tooling {0} {1} tool
635635
WLSDPLY-06040=running in {0} mode against a domain using WebLogic Server {1}.
636+
WLSDPLY-06041=Please collect the {0} from the remote file system location {1} and place it into the archive file at {2}.
637+
WLSDPLY-06042=Please create the {0} in the archive file at {1}.
636638

637639
# discoverer.py
638640
WLSDPLY-06100=Find attributes at location {0}

0 commit comments

Comments
 (0)