waibu 2.15.1 → 2.16.0

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.
@@ -6,6 +6,13 @@ export const methodColor = {
6
6
  DELETE: 'red'
7
7
  }
8
8
 
9
+ const stateColor = {
10
+ 2: 'green',
11
+ 3: 'yellow',
12
+ 4: 'red',
13
+ 5: 'red'
14
+ }
15
+
9
16
  async function hook () {
10
17
  return [{
11
18
  name: 'waibu:onClose',
@@ -39,7 +46,7 @@ async function hook () {
39
46
  if (this.config.log.defer) {
40
47
  this.reqLog = this.reqLog ?? {}
41
48
  this.reqLog[req.id] = msg
42
- } else if (!this.config.log.noReq) this.app[ns].log.info(msg)
49
+ } else if (!this.config.log.disable.includes('request')) this.app[ns].log.info(msg)
43
50
  if (Object.keys(this.config.paramsCharMap).length === 0) return
44
51
  for (const key in req.params) {
45
52
  let val = req.params[key]
@@ -50,6 +57,37 @@ async function hook () {
50
57
  req.params[key] = val
51
58
  }
52
59
  }
60
+ }, {
61
+ level: 5,
62
+ name: 'waibu:onResponse',
63
+ handler: async function onResponse (req, reply) {
64
+ const { importPkg } = this.app.bajo
65
+ const { get } = this.app.lib._
66
+ const { plain } = this.app.bajo.config.log
67
+ const chalk = await importPkg('bajo:chalk')
68
+ let level = 'info'
69
+ if (reply.statusCode >= 300 && reply.statusCode < 400) level = 'warn'
70
+ else if (reply.statusCode >= 400) level = 'error'
71
+ const ns = get(reply.request, 'routeOptions.config.webApp') ?? this.ns
72
+ const arrow = plain ? '>' : chalk.bold('🡪')
73
+ const mc = methodColor[req.method] ?? 'gray'
74
+ const method = plain ? req.method : chalk[mc](req.method)
75
+ const url = plain ? (':' + req.url) : chalk.gray(':' + req.url)
76
+ let state = plain ? reply.statusCode : chalk.gray(reply.statusCode)
77
+ const sc = stateColor[Math.floor(reply.statusCode / 100)]
78
+ if (!plain && sc) state = chalk[sc](reply.statusCode)
79
+ const elapsed = reply.elapsedTime ?? 0
80
+ let tc = 'red'
81
+ if (elapsed < 1000) tc = 'yellow'
82
+ if (elapsed < 500) tc = 'green'
83
+ const time = plain ? elapsed.toFixed(2) : chalk[tc](elapsed.toFixed(2))
84
+ if (this.config.log.defer) {
85
+ this.reqLog = this.reqLog ?? {}
86
+ if (this.reqLog[req.id] && !this.config.log.disable.includes('request')) this.app[ns].log.info(this.reqLog[req.id])
87
+ delete this.reqLog[req.id]
88
+ }
89
+ if (!this.config.log.disable.includes('response')) this.app[ns].log[level]('httpResp%s%s%s%s%s', arrow, method, url, state, time)
90
+ }
53
91
  }, {
54
92
  level: 5,
55
93
  name: 'waibu:onRoute',
package/index.js CHANGED
@@ -92,8 +92,7 @@ async function factory (pkgName) {
92
92
  detectors: ['qs']
93
93
  },
94
94
  log: {
95
- noReq: false,
96
- noReply: false,
95
+ disable: [],
97
96
  defer: false
98
97
  },
99
98
  prefixVirtual: '~',
@@ -161,6 +160,8 @@ async function factory (pkgName) {
161
160
  * @async
162
161
  */
163
162
  init = async () => {
163
+ const { isString } = this.app.lib._
164
+ if (isString(this.config.log.disable)) this.config.log.disable = [this.config.log.disable]
164
165
  if (this.config.home === '/') this.config.home = false
165
166
  await collectRoutePathHandlers.call(this)
166
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.15.1",
3
+ "version": "2.16.0",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-05-30
4
+
5
+ - [2.16.0] Change ```config.log.[noReq|noReply]``` to array ```config.log.disable``` with possible values: ```request``` and ```response```. Defaults to empty values
6
+
3
7
  ## 2026-05-29
4
8
 
5
9
  - [2.15.1] Bug fix in ```build-locals.js```
10
+ - [2.15.2] Bug fix in ```hook.js```
6
11
 
7
12
  ## 2026-05-28
8
13