|
58 | 58 | import jakarta.inject.Singleton;
|
59 | 59 | import jakarta.validation.Valid;
|
60 | 60 | import java.nio.charset.StandardCharsets;
|
| 61 | +import java.util.Locale; |
61 | 62 | import java.util.Map;
|
62 | 63 | import java.util.concurrent.atomic.AtomicInteger;
|
63 | 64 | import java.util.concurrent.atomic.AtomicReference;
|
@@ -217,8 +218,24 @@ public V3HttpHandlerNode(
|
217 | 218 |
|
218 | 219 | @RequestHandler(path = "/api/v3/node/logLines")
|
219 | 220 | @Authentication(providers = "jwt", scopes = {"cloudnet_rest:node_read", "cloudnet_rest:node_log_lines"})
|
220 |
| - public @NonNull IntoResponse<?> handleLogLinesRequest() { |
221 |
| - return JsonResponse.builder().body(Map.of("lines", this.consoleLogAppender.formattedCachedLogLines())); |
| 221 | + public @NonNull IntoResponse<?> handleLogLinesRequest( |
| 222 | + @NonNull @Optional @FirstRequestQueryParam(value = "format", def = "raw") String formatType |
| 223 | + ) { |
| 224 | + return switch (formatType.toLowerCase(Locale.ROOT)) { |
| 225 | + case "raw" -> { |
| 226 | + var lines = this.consoleLogAppender.cachedLogEntries().stream() |
| 227 | + .map(ILoggingEvent::getFormattedMessage) |
| 228 | + .toList(); |
| 229 | + yield JsonResponse.builder().body(lines); |
| 230 | + } |
| 231 | + case "ansi" -> JsonResponse.builder().body(this.consoleLogAppender.cachedLogEntries()); |
| 232 | + default -> ProblemDetail.builder() |
| 233 | + .type("console-invalid-formatting-type") |
| 234 | + .title("Console Invalid Formatting Type") |
| 235 | + .status(HttpResponseCode.BAD_REQUEST) |
| 236 | + .detail("The cached log lines do not support the format " + formatType) |
| 237 | + .build(); |
| 238 | + }; |
222 | 239 | }
|
223 | 240 |
|
224 | 241 | private void reloadConfig() {
|
|
0 commit comments