@jsenv/server 12.6.1 → 12.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/startServer.js +26 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/server",
3
- "version": "12.6.1",
3
+ "version": "12.6.2",
4
4
  "description": "Write your Node.js server using pure functions",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -299,25 +299,47 @@ export const startServer = async ({
299
299
  const prefixLines = (string, prefix) => {
300
300
  return string.replace(/^(?!\s*$)/gm, prefix)
301
301
  }
302
- const writeLog = ({ type, value }, depth) => {
302
+ const writeLog = (
303
+ { type, value },
304
+ { someLogIsError, someLogIsWarn, depth },
305
+ ) => {
303
306
  if (depth > 0) {
304
307
  value = prefixLines(value, " ".repeat(depth))
305
308
  }
309
+ if (type === "info") {
310
+ if (someLogIsError) {
311
+ type = "error"
312
+ } else if (someLogIsWarn) {
313
+ type = "warn"
314
+ }
315
+ }
306
316
  logger[type](value)
307
317
  }
308
318
  const visitRequestNodeToLog = (requestNode, depth) => {
319
+ let someLogIsError = false
320
+ let someLogIsWarn = false
321
+ requestNode.logs.forEach((log) => {
322
+ if (log.type === "error") {
323
+ someLogIsError = true
324
+ }
325
+ if (log.type === "warn") {
326
+ someLogIsWarn = true
327
+ }
328
+ })
329
+
309
330
  const firstLog = requestNode.logs.shift()
310
331
  const lastLog = requestNode.logs.pop()
311
332
  const middleLogs = requestNode.logs
312
- writeLog(firstLog, depth)
333
+
334
+ writeLog(firstLog, { someLogIsError, someLogIsWarn, depth })
313
335
  middleLogs.forEach((log) => {
314
- writeLog(log, depth)
336
+ writeLog(log, { someLogIsError, someLogIsWarn, depth })
315
337
  })
316
338
  requestNode.children.forEach((child) => {
317
339
  visitRequestNodeToLog(child, depth + 1)
318
340
  })
319
341
  if (lastLog) {
320
- writeLog(lastLog, depth + 1)
342
+ writeLog(lastLog, { someLogIsError, someLogIsWarn, depth: depth + 1 })
321
343
  }
322
344
  }
323
345
  visitRequestNodeToLog(rootRequestNode, 0)