/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.apex.tools.common;
+import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
-
import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.text.StrBuilder;
import org.slf4j.ext.XLoggerFactory;
import org.slf4j.helpers.MessageFormatter;
/** Configuration for a collecting warning messages. */
public static final int CONFIG_COLLECT_WARNINGS = 0b0010;
+ // Input and output streams
+ private static final PrintStream ERR_STREAM = System.err;
+
/** The setting for message types, set using type flags. */
private int types;
return;
}
- final StrBuilder err = new StrBuilder();
+ final var err = new StringBuilder();
if (appName != null) {
err.append(this.getAppName()).append(": ");
}
err.append(MessageFormatter.arrayFormat(message, objects).getMessage());
if ((types & TYPE_ERROR) == TYPE_ERROR) {
- System.err.println(err.build());
+ ERR_STREAM.println(err.toString());
}
if ((configuration & CONFIG_COLLECT_ERRORS) == CONFIG_COLLECT_ERRORS) {
- errors.add(err.build());
+ errors.add(err.toString());
}
}
return;
}
- final StrBuilder warn = new StrBuilder();
+ final var warn = new StringBuilder();
if (appName != null) {
warn.append(this.getAppName()).append(": ");
}
warn.append(MessageFormatter.arrayFormat(message, objects).getMessage());
if ((types & TYPE_WARNING) == TYPE_WARNING) {
- System.err.println(warn.build());
+ ERR_STREAM.println(warn.toString());
}
if ((configuration & CONFIG_COLLECT_WARNINGS) == CONFIG_COLLECT_WARNINGS) {
- warnings.add(warn.build());
+ warnings.add(warn.toString());
}
}
if ((types & TYPE_INFO) == TYPE_INFO) {
if (appName != null) {
- System.err.print(appName + ": ");
+ ERR_STREAM.print(appName + ": ");
}
- System.err.println(MessageFormatter.arrayFormat(message, objects).getMessage());
+ ERR_STREAM.println(MessageFormatter.arrayFormat(message, objects).getMessage());
}
}
if ((types & TYPE_PROGRESS) == TYPE_PROGRESS) {
if (appName != null) {
- System.err.print(appName + ": ");
+ ERR_STREAM.print(appName + ": ");
}
- System.err.print("progress: ");
- System.err.println(MessageFormatter.arrayFormat(message, objects).getMessage());
+ ERR_STREAM.print("progress: ");
+ ERR_STREAM.println(MessageFormatter.arrayFormat(message, objects).getMessage());
}
}
if ((types & TYPE_DEBUG) == TYPE_DEBUG) {
if (appName != null) {
- System.err.print(appName + ": ");
+ ERR_STREAM.print(appName + ": ");
}
- System.err.print("debug: ");
- System.err.println(MessageFormatter.arrayFormat(message, objects).getMessage());
+ ERR_STREAM.print("debug: ");
+ ERR_STREAM.println(MessageFormatter.arrayFormat(message, objects).getMessage());
}
}
if ((types & TYPE_TRACE) == TYPE_TRACE) {
if (appName != null) {
- System.err.print(appName + ": ");
+ ERR_STREAM.print(appName + ": ");
}
- System.err.print("trace: ");
- System.err.println(MessageFormatter.arrayFormat(message, objects).getMessage());
+ ERR_STREAM.print("trace: ");
+ ERR_STREAM.println(MessageFormatter.arrayFormat(message, objects).getMessage());
}
}
if ((types & TYPE_STACKTRACE) == TYPE_STACKTRACE) {
if (appName != null) {
- System.err.print(appName + ": ");
+ ERR_STREAM.print(appName + ": ");
}
- System.err.println(" exception message: " + exception.getMessage());
+ ERR_STREAM.println(" exception message: " + exception.getMessage());
if (exception.getCause() != null) {
- System.err.println(" exception cause: " + exception.getCause());
+ ERR_STREAM.println(" exception cause: " + exception.getCause());
}
- System.err.println("for exception stack trace, please refer logs.");
+ ERR_STREAM.println("for exception stack trace, please refer logs.");
XLoggerFactory.getXLogger(Console.class).error("stacktrace", exception);
}
}