@jaypie/express 1.0.11 → 1.0.13

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.
package/dist/module.cjs CHANGED
@@ -196,6 +196,11 @@ const expressHandler = (
196
196
  const libLogger = core.log.lib({
197
197
  lib: core.JAYPIE.LIB.EXPRESS,
198
198
  });
199
+ // Top-level, important details that run at the same level as the main logger
200
+ const log = core.log.lib({
201
+ level: core.log.level,
202
+ lib: core.JAYPIE.LIB.EXPRESS,
203
+ });
199
204
 
200
205
  // Update the public logger with the request ID
201
206
  const invokeUuid = getCurrentInvokeUuid();
@@ -205,15 +210,24 @@ const expressHandler = (
205
210
  // TODO: in theory this is redundant
206
211
  libLogger.tag({ invoke: invokeUuid });
207
212
  libLogger.tag({ shortInvoke: invokeUuid.slice(0, 8) });
213
+ log.tag({ invoke: invokeUuid });
214
+ log.tag({ shortInvoke: invokeUuid.slice(0, 8) });
208
215
  }
209
216
 
210
- libLogger.trace("[jaypie] Express init");
217
+ if (!name) {
218
+ // If handler has a name, use it
219
+ if (handler.name) {
220
+ name = handler.name;
221
+ } else {
222
+ name = core.JAYPIE.UNKNOWN;
223
+ }
224
+ }
225
+ core.log.tag({ handler: name });
226
+ // TODO: in theory this is redundant
227
+ libLogger.tag({ handler: name });
228
+ log.tag({ handler: name });
211
229
 
212
- // Top-level, important details that run at the same level as the main logger
213
- const log = core.log.lib({
214
- level: core.log.level,
215
- lib: core.JAYPIE.LIB.EXPRESS,
216
- });
230
+ libLogger.trace("[jaypie] Express init");
217
231
 
218
232
  // Set req.locals if it doesn't exist
219
233
  if (!req.locals) req.locals = {};
@@ -271,15 +285,15 @@ const expressHandler = (
271
285
  // Locals
272
286
  const keys = Object.keys(locals);
273
287
  if (keys.length > 0) {
274
- const localsSetup = async () => {
288
+ const localsSetup = async (localsReq, localsRes) => {
275
289
  for (let i = 0; i < keys.length; i += 1) {
276
290
  const key = keys[i];
277
291
  libLogger.trace(`[jaypie] Locals: ${key}`);
278
292
  if (typeof locals[key] === "function") {
279
293
  // eslint-disable-next-line no-await-in-loop
280
- req.locals[key] = await locals[key](req, res);
294
+ localsReq.locals[key] = await locals[key](localsReq, localsRes);
281
295
  } else {
282
- req.locals[key] = locals[key];
296
+ localsReq.locals[key] = locals[key];
283
297
  }
284
298
  }
285
299
  };
@@ -194,6 +194,11 @@ const expressHandler = (
194
194
  const libLogger = log.lib({
195
195
  lib: JAYPIE.LIB.EXPRESS,
196
196
  });
197
+ // Top-level, important details that run at the same level as the main logger
198
+ const log$1 = log.lib({
199
+ level: log.level,
200
+ lib: JAYPIE.LIB.EXPRESS,
201
+ });
197
202
 
198
203
  // Update the public logger with the request ID
199
204
  const invokeUuid = getCurrentInvokeUuid();
@@ -203,15 +208,24 @@ const expressHandler = (
203
208
  // TODO: in theory this is redundant
204
209
  libLogger.tag({ invoke: invokeUuid });
205
210
  libLogger.tag({ shortInvoke: invokeUuid.slice(0, 8) });
211
+ log$1.tag({ invoke: invokeUuid });
212
+ log$1.tag({ shortInvoke: invokeUuid.slice(0, 8) });
206
213
  }
207
214
 
208
- libLogger.trace("[jaypie] Express init");
215
+ if (!name) {
216
+ // If handler has a name, use it
217
+ if (handler.name) {
218
+ name = handler.name;
219
+ } else {
220
+ name = JAYPIE.UNKNOWN;
221
+ }
222
+ }
223
+ log.tag({ handler: name });
224
+ // TODO: in theory this is redundant
225
+ libLogger.tag({ handler: name });
226
+ log$1.tag({ handler: name });
209
227
 
210
- // Top-level, important details that run at the same level as the main logger
211
- const log$1 = log.lib({
212
- level: log.level,
213
- lib: JAYPIE.LIB.EXPRESS,
214
- });
228
+ libLogger.trace("[jaypie] Express init");
215
229
 
216
230
  // Set req.locals if it doesn't exist
217
231
  if (!req.locals) req.locals = {};
@@ -269,15 +283,15 @@ const expressHandler = (
269
283
  // Locals
270
284
  const keys = Object.keys(locals);
271
285
  if (keys.length > 0) {
272
- const localsSetup = async () => {
286
+ const localsSetup = async (localsReq, localsRes) => {
273
287
  for (let i = 0; i < keys.length; i += 1) {
274
288
  const key = keys[i];
275
289
  libLogger.trace(`[jaypie] Locals: ${key}`);
276
290
  if (typeof locals[key] === "function") {
277
291
  // eslint-disable-next-line no-await-in-loop
278
- req.locals[key] = await locals[key](req, res);
292
+ localsReq.locals[key] = await locals[key](localsReq, localsRes);
279
293
  } else {
280
- req.locals[key] = locals[key];
294
+ localsReq.locals[key] = locals[key];
281
295
  }
282
296
  }
283
297
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/express",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "author": "Finlayson Studio",
5
5
  "type": "module",
6
6
  "exports": {
@@ -45,7 +45,7 @@
45
45
  "@jaypie/core": "^1.0.41"
46
46
  },
47
47
  "devDependencies": {
48
- "@jaypie/testkit": "^1.0.19",
48
+ "@jaypie/testkit": "^1.0.20",
49
49
  "@rollup/plugin-commonjs": "^26.0.1",
50
50
  "@rollup/plugin-node-resolve": "^15.2.3",
51
51
  "eslint": "^8.57.0",
@@ -47,6 +47,11 @@ const expressHandler = (
47
47
  const libLogger = publicLogger.lib({
48
48
  lib: JAYPIE.LIB.EXPRESS,
49
49
  });
50
+ // Top-level, important details that run at the same level as the main logger
51
+ const log = publicLogger.lib({
52
+ level: publicLogger.level,
53
+ lib: JAYPIE.LIB.EXPRESS,
54
+ });
50
55
 
51
56
  // Update the public logger with the request ID
52
57
  const invokeUuid = getCurrentInvokeUuid();
@@ -56,15 +61,24 @@ const expressHandler = (
56
61
  // TODO: in theory this is redundant
57
62
  libLogger.tag({ invoke: invokeUuid });
58
63
  libLogger.tag({ shortInvoke: invokeUuid.slice(0, 8) });
64
+ log.tag({ invoke: invokeUuid });
65
+ log.tag({ shortInvoke: invokeUuid.slice(0, 8) });
59
66
  }
60
67
 
61
- libLogger.trace("[jaypie] Express init");
68
+ if (!name) {
69
+ // If handler has a name, use it
70
+ if (handler.name) {
71
+ name = handler.name;
72
+ } else {
73
+ name = JAYPIE.UNKNOWN;
74
+ }
75
+ }
76
+ publicLogger.tag({ handler: name });
77
+ // TODO: in theory this is redundant
78
+ libLogger.tag({ handler: name });
79
+ log.tag({ handler: name });
62
80
 
63
- // Top-level, important details that run at the same level as the main logger
64
- const log = publicLogger.lib({
65
- level: publicLogger.level,
66
- lib: JAYPIE.LIB.EXPRESS,
67
- });
81
+ libLogger.trace("[jaypie] Express init");
68
82
 
69
83
  // Set req.locals if it doesn't exist
70
84
  if (!req.locals) req.locals = {};
@@ -122,15 +136,15 @@ const expressHandler = (
122
136
  // Locals
123
137
  const keys = Object.keys(locals);
124
138
  if (keys.length > 0) {
125
- const localsSetup = async () => {
139
+ const localsSetup = async (localsReq, localsRes) => {
126
140
  for (let i = 0; i < keys.length; i += 1) {
127
141
  const key = keys[i];
128
142
  libLogger.trace(`[jaypie] Locals: ${key}`);
129
143
  if (typeof locals[key] === "function") {
130
144
  // eslint-disable-next-line no-await-in-loop
131
- req.locals[key] = await locals[key](req, res);
145
+ localsReq.locals[key] = await locals[key](localsReq, localsRes);
132
146
  } else {
133
- req.locals[key] = locals[key];
147
+ localsReq.locals[key] = locals[key];
134
148
  }
135
149
  }
136
150
  };