Skip to content

Commit ef405ce

Browse files
Merge pull request #269 from wttech/out-success
Output success
2 parents 0961c47 + 4dc6bce commit ef405ce

File tree

6 files changed

+40
-35
lines changed

6 files changed

+40
-35
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,14 @@ void doRun() {
371371

372372
##### Timestamped console output
373373

374-
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.
374+
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.
375375

376376
```groovy
377377
void doRun() {
378378
out.error "Failed to process resource: ${resource.path}"
379379
out.warn "Resource ${resource.path} is missing required property"
380+
out.success "Resource ${resource.path} processed successfully"
380381
out.info "Processing started"
381-
out.debug "Processing resource: ${resource.path}"
382-
out.trace "Entering method with params: ${params}"
383382
}
384383
```
385384

core/src/main/java/dev/vml/es/acm/core/code/CodePrintLevel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import java.util.Optional;
55

66
public enum CodePrintLevel {
7-
INFO,
7+
SUCCESS,
88
ERROR,
9+
INFO,
910
WARN,
10-
DEBUG,
11-
TRACE;
11+
DEBUG;
1212

1313
public static Optional<CodePrintLevel> find(String level) {
1414
return Arrays.stream(values())

core/src/main/java/dev/vml/es/acm/core/code/CodePrintStream.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ public void fromLoggers(List<String> loggerNames) {
147147
loggerNames.forEach(this::fromLogger);
148148
}
149149

150+
public void success(String message) {
151+
printStamped(CodePrintLevel.SUCCESS, message);
152+
}
153+
150154
public void info(String message) {
151155
printStamped(CodePrintLevel.INFO, message);
152156
}
@@ -163,10 +167,6 @@ public void debug(String message) {
163167
printStamped(CodePrintLevel.DEBUG, message);
164168
}
165169

166-
public void trace(String message) {
167-
printStamped(CodePrintLevel.TRACE, message);
168-
}
169-
170170
public void printStamped(String level, String message) {
171171
printStamped(CodePrintLevel.of(level), message);
172172
}

core/src/test/java/dev/vml/es/acm/core/code/CodePrintStreamTest.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ void shouldPrintInfoWithTimestamp() {
1616
}
1717

1818
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
19-
CodePrintStream printStream = new CodePrintStream(outputStream, "test-id");
20-
21-
printStream.info("Test info message");
19+
try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) {
20+
out.info("Test info message");
21+
}
2222

2323
String output = outputStream.toString();
2424
assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[INFO\\] Test info message\\R"));
@@ -31,9 +31,9 @@ void shouldPrintErrorWithTimestamp() {
3131
}
3232

3333
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
34-
CodePrintStream printStream = new CodePrintStream(outputStream, "test-id");
35-
36-
printStream.error("Test error message");
34+
try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) {
35+
out.error("Test error message");
36+
}
3737

3838
String output = outputStream.toString();
3939
assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[ERROR\\] Test error message\\R"));
@@ -46,42 +46,42 @@ void shouldPrintWarnWithTimestamp() {
4646
}
4747

4848
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
49-
CodePrintStream printStream = new CodePrintStream(outputStream, "test-id");
50-
51-
printStream.warn("Test warn message");
49+
try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) {
50+
out.warn("Test warn message");
51+
}
5252

5353
String output = outputStream.toString();
5454
assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[WARN\\] Test warn message\\R"));
5555
}
5656

5757
@Test
58-
void shouldPrintDebugWithTimestamp() {
58+
void shouldPrintSuccessWithTimestamp() {
5959
if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) {
6060
return;
6161
}
6262

6363
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
64-
CodePrintStream printStream = new CodePrintStream(outputStream, "test-id");
65-
66-
printStream.debug("Test debug message");
64+
try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) {
65+
out.success("Test success message");
66+
}
6767

6868
String output = outputStream.toString();
69-
assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[DEBUG\\] Test debug message\\R"));
69+
assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[SUCCESS\\] Test success message\\R"));
7070
}
7171

7272
@Test
73-
void shouldPrintTraceWithTimestamp() {
73+
void shouldPrintDebugWithTimestamp() {
7474
if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) {
7575
return;
7676
}
7777

7878
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
79-
CodePrintStream printStream = new CodePrintStream(outputStream, "test-id");
80-
81-
printStream.trace("Test trace message");
79+
try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) {
80+
out.debug("Test debug message");
81+
}
8282

8383
String output = outputStream.toString();
84-
assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[TRACE\\] Test trace message\\R"));
84+
assertTrue(output.matches("\\d{2}:\\d{2}:\\d{2}\\.\\d{3} \\[DEBUG\\] Test debug message\\R"));
8585
}
8686

8787
@Test
@@ -91,15 +91,19 @@ void shouldPrintMultipleMessagesWithDifferentLevels() {
9191
}
9292

9393
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
94-
CodePrintStream printStream = new CodePrintStream(outputStream, "test-id");
95-
96-
printStream.info("Info message");
97-
printStream.error("Error message");
98-
printStream.warn("Warn message");
94+
try (CodePrintStream out = new CodePrintStream(outputStream, "test-id")) {
95+
out.info("Info message");
96+
out.error("Error message");
97+
out.warn("Warn message");
98+
out.debug("Debug message");
99+
out.success("Success message");
100+
}
99101

100102
String output = outputStream.toString();
101103
assertTrue(output.contains("[INFO] Info message"));
102104
assertTrue(output.contains("[ERROR] Error message"));
103105
assertTrue(output.contains("[WARN] Warn message"));
106+
assertTrue(output.contains("[DEBUG] Debug message"));
107+
assertTrue(output.contains("[SUCCESS] Success message"));
104108
}
105109
}

ui.content/src/main/content/jcr_root/conf/acm/settings/snippet/available/core/general/demo_processing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ content: |
1616
out.info "Updated (\${i + 1}/\${max})"
1717
}
1818
19-
out.info "Processing done"
19+
out.success "Processing done"
2020
}
2121
documentation: |
2222
A skeleton for a script that simulates a processing task.

ui.frontend/src/utils/monaco/log.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function registerLogLanguage(instance: Monaco) {
1717
root: [
1818
[/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[ERROR\].*$/, 'log-error'],
1919
[/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[WARN\].*$/, 'log-warn'],
20+
[/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[SUCCESS\].*$/, 'log-success'],
2021
[/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[INFO\].*$/, 'log-info'],
2122
[/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[DEBUG\].*$/, 'log-debug'],
2223
[/^(\d{2}:\d{2}:\d{2}\.\d{3} )?\[TRACE\].*$/, 'log-trace'],
@@ -30,6 +31,7 @@ export function registerLogLanguage(instance: Monaco) {
3031
rules: [
3132
{ token: 'log-error', foreground: 'f14c4c', fontStyle: 'bold' },
3233
{ token: 'log-warn', foreground: 'e5c07b' },
34+
{ token: 'log-success', foreground: '89d185', fontStyle: 'bold' },
3335
{ token: 'log-info', foreground: 'ededed' },
3436
{ token: 'log-debug', foreground: '8b949e' },
3537
{ token: 'log-trace', foreground: '6a6a6a' },

0 commit comments

Comments
 (0)