Skip to content

Commit

Permalink
fixed logs returned by API are too long sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Nov 10, 2024
1 parent a78d65d commit 0ad610b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/erudika/scoold/api/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1014,13 +1014,14 @@ public Map<String, Object> 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<String> lines = Files.lines(path)) {
List<String> 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());
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/templates/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ad610b

Please sign in to comment.