From 0ad610b47c6dcbc846317295b9f72174507618f1 Mon Sep 17 00:00:00 2001 From: Alex Bogdanovski Date: Sun, 10 Nov 2024 12:46:49 +0200 Subject: [PATCH] fixed logs returned by API are too long sometimes --- src/main/java/com/erudika/scoold/api/ApiController.java | 5 +++-- src/main/resources/templates/api.yaml | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/erudika/scoold/api/ApiController.java b/src/main/java/com/erudika/scoold/api/ApiController.java index 701e3e7d..ef0fe7c1 100644 --- a/src/main/java/com/erudika/scoold/api/ApiController.java +++ b/src/main/java/com/erudika/scoold/api/ApiController.java @@ -1014,13 +1014,14 @@ public Map stats(HttpServletRequest req) { if ("true".equals(req.getParameter("includeLogs"))) { try { + int maxLines = NumberUtils.toInt(req.getParameter("maxLogLines"), 10000); String logFile = System.getProperty("para.logs_dir", System.getProperty("user.dir")) + "/" + System.getProperty("para.logs_name", "scoold") + ".log"; Path path = Paths.get(logFile); try (Stream lines = Files.lines(path)) { List linez = lines.collect(Collectors.toList()); - linez.subList(Math.max(0, linez.size() - 10000), linez.size()); - stats.put("log", linez.stream().collect(Collectors.joining("\n"))); + stats.put("log", linez.subList(Math.max(0, linez.size() - maxLines), linez.size()). + stream().collect(Collectors.joining("\n"))); } } catch (Exception e) { logger.error("Failed to read log file. {}", e.getMessage()); diff --git a/src/main/resources/templates/api.yaml b/src/main/resources/templates/api.yaml index 9bec219d..9182f1fa 100644 --- a/src/main/resources/templates/api.yaml +++ b/src/main/resources/templates/api.yaml @@ -1480,6 +1480,12 @@ paths: description: If set to `true` will read and return the Scoold log file as well. schema: type: boolean + - name: maxLogLines + in: query + required: false + description: The number of log lines to return, default is `10000`. + schema: + type: integer responses: '200': description: stats