CH-J Server Managerbainisteoireacht freastalaí SSH
Roghchlár
Foinse foilsithe

CH-J Server Manager

Brabhsáil comhadlanna agus comhaid chun feidhmchlár áirithe a scaoileadh.

Íosluchtaigh foinse ZIP
CH-J / Server Manager 193 Comhaid
core-20261011T184039Z-4148710795d0 Suimigh: Dáta gan taifeadadh · Tógtha:
Comhaid
logService.js Suimigh: Dáta gan taifeadadh 1.6 KB · 53 líne
Íosluchtaigh comhad
1"use strict";
3const fs = require("node:fs");
5const DEFAULT_LIMIT = 256 * 1024;
6const MAX_LIMIT = 1024 * 1024;
8function normalizeLimit(value) {
9 const parsed = Number(value);
10 if (!Number.isSafeInteger(parsed) || parsed <= 0) return DEFAULT_LIMIT;
11 return Math.min(parsed, MAX_LIMIT);
14class LogService {
15 constructor(logPath) {
16 this.logPath = String(logPath || "");
17 if (!this.logPath) throw new Error("Log path is required.");
18 }
20 async readTail(payload = {}) {
21 const maxBytes = normalizeLimit(payload.maxBytes);
22 let handle;
23 try {
24 const stat = await fs.promises.stat(this.logPath);
25 if (!stat.isFile()) throw new Error("Application log is not a file.");
26 const length = Math.min(stat.size, maxBytes);
27 const offset = Math.max(0, stat.size - length);
28 const buffer = Buffer.alloc(length);
29 handle = await fs.promises.open(this.logPath, "r");
30 const { bytesRead } = await handle.read(buffer, 0, length, offset);
31 let text = buffer.subarray(0, bytesRead).toString("utf8");
32 if (offset > 0) {
33 const firstNewline = text.indexOf("\n");
34 text = firstNewline >= 0 ? text.slice(firstNewline + 1) : "";
35 }
36 return {
37 text,
38 truncated: offset > 0,
39 size: stat.size,
40 readAt: new Date().toISOString()
41 };
42 } catch (error) {
43 if (error?.code === "ENOENT") {
44 return { text: "", truncated: false, size: 0, readAt: new Date().toISOString() };
45 }
46 throw error;
47 } finally {
48 await handle?.close().catch(() => {});
49 }
50 }
53module.exports = { DEFAULT_LIMIT, LogService, MAX_LIMIT, normalizeLimit };
SHA-25636887b34740b6272535cb482c08ce23086fc1e30716612d11ddb1be66bb1dc02

CH-J Proprietary Software License 1.14 · Tá Foinse ar fáil faoin CH-J Proprietary Software License 1.14. Ní chuireann a infhaighteacht a athrú ar na téarmaí ceadúnais nó cearta breise a dheonú.

Cartlann SHA-2565a8ea02d06a5643cf2330fe9f54b8767a06c1c59d36527705e536fa9dbca7614