From d4a9f475726779a18b93299fa4649607128c427f Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Thu, 13 Nov 2025 10:03:49 +0100 Subject: [PATCH 1/2] Debug level --- README.md | 5 +- .../vml/es/acm/core/code/CodePrintLevel.java | 6 +-- .../vml/es/acm/core/code/CodePrintStream.java | 8 +-- .../es/acm/core/code/CodePrintStreamTest.java | 52 ++++++++++--------- .../core/general/demo_processing.yml | 2 +- ui.frontend/src/utils/monaco/log.ts | 2 + 6 files changed, 40 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index acf476d5..54d901e8 100644 --- a/README.md +++ b/README.md @@ -371,15 +371,14 @@ void doRun() { ##### Timestamped console output -Use `out.error()`, `out.warn()`, `out.info()`, `out.debug()`, `out.trace()` to write messages to the console with timestamps and log levels. These messages appear only in the execution console and are not persisted to AEM logs. +Use `out.error()`, `out.warn()`, `out.success()`, `out.info()` to write messages to the console with timestamps and log levels. These messages appear only in the execution console and are not persisted to AEM logs. ```groovy void doRun() { out.error "Failed to process resource: ${resource.path}" out.warn "Resource ${resource.path} is missing required property" + out.success "Resource ${resource.path} processed successfully" out.info "Processing started" - out.debug "Processing resource: ${resource.path}" - out.trace "Entering method with params: ${params}" } ``` diff --git a/core/src/main/java/dev/vml/es/acm/core/code/CodePrintLevel.java b/core/src/main/java/dev/vml/es/acm/core/code/CodePrintLevel.java index af3325d8..203a824a 100644 --- a/core/src/main/java/dev/vml/es/acm/core/code/CodePrintLevel.java +++ b/core/src/main/java/dev/vml/es/acm/core/code/CodePrintLevel.java @@ -4,11 +4,11 @@ import java.util.Optional; public enum CodePrintLevel { - INFO, + SUCCESS, ERROR, + INFO, WARN, - DEBUG, - TRACE; + DEBUG; public static Optional find(String level) { return Arrays.stream(values()) diff --git a/core/src/main/java/dev/vml/es/acm/core/code/CodePrintStream.java b/core/src/main/java/dev/vml/es/acm/core/code/CodePrintStream.java index f028ae61..77c94e77 100644 --- a/core/src/main/java/dev/vml/es/acm/core/code/CodePrintStream.java +++ b/core/src/main/java/dev/vml/es/acm/core/code/CodePrintStream.java @@ -147,6 +147,10 @@ public void fromLoggers(List loggerNames) { loggerNames.forEach(this::fromLogger); } + public void success(String message) { + printStamped(CodePrintLevel.SUCCESS, message); + } + public void info(String message) { printStamped(CodePrintLevel.INFO, message); } @@ -163,10 +167,6 @@ public void debug(String message) { printStamped(CodePrintLevel.DEBUG, message); } - public void trace(String message) { - printStamped(CodePrintLevel.TRACE, message); - } - public void printStamped(String level, String message) { printStamped(CodePrintLevel.of(level), message); } diff --git a/core/src/test/java/dev/vml/es/acm/core/code/CodePrintStreamTest.java b/core/src/test/java/dev/vml/es/acm/core/code/CodePrintStreamTest.java index 7cc6dfc1..358fe69b 100644 --- a/core/src/test/java/dev/vml/es/acm/core/code/CodePrintStreamTest.java +++ b/core/src/test/java/dev/vml/es/acm/core/code/CodePrintStreamTest.java @@ -16,9 +16,9 @@ void shouldPrintInfoWithTimestamp() { } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - CodePrintStream printStream = new CodePrintStream(outputStream, "test-id"); - - printStream.info("Test info message"); + try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) { + out.info("Test info message"); + } String output = outputStream.toString(); assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[INFO\\] Test info message\\R")); @@ -31,9 +31,9 @@ void shouldPrintErrorWithTimestamp() { } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - CodePrintStream printStream = new CodePrintStream(outputStream, "test-id"); - - printStream.error("Test error message"); + try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) { + out.error("Test error message"); + } String output = outputStream.toString(); assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[ERROR\\] Test error message\\R")); @@ -46,42 +46,42 @@ void shouldPrintWarnWithTimestamp() { } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - CodePrintStream printStream = new CodePrintStream(outputStream, "test-id"); - - printStream.warn("Test warn message"); + try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) { + out.warn("Test warn message"); + } String output = outputStream.toString(); assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[WARN\\] Test warn message\\R")); } @Test - void shouldPrintDebugWithTimestamp() { + void shouldPrintSuccessWithTimestamp() { if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) { return; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - CodePrintStream printStream = new CodePrintStream(outputStream, "test-id"); - - printStream.debug("Test debug message"); + try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) { + out.success("Test success message"); + } String output = outputStream.toString(); - assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[DEBUG\\] Test debug message\\R")); + assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[SUCCESS\\] Test success message\\R")); } @Test - void shouldPrintTraceWithTimestamp() { + void shouldPrintDebugWithTimestamp() { if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) { return; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - CodePrintStream printStream = new CodePrintStream(outputStream, "test-id"); - - printStream.trace("Test trace message"); + try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) { + out.debug("Test debug message"); + } String output = outputStream.toString(); - assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[TRACE\\] Test trace message\\R")); + assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[DEBUG\\] Test debug message\\R")); } @Test @@ -91,15 +91,19 @@ void shouldPrintMultipleMessagesWithDifferentLevels() { } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - CodePrintStream printStream = new CodePrintStream(outputStream, "test-id"); - - printStream.info("Info message"); - printStream.error("Error message"); - printStream.warn("Warn message"); + try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) { + out.info("Info message"); + out.error("Error message"); + out.warn("Warn message"); + out.debug("Debug message"); + out.success("Success message"); + } String output = outputStream.toString(); assertTrue(output.contains("[INFO] Info message")); assertTrue(output.contains("[ERROR] Error message")); assertTrue(output.contains("[WARN] Warn message")); + assertTrue(output.contains("[DEBUG] Debug message")); + assertTrue(output.contains("[SUCCESS] Success message")); } } diff --git a/ui.content/src/main/content/jcr_root/conf/acm/settings/snippet/available/core/general/demo_processing.yml b/ui.content/src/main/content/jcr_root/conf/acm/settings/snippet/available/core/general/demo_processing.yml index 3ce5aa7b..c2dd97fb 100644 --- a/ui.content/src/main/content/jcr_root/conf/acm/settings/snippet/available/core/general/demo_processing.yml +++ b/ui.content/src/main/content/jcr_root/conf/acm/settings/snippet/available/core/general/demo_processing.yml @@ -16,7 +16,7 @@ content: | out.info "Updated (\${i + 1}/\${max})" } - out.info "Processing done" + out.success "Processing done" } documentation: | A skeleton for a script that simulates a processing task. diff --git a/ui.frontend/src/utils/monaco/log.ts b/ui.frontend/src/utils/monaco/log.ts index f687e8b7..e4ca1d95 100644 --- a/ui.frontend/src/utils/monaco/log.ts +++ b/ui.frontend/src/utils/monaco/log.ts @@ -17,6 +17,7 @@ export function registerLogLanguage(instance: Monaco) { root: [ [/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[ERROR\].*$/, 'log-error'], [/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[WARN\].*$/, 'log-warn'], + [/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[SUCCESS\].*$/, 'log-success'], [/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[INFO\].*$/, 'log-info'], [/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[DEBUG\].*$/, 'log-debug'], [/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[TRACE\].*$/, 'log-trace'], @@ -30,6 +31,7 @@ export function registerLogLanguage(instance: Monaco) { rules: [ { token: 'log-error', foreground: 'f14c4c', fontStyle: 'bold' }, { token: 'log-warn', foreground: 'e5c07b' }, + { token: 'log-success', foreground: '89d185', fontStyle: 'bold' }, { token: 'log-info', foreground: 'ededed' }, { token: 'log-debug', foreground: '8b949e' }, { token: 'log-trace', foreground: '6a6a6a' }, From 4dc6bce87f27097b84c806b83c7209b30d9fa212 Mon Sep 17 00:00:00 2001 From: Krystian Panek <81212505+krystian-panek-vmltech@users.noreply.github.com> Date: Thu, 13 Nov 2025 10:20:29 +0100 Subject: [PATCH 2/2] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 54d901e8..d738cbb7 100644 --- a/README.md +++ b/README.md @@ -371,7 +371,7 @@ void doRun() { ##### Timestamped console output -Use `out.error()`, `out.warn()`, `out.success()`, `out.info()` to write messages to the console with timestamps and log levels. These messages appear only in the execution console and are not persisted to AEM logs. +Use `out.error()`, `out.warn()`, `out.success()`, `out.info()`, `out.debug()` to write messages to the console with timestamps and log levels. These messages appear only in the execution console and are not persisted to AEM logs. ```groovy void doRun() {