diff --git a/lib/repo/ch/autumo/beetroot/autumo-beetroot/3.1.3/autumo-beetroot-3.1.3.jar b/lib/repo/ch/autumo/beetroot/autumo-beetroot/3.1.3/autumo-beetroot-3.1.3.jar index deb538aa..f4fad1ae 100644 Binary files a/lib/repo/ch/autumo/beetroot/autumo-beetroot/3.1.3/autumo-beetroot-3.1.3.jar and b/lib/repo/ch/autumo/beetroot/autumo-beetroot/3.1.3/autumo-beetroot-3.1.3.jar differ diff --git a/src/main/java/ch/autumo/beetroot/handler/system/LogHandler.java b/src/main/java/ch/autumo/beetroot/handler/system/LogHandler.java index c433f967..60cc464d 100644 --- a/src/main/java/ch/autumo/beetroot/handler/system/LogHandler.java +++ b/src/main/java/ch/autumo/beetroot/handler/system/LogHandler.java @@ -35,6 +35,7 @@ import ch.autumo.beetroot.logging.LogEventAppender; import ch.autumo.beetroot.server.message.ClientAnswer; import ch.autumo.beetroot.server.modules.log.LogFactory; +import ch.autumo.beetroot.utils.system.OS; import ch.autumo.beetroot.utils.web.Web; @@ -42,7 +43,7 @@ * Log extended handler. */ public class LogHandler extends NoConfigHandler { - + private static final Logger LOG = LoggerFactory.getLogger(LogHandler.class); /** Default log size . */ @@ -73,6 +74,7 @@ public LogHandler(String entity) { this.layout = PatternLayout.newBuilder() .withPattern(LOG_PATTERN) .withCharset(StandardCharsets.UTF_8) + .withDisableAnsi(false) .build(); } @@ -160,68 +162,108 @@ public void render(BeetRootHTTPSession session) { public String format(LogEvent event) { String formattedMessage = layout.toSerializable(event); - - // You can now post-process the formattedMessage if needed - formattedMessage = processCustomPatternReferences(formattedMessage, event); - + // Post-process the formattedMessage if needed + // formattedMessage = processCustomPatternReferences(formattedMessage, event); // Escape HTML characters to avoid issues with displaying in HTML formattedMessage = Web.escapeHtmlReserved(formattedMessage); - // Replace ANSI escape codes with corresponding HTML styles formattedMessage = replaceAnsiWithHtml(formattedMessage); - return formattedMessage; } + /** private String processCustomPatternReferences(String formattedMessage, LogEvent event) { // Example: Replace %im with custom logic formattedMessage = formattedMessage.replace("%im", customIMConverter(event)); return formattedMessage; - } - + } private String customIMConverter(LogEvent event) { // Example custom logic for %im String message = event.getMessage().getFormattedMessage(); // Apply your custom formatting logic here return message; } + */ private String replaceAnsiWithHtml(String input) { + // If the platform is Windows, handle full ANSI sequences including \u001b + if (OS.isWindows()) { + + // Full escape sequences (with \u001b) for Windows + + // Standard colors + input = input.replace("\u001b[30m", ""); + input = input.replace("\u001b[31m", ""); + input = input.replace("\u001b[32m", ""); + input = input.replace("\u001b[33m", ""); + input = input.replace("\u001b[34m", ""); + input = input.replace("\u001b[35m", ""); + input = input.replace("\u001b[36m", ""); + input = input.replace("\u001b[37m", ""); + + // Standard bright colors + input = input.replace("\u001b[1;30m", ""); + input = input.replace("\u001b[1;31m", ""); + input = input.replace("\u001b[1;32m", ""); + input = input.replace("\u001b[1;33m", ""); + input = input.replace("\u001b[1;34m", ""); + input = input.replace("\u001b[1;35m", ""); + input = input.replace("\u001b[1;36m", ""); + input = input.replace("\u001b[1;37m", ""); + + // beetRoot ANSI colors + input = input.replace("\u001b[90m", ""); + input = input.replace("\u001b[91m", ""); + input = input.replace("\u001b[92m", ""); + input = input.replace("\u001b[93m", ""); + input = input.replace("\u001b[94m", ""); + input = input.replace("\u001b[95m", ""); + input = input.replace("\u001b[96m", ""); + input = input.replace("\u001b[97m", ""); + + // Resets (any reset sequence) + input = input.replaceAll("\u001b\\[0m", ""); + input = input.replaceAll("\u001b\\[m", ""); + + } else { + + // macOSm Linux: Handle only the color codes, no \u001b present + + // Standard colors + input = input.replace("[30m", ""); + input = input.replace("[31m", ""); + input = input.replace("[32m", ""); + input = input.replace("[33m", ""); + input = input.replace("[34m", ""); + input = input.replace("[35m", ""); + input = input.replace("[36m", ""); + input = input.replace("[37m", ""); + + // Standard bright colors + input = input.replace("[1;30m", ""); + input = input.replace("[1;31m", ""); + input = input.replace("[1;32m", ""); + input = input.replace("[1;33m", ""); + input = input.replace("[1;34m", ""); + input = input.replace("[1;35m", ""); + input = input.replace("[1;36m", ""); + input = input.replace("[1;37m", ""); + + // beetRoot ANSI colors + input = input.replace("[90m", ""); + input = input.replace("[91m", ""); + input = input.replace("[92m", ""); + input = input.replace("[93m", ""); + input = input.replace("[94m", ""); + input = input.replace("[95m", ""); + input = input.replace("[96m", ""); + input = input.replace("[97m", ""); + + // Resets + input = input.replace("[0m", ""); + input = input.replace("[m", ""); + } - // Standard colors - input = input.replace("[30m", ""); - input = input.replace("[31m", ""); - input = input.replace("[32m", ""); - input = input.replace("[33m", ""); - input = input.replace("[34m", ""); - input = input.replace("[35m", ""); - input = input.replace("[36m", ""); - input = input.replace("[37m", ""); - - // Standard bright colors - input = input.replace("[1;30m", ""); - input = input.replace("[1;31m", ""); - input = input.replace("[1;32m", ""); - input = input.replace("[1;33m", ""); - input = input.replace("[1;34m", ""); - input = input.replace("[1;35m", ""); - input = input.replace("[1;36m", ""); - input = input.replace("[1;37m", ""); - - // beetRoot ANSI colors - input = input.replace("[90m", ""); - input = input.replace("[91m", ""); - input = input.replace("[92m", ""); - input = input.replace("[93m", ""); - input = input.replace("[94m", ""); - input = input.replace("[95m", ""); - input = input.replace("[96m", ""); - input = input.replace("[97m", ""); - - // Resets - input = input.replace("[0m", ""); - input = input.replace("[m", ""); - // Special words (artistic freedom) input = input.replace("READER", "READER"); input = input.replace("READING", "READING");