diff --git a/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java b/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java
index 0a36a158..3234591c 100644
--- a/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java
+++ b/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java
@@ -216,19 +216,19 @@ public final class EngineConfiguration extends Configuration {
private String loggerTemplate;
/**
- * If enabled, the JVM will immediately shutdown on an engine crash. This will prevent shutdown hooks from executing.
- * Note: This will also prevent Jansi and potentially other libraries from removing temporary native libraries at shutdown.
+ * Contains how fast the logging thread will poll for queued messages.
+ * Only applies if {@code optimizeLogging} is turned on.
*
- * @see CrashHandler
- * @since v1-alpha0
+ * @see #optimizeLogging
+ * @since v1-alpha1
* -- GETTER --
- * Gets the value for {@link #loggerImmediateShutdown}.
+ * Gets the value for {@link #loggerPollingSpeed}.
*
* @return variable value
- * @see #loggerImmediateShutdown
- * @since v1-alpha0
+ * @see #loggerPollingSpeed
+ * @since v1-alpha1
*/
- private boolean loggerImmediateShutdown;
+ private int loggerPollingSpeed;
/**
* If enabled, will force the {@link Logger} and {@link CrashHandler} to use the standard output
@@ -245,19 +245,34 @@ public final class EngineConfiguration extends Configuration {
private boolean loggerForceStandardOutput;
/**
- * Contains how fast the logging thread will poll for queued messages.
- * Only applies if {@code optimizeLogging} is turned on.
+ * If enabled, will enable support for printing log messages on multiple lines.
+ * By enabling this configuration setting, logger throughput will be decreased slightly when encountering a log message with newlines found in it.
+ * This performance hit is negligible though and should not affect application performance, especially with logger multi-threading turned on (see {@link #optimizeLogging}).
*
- * @see #optimizeLogging
- * @since v1-alpha1
+ * @since v1-alpha4
* -- GETTER --
- * Gets the value for {@link #loggerForceStandardOutput}.
+ * Gets the value for {@link #loggerEnableNewlineSupport}.
*
* @return variable value
- * @see #loggerForceStandardOutput
- * @since v1-alpha1
+ * @see #loggerEnableNewlineSupport
+ * @since v1-alpha4
*/
- private int loggerPollingSpeed;
+ private boolean loggerEnableNewlineSupport;
+
+ /**
+ * If enabled, the JVM will immediately shutdown on an engine crash. This will prevent shutdown hooks from executing.
+ * Note: This will also prevent Jansi and potentially other libraries from removing temporary native libraries at shutdown.
+ *
+ * @see CrashHandler
+ * @since v1-alpha0
+ * -- GETTER --
+ * Gets the value for {@link #loggerImmediateShutdown}.
+ *
+ * @return variable value
+ * @see #loggerImmediateShutdown
+ * @since v1-alpha0
+ */
+ private boolean loggerImmediateShutdown;
/**
* Will truncate the path of types when using their {@code toString} method.
@@ -325,9 +340,10 @@ public final class EngineConfiguration extends Configuration {
}
}
case "loggerTemplate" -> loggerTemplate = parser.getString(group + property);
- case "loggerImmediateShutdown" -> loggerImmediateShutdown = parser.getBoolean(group + property);
- case "loggerForceStandardOutput" -> loggerForceStandardOutput = parser.getBoolean(group + property);
case "loggerPollingSpeed" -> loggerPollingSpeed = parser.getInteger(group + property, true);
+ case "loggerForceStandardOutput" -> loggerForceStandardOutput = parser.getBoolean(group + property);
+ case "loggerEnableNewlineSupport" -> loggerEnableNewlineSupport = parser.getBoolean(group + property);
+ case "loggerImmediateShutdown" -> loggerImmediateShutdown = parser.getBoolean(group + property);
case "hideFullTypePath" -> hideFullTypePath = parser.getBoolean(group + property);
}
@@ -359,9 +375,10 @@ public final class EngineConfiguration extends Configuration {
loggerLevel = LogLevel.INFORMATIONAL;
loggerTemplate = "%log_color_primary%[%time_hour%:%time_minute%:%time_second%] [%log_level% %log_path%%log_metadata%] %log_message_prefix%%log_color_primary%%log_color_secondary%%log_message%";
- loggerImmediateShutdown = false;
- loggerForceStandardOutput = false;
loggerPollingSpeed = 5;
+ loggerForceStandardOutput = false;
+ loggerEnableNewlineSupport = true;
+ loggerImmediateShutdown = false;
hideFullTypePath = false;
}
@@ -382,9 +399,10 @@ public final class EngineConfiguration extends Configuration {
case "loggerLevel" -> { return loggerLevel; }
case "loggerTemplate" -> { return loggerTemplate; }
- case "loggerImmediateShutdown" -> { return loggerImmediateShutdown; }
- case "loggerForceStandardOutput" -> { return loggerForceStandardOutput; }
case "loggerPollingSpeed" -> { return loggerPollingSpeed; }
+ case "loggerForceStandardOutput" -> { return loggerForceStandardOutput; }
+ case "loggerEnableNewlineSupport" -> { return loggerEnableNewlineSupport; }
+ case "loggerImmediateShutdown" -> { return loggerImmediateShutdown; }
case "hideFullTypePath" -> { return hideFullTypePath; }
default -> { return null; }
diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java b/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java
index 5f69795d..a62a0e3c 100644
--- a/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java
+++ b/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java
@@ -212,7 +212,7 @@ public final class Logger {
format = new LogPath(issuerClass).replace(format);
// Handle newlines
- if (message.contains("\n"))
+ if (EngineConfiguration.getInstance().isLoggerEnableNewlineSupport() && message.contains("\n"))
try (Scanner scanner = new Scanner(message)) {
int indexPrefix = format.indexOf("%log_message_prefix%");
int indexMessage = format.indexOf("%log_message%");
@@ -233,7 +233,6 @@ public final class Logger {
.replace("%log_color_secondary%", ""), false
).getClean().length());
-
while (scanner.hasNextLine()) {
if (formatNew.isEmpty())
formatNew.append(format, 0, indexPrefix == -1 ? indexMessage : indexPrefix);
@@ -254,7 +253,7 @@ public final class Logger {
// No newline found, use performance-efficient replacing
format = format
.replace("%log_message_prefix%", "")
- .replace("%log_message%", message);
+ .replace("%log_message%", message.replace("\n", "\\n"));
// Replace placeholders involving colors
format = new LogColorPrimary(level).replace(format);