Skip to content
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`, `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() {
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}"
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import java.util.Optional;

public enum CodePrintLevel {
INFO,
SUCCESS,
ERROR,
INFO,
WARN,
DEBUG,
TRACE;
DEBUG;

public static Optional<CodePrintLevel> find(String level) {
return Arrays.stream(values())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public void fromLoggers(List<String> loggerNames) {
loggerNames.forEach(this::fromLogger);
}

public void success(String message) {
printStamped(CodePrintLevel.SUCCESS, message);
}

public void info(String message) {
printStamped(CodePrintLevel.INFO, message);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
Expand All @@ -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
Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions ui.frontend/src/utils/monaco/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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' },
Expand Down