Skip to content

Commit

Permalink
remove empty [++]
Browse files Browse the repository at this point in the history
  • Loading branch information
querdenker2k committed Dec 20, 2023
1 parent 5809edb commit 47df82f
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/main/java/org/openhab/automation/jrule/internal/JRuleLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@
* @author Joseph (Seaside) Hagberg - Initial contribution
*/
public class JRuleLog {
private static final String PREFIX_INFO_LOG = "[{}] {}";
private static final String PREFIX_DEBUG_LOG = "[+{}+] {}";
private static final String PREFIX_WARN_LOG = "[{}] {}";
private static final String PREFIX_ERROR_LOG = "[{}] {}";
private static final String LOG_FORMAT = "{}{}";

public static void debug(Logger logger, String logPrefix, String message, Object... parameters) {
final FormattingTuple logMessage = MessageFormatter.arrayFormat(message, parameters);
logger.debug(PREFIX_DEBUG_LOG, logPrefix, logMessage.getMessage());
logger.debug(LOG_FORMAT, getPrefix(logPrefix, true), logMessage.getMessage());
}

public static void debug(Logger logger, String logPrefix, String message, String... parameters) {
Expand All @@ -38,17 +35,17 @@ public static void debug(Logger logger, String logPrefix, String message, String

public static void info(Logger logger, String logPrefix, String message, Object... parameters) {
final FormattingTuple logMessage = MessageFormatter.arrayFormat(message, parameters);
logger.info(PREFIX_INFO_LOG, logPrefix, logMessage.getMessage());
logger.info(LOG_FORMAT, getPrefix(logPrefix, false), logMessage.getMessage());
}

public static void warn(Logger logger, String logPrefix, String message, Object... parameters) {
final FormattingTuple logMessage = MessageFormatter.arrayFormat(message, parameters);
logger.warn(PREFIX_WARN_LOG, logPrefix, logMessage.getMessage());
logger.warn(LOG_FORMAT, getPrefix(logPrefix, false), logMessage.getMessage());
}

public static void error(Logger logger, String logPrefix, Throwable t, String message, Object... parameters) {
final FormattingTuple logMessage = MessageFormatter.arrayFormat(message, parameters);
final FormattingTuple finalLogmessage = MessageFormatter.format(PREFIX_ERROR_LOG,
final FormattingTuple finalLogmessage = MessageFormatter.format(LOG_FORMAT,
new String[] { logPrefix, logMessage.getMessage() });
error(logger, t, finalLogmessage.getMessage());
}
Expand All @@ -59,6 +56,17 @@ private static void error(Logger logger, Throwable t, String message) {

public static void error(Logger logger, String logPrefix, String message, Object... parameters) {
final FormattingTuple logMessage = MessageFormatter.arrayFormat(message, parameters);
logger.error(PREFIX_ERROR_LOG, logPrefix, logMessage.getMessage());
logger.error(LOG_FORMAT, getPrefix(logPrefix, false), logMessage.getMessage());
}

private static String getPrefix(String logPrefix, boolean debug) {
if (logPrefix.isBlank()) {
return "";
}
if (debug) {
return "[+%s+] ".formatted(logPrefix);
} else {
return "[%s] ".formatted(logPrefix);
}
}
}

0 comments on commit 47df82f

Please sign in to comment.