CH-J Server Managerserver management over SSH
Menu
Published source

CH-J Server Manager

Browse directories and files for a specific application release.

Download source ZIP
CH-J Proprietary Software License 1.14

Source is provided under the CH-J Proprietary Software License 1.14. Its availability does not change the license terms or grant additional rights.

1,5 KB · 44 linesDownload file
1"use strict";
3const fs = require("node:fs");
4const path = require("node:path");
6const SENSITIVE_KEYS = /pass(word|phrase)?|private.?key|secret|token|credential/i;
8function sanitize(value, depth = 0) {
9 if (depth > 5) return "[depth-limit]";
10 if (Array.isArray(value)) return value.slice(0, 50).map((item) => sanitize(item, depth + 1));
11 if (!value || typeof value !== "object") return value;
12 const result = {};
13 for (const [key, entry] of Object.entries(value)) {
14 result[key] = SENSITIVE_KEYS.test(key) ? "[redacted]" : sanitize(entry, depth + 1);
15 }
16 return result;
19class Logger {
20 constructor(rootDir) {
21 this.logDir = path.join(rootDir, "logs");
22 this.logPath = path.join(this.logDir, "core.log");
23 fs.mkdirSync(this.logDir, { recursive: true });
24 }
26 write(level, message, data = {}) {
27 const record = {
28 timestamp: new Date().toISOString(),
29 level,
30 message: String(message || ""),
31 data: sanitize(data)
32 };
33 const line = `${JSON.stringify(record)}\n`;
34 try { fs.appendFileSync(this.logPath, line, { encoding: "utf8", mode: 0o600 }); } catch {}
35 const output = level === "error" ? console.error : level === "warn" ? console.warn : console.log;
36 output(`[${level.toUpperCase()}] ${record.message}`, record.data);
37 }
39 info(message, data) { this.write("info", message, data); }
40 warn(message, data) { this.write("warn", message, data); }
41 error(message, data) { this.write("error", message, data); }
44module.exports = { Logger, sanitize };

SHA-256: 89d04a484d9f684bf017a708c287c87d3f4fda912207ba8f7dc06bd33b35e5c5

Archive SHA-256: 5ac91caf4fa32a6fdb114f2430deed486fbe7489d5eea343d1f034169fafb5e0