fix: парсить уровень лога sing-box из stderr вместо hardcode error
All checks were successful
Build and Deploy Gateway / build-and-deploy (push) Successful in 5s

This commit is contained in:
2026-05-08 18:45:16 +03:00
parent b716b370ac
commit 7489b5ef97

View File

@@ -30,7 +30,18 @@ function pushLog(level, line) {
}
}
function captureStream(stream, level) {
// Sing-box пишет все логи в stderr, поэтому парсим уровень из содержимого строки
const SINGBOX_LEVEL_RE = /\[\d+m(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\[0m/i;
function parseSingboxLevel(line, fallback) {
const m = line.match(SINGBOX_LEVEL_RE);
if (!m) return fallback;
const l = m[1].toLowerCase();
if (l === "warn") return "warning";
if (l === "fatal") return "error";
return l; // trace, debug, info, error
}
function captureStream(stream, fallbackLevel) {
let remainder = "";
stream.setEncoding("utf8");
stream.on("data", (chunk) => {
@@ -39,12 +50,14 @@ function captureStream(stream, level) {
remainder = lines.pop() || "";
for (const line of lines) {
if (!line) continue;
const level = parseSingboxLevel(line, fallbackLevel);
process.stdout.write(`[sing-box:${level}] ${line}\n`);
pushLog(level, line);
}
});
stream.on("end", () => {
if (remainder) {
const level = parseSingboxLevel(remainder, fallbackLevel);
process.stdout.write(`[sing-box:${level}] ${remainder}\n`);
pushLog(level, remainder);
}