@jsenv/server
Advanced tools
Comparing version 12.6.1 to 12.6.2
{ | ||
"name": "@jsenv/server", | ||
"version": "12.6.1", | ||
"version": "12.6.2", | ||
"description": "Write your Node.js server using pure functions", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -302,15 +302,37 @@ import http from "node:http" | ||
} | ||
const writeLog = ({ type, value }, depth) => { | ||
const writeLog = ( | ||
{ type, value }, | ||
{ someLogIsError, someLogIsWarn, depth }, | ||
) => { | ||
if (depth > 0) { | ||
value = prefixLines(value, " ".repeat(depth)) | ||
} | ||
if (type === "info") { | ||
if (someLogIsError) { | ||
type = "error" | ||
} else if (someLogIsWarn) { | ||
type = "warn" | ||
} | ||
} | ||
logger[type](value) | ||
} | ||
const visitRequestNodeToLog = (requestNode, depth) => { | ||
let someLogIsError = false | ||
let someLogIsWarn = false | ||
requestNode.logs.forEach((log) => { | ||
if (log.type === "error") { | ||
someLogIsError = true | ||
} | ||
if (log.type === "warn") { | ||
someLogIsWarn = true | ||
} | ||
}) | ||
const firstLog = requestNode.logs.shift() | ||
const lastLog = requestNode.logs.pop() | ||
const middleLogs = requestNode.logs | ||
writeLog(firstLog, depth) | ||
writeLog(firstLog, { someLogIsError, someLogIsWarn, depth }) | ||
middleLogs.forEach((log) => { | ||
writeLog(log, depth) | ||
writeLog(log, { someLogIsError, someLogIsWarn, depth }) | ||
}) | ||
@@ -321,3 +343,3 @@ requestNode.children.forEach((child) => { | ||
if (lastLog) { | ||
writeLog(lastLog, depth + 1) | ||
writeLog(lastLog, { someLogIsError, someLogIsWarn, depth: depth + 1 }) | ||
} | ||
@@ -324,0 +346,0 @@ } |
136205
4268