Skip to content
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

Dev/1.15.9 #85

Merged
merged 3 commits into from
Dec 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- PROJECT NAME -->
<name>Ewon Flexy Extensions Library</name>
<!-- PROJECT VERSION -->
<version>1.15.8</version>
<version>1.15.9</version>
<!-- PROJECT GROUP ID (PARENT PACKAGE) -->
<groupId>com.hms_networks.americas.sc</groupId>
<!-- PROJECT ARTIFACT ID (ROOT PACKAGE NAME) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
*/
public abstract class AbstractConnectorConfig extends ConfigFile {

/**
* The uniqueness prefix appended to the key of a missing field to ensure that the log event is
* uniquely keyed in the log once system.
*
* <p>ACCLMF = Abstract Connector Config Log Missing Field
*
* @since 1.15.9
*/
private static final String LOG_ONCE_UNIQUENESS_PREFIX_ACCLMF = "ACCLMF_";

/**
* The path to the configuration file.
*
Expand Down Expand Up @@ -538,12 +548,33 @@ public JSONObject getDefaultConfigurationObject() throws JSONException {
* @since 1.15.2
*/
protected void logMissingField(String missingKey, String defaultValue) {
Logger.LOG_WARN(
final boolean suppressAdditional = false;
logMissingField(missingKey, defaultValue, suppressAdditional);
}

/**
* Logs a missing field in the configuration file along with the default value that will be used.
* If the specified {@code suppressAdditional} boolean is {@code true}, the event will only be
* logged once (tracked by the key).
*
* @param missingKey the JSON key of the field that was missing/could not be found
* @param defaultValue the default value that will be used
* @param logOnce whether to log only once and suppress additional log events for the same key
* @since 1.15.9
*/
protected void logMissingField(String missingKey, String defaultValue, boolean logOnce) {
String logMessage =
"The "
+ missingKey
+ " option was not found in the configuration file. Using default value of "
+ defaultValue
+ ".");
+ ".";
if (logOnce) {
final String logOnceKey = LOG_ONCE_UNIQUENESS_PREFIX_ACCLMF + missingKey;
Logger.LOG_WARN_ONCE(logOnceKey, logMessage);
} else {
Logger.LOG_WARN(logMessage);
}
}

/**
Expand All @@ -553,7 +584,26 @@ protected void logMissingField(String missingKey, String defaultValue) {
* @since 1.15.2
*/
protected void logMissingField(String missingKey) {
Logger.LOG_WARN("The " + missingKey + " option was not found in the configuration file.");
final boolean suppressAdditional = false;
logMissingField(missingKey, suppressAdditional);
}

/**
* Logs a missing field in the configuration file. If the specified {@code suppressAdditional}
* boolean is {@code true}, the event will only be logged once (tracked by the key).
*
* @param missingKey the JSON key of the field that was missing/could not be found
* @param logOnce whether to log only once and suppress additional log events for the same key
* @since 1.15.9
*/
protected void logMissingField(String missingKey, boolean logOnce) {
String logMessage = "The " + missingKey + " option was not found in the configuration file.";
if (logOnce) {
final String logOnceKey = LOG_ONCE_UNIQUENESS_PREFIX_ACCLMF + missingKey;
Logger.LOG_WARN_ONCE(logOnceKey, logMessage);
} else {
Logger.LOG_WARN(logMessage);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;

/**
* Logger.java
Expand Down Expand Up @@ -80,6 +82,17 @@ public class Logger {
/** Queue of unprinted logs. */
private static LogQueue logQueue;

/**
* Set for tracking whether a specific log has been outputted. This is used to prevent spamming
* the log with the same message.
*
* <p>If the log has already been outputted, its key will be in the set, otherwise it will not be
* present.
*
* @since 1.15.9
*/
private static final Set logOnceList = new HashSet(); // Set<String>

/**
* Enable logging to Flexy's realtime logs.
*
Expand Down Expand Up @@ -311,6 +324,24 @@ public static void LOG_DEBUG(String logString) {
LOG(LOG_LEVEL_DEBUG, logString);
}

/**
* Log a string with the debug log level at most once (tracked by specified log key).
*
* <p>The specified log key must be unique for each log event that should only be logged once. If
* the same log key is used for multiple log events, only the first log event will be logged,
* regardless of the message.
*
* @param logKey key for the log event
* @param logString string to log
* @since 1.15.9
*/
public static void LOG_DEBUG_ONCE(String logKey, String logString) {
if (!getLoggedOnce(logKey)) {
setLoggedOnce(logKey, true);
LOG(LOG_LEVEL_DEBUG, logString);
}
}

/**
* Log a string and exception with the debug log level.
*
Expand Down Expand Up @@ -348,6 +379,24 @@ public static void LOG_INFO(String logString) {
LOG(LOG_LEVEL_INFO, logString);
}

/**
* Log a string with the info log level at most once (tracked by specified log key).
*
* <p>The specified log key must be unique for each log event that should only be logged once. If
* the same log key is used for multiple log events, only the first log event will be logged,
* regardless of the message.
*
* @param logKey key for the log event
* @param logString string to log
* @since 1.15.9
*/
public static void LOG_INFO_ONCE(String logKey, String logString) {
if (!getLoggedOnce(logKey)) {
setLoggedOnce(logKey, true);
LOG(LOG_LEVEL_INFO, logString);
}
}

/**
* Log a string and exception with the info log level.
*
Expand Down Expand Up @@ -384,6 +433,24 @@ public static void LOG_WARN(String logString) {
LOG(LOG_LEVEL_WARN, logString);
}

/**
* Log a string with the warning log level at most once (tracked by specified log key).
*
* <p>The specified log key must be unique for each log event that should only be logged once. If
* the same log key is used for multiple log events, only the first log event will be logged,
* regardless of the message.
*
* @param logKey key for the log event
* @param logString string to log
* @since 1.15.9
*/
public static void LOG_WARN_ONCE(String logKey, String logString) {
if (!getLoggedOnce(logKey)) {
setLoggedOnce(logKey, true);
LOG(LOG_LEVEL_WARN, logString);
}
}

/**
* Log a string and exception with the warning log level.
*
Expand Down Expand Up @@ -420,6 +487,24 @@ public static void LOG_SERIOUS(String logString) {
LOG(LOG_LEVEL_SERIOUS, logString);
}

/**
* Log a string with the serious log level at most once (tracked by specified log key).
*
* <p>The specified log key must be unique for each log event that should only be logged once. If
* the same log key is used for multiple log events, only the first log event will be logged,
* regardless of the message.
*
* @param logKey key for the log event
* @param logString string to log
* @since 1.15.9
*/
public static void LOG_SERIOUS_ONCE(String logKey, String logString) {
if (!getLoggedOnce(logKey)) {
setLoggedOnce(logKey, true);
LOG(LOG_LEVEL_SERIOUS, logString);
}
}

/**
* Log a string and exception with the serious log level.
*
Expand Down Expand Up @@ -457,6 +542,24 @@ public static void LOG_CRITICAL(String logString) {
LOG(LOG_LEVEL_CRITICAL, logString);
}

/**
* Log a string with the critical log level at most once (tracked by specified log key).
*
* <p>The specified log key must be unique for each log event that should only be logged once. If
* the same log key is used for multiple log events, only the first log event will be logged,
* regardless of the message.
*
* @param logKey key for the log event
* @param logString string to log
* @since 1.15.9
*/
public static void LOG_CRITICAL_ONCE(String logKey, String logString) {
if (!getLoggedOnce(logKey)) {
setLoggedOnce(logKey, true);
LOG(LOG_LEVEL_CRITICAL, logString);
}
}

/**
* Log a string and exception with the critical log level.
*
Expand Down Expand Up @@ -491,4 +594,40 @@ public static void DUMP_LOG_QUEUE() {
LOG(LOG_LEVEL_CRITICAL, logQueue.poll());
}
}

/**
* Sets whether a specific log has been outputted. This is used to prevent spamming the log with
* the same message.
*
* <p>The specified log key must be unique for each log event that should only be logged once. If
* the same log key is used for multiple log events, only the first log event will be logged,
* regardless of the message.
*
* @param logKey key for the log event
* @param logOutputted boolean representing whether the log has been output (true) or not (false)
* @since 1.15.9
*/
public static void setLoggedOnce(String logKey, boolean logOutputted) {
if (logOutputted) {
logOnceList.add(logKey);
} else {
logOnceList.remove(logKey);
}
}

/**
* Gets a boolean indicating whether a specific log has been outputted. This is used to prevent
* spamming the log with the same message.
*
* <p>The specified log key must be unique for each log event that should only be logged once. If
* the same log key is used for multiple log events, only the first log event will be logged,
* regardless of the message.
*
* @param logKey key for the log event
* @return {@code true} if the log has been outputted, {@code false} otherwise
* @since 1.15.9
*/
public static boolean getLoggedOnce(String logKey) {
return logOnceList.contains(logKey);
it-hms marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extension classes include many supplemental features, and the addition
of new functionality which may not be present in the supported Java version.

@version 1.15.8
@version 1.15.9
@author HMS Networks, MU Americas Solution Center
</BODY>
</HTML>
2 changes: 1 addition & 1 deletion starting-files/jvmrun
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-heapsize 25M -classpath /usr/extensions-1.15.8-full.jar -emain com.hms_networks.americas.sc.extensions.ExtensionsMain
-heapsize 25M -classpath /usr/extensions-1.15.9-full.jar -emain com.hms_networks.americas.sc.extensions.ExtensionsMain
5 changes: 5 additions & 0 deletions web-docs/docs/02-CHANGELOG.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ sidebar_label: Change Log
toc_max_heading_level: 2
---

## Version 1.15.9
### Features
- Added log once methods to Logger.java to enable suppressing of duplicate log messages
- Added log once support to logMissingField methods in abstract connector framework config class

## Version 1.15.8
### Bug Fixes
- Removed redundant quotes from unit value in TagInfo.java based objects
Expand Down
2 changes: 1 addition & 1 deletion web-docs/docs/_partial/_pom_library.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ScDocusaurusConfig from "@site/ScDocusaurusConfig.js";
<dependency>
<groupId>com.hms_networks.americas.sc</groupId>
<artifactId>extensions</artifactId>
<version>1.15.8</version>
<version>1.15.9</version>
</dependency>
...
</dependencies>
Expand Down