@naturalcycles/backend-lib 9.30.3 → 9.31.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.
@@ -96,6 +96,7 @@ export class SentrySharedService {
96
96
  */
97
97
  getCommonLogger() {
98
98
  return {
99
+ debug: () => { }, // noop
99
100
  log: () => { }, // noop
100
101
  warn: () => { }, // noop
101
102
  error: (...args) => {
@@ -38,6 +38,7 @@ export function getRequestLogger() {
38
38
  * @experimental
39
39
  */
40
40
  export const requestLogger = {
41
+ debug: (...args) => getRequestLogger().debug(...args),
41
42
  log: (...args) => getRequestLogger().log(...args),
42
43
  warn: (...args) => getRequestLogger().warn(...args),
43
44
  error: (...args) => getRequestLogger().error(...args),
@@ -1,4 +1,5 @@
1
1
  import { inspect } from 'node:util';
2
+ import { _objectAssign } from '@naturalcycles/js-lib/types';
2
3
  import { _inspect } from '@naturalcycles/nodejs-lib';
3
4
  import { dimGrey } from '@naturalcycles/nodejs-lib/colors';
4
5
  const { GOOGLE_CLOUD_PROJECT, GAE_INSTANCE, K_SERVICE, APP_ENV } = process.env;
@@ -13,6 +14,7 @@ let reqCounter = 0;
13
14
  * To be used in outside-of-request situations (otherwise req.log should be used).
14
15
  */
15
16
  export const gcpStructuredLogger = {
17
+ debug: (...args) => writeGCPStructuredLog({ severity: 'DEBUG' }, args),
16
18
  log: (...args) => writeGCPStructuredLog({}, args),
17
19
  warn: (...args) => writeGCPStructuredLog({ severity: 'WARNING' }, args),
18
20
  error: (...args) => writeGCPStructuredLog({ severity: 'ERROR' }, args),
@@ -22,6 +24,7 @@ export const gcpStructuredLogger = {
22
24
  * (otherwise req.log should be used).
23
25
  */
24
26
  export const devLogger = {
27
+ debug: (...args) => logToDev(null, args),
25
28
  log: (...args) => logToDev(null, args),
26
29
  warn: (...args) => logToDev(null, args),
27
30
  error: (...args) => logToDev(null, args),
@@ -30,6 +33,7 @@ export const devLogger = {
30
33
  * Same as devLogger, but without colors (e.g to not confuse Sentry).
31
34
  */
32
35
  export const ciLogger = {
36
+ debug: (...args) => logToCI(args),
33
37
  log: (...args) => logToCI(args),
34
38
  warn: (...args) => logToCI(args),
35
39
  error: (...args) => logToCI(args),
@@ -81,7 +85,8 @@ export function logMiddleware() {
81
85
  if (isGAE) {
82
86
  meta['appengine.googleapis.com/request_id'] = req.header('x-appengine-request-log-id');
83
87
  }
84
- Object.assign(req, {
88
+ _objectAssign(req, {
89
+ debug: (...args) => writeGCPStructuredLog({ ...meta, severity: 'DEBUG' }, args),
85
90
  log: (...args) => writeGCPStructuredLog({ ...meta, severity: 'INFO' }, args),
86
91
  warn: (...args) => writeGCPStructuredLog({ ...meta, severity: 'WARNING' }, args),
87
92
  error: (...args) => writeGCPStructuredLog({ ...meta, severity: 'ERROR' }, args),
@@ -94,14 +99,18 @@ export function logMiddleware() {
94
99
  return function devLogHandler(req, _res, next) {
95
100
  // Local machine
96
101
  req.requestId = String(++reqCounter);
97
- req.log = req.warn = req.error = (...args) => logToDev(req.requestId, args);
102
+ req.debug =
103
+ req.log =
104
+ req.warn =
105
+ req.error =
106
+ (...args) => logToDev(req.requestId, args);
98
107
  next();
99
108
  };
100
109
  }
101
110
  // Otherwise, return "simple" logger
102
111
  // This includes: unit tests, CI environments
103
112
  return function simpleLogHandler(req, _res, next) {
104
- req.log = req.warn = req.error = (...args) => logToCI(args);
113
+ req.debug = req.log = req.warn = req.error = (...args) => logToCI(args);
105
114
  next();
106
115
  };
107
116
  }
@@ -9,6 +9,7 @@ import type { Application, IRouter, NextFunction, Request, Response } from 'expr
9
9
  * Previous name `ExpressRequest` was clashing with Sentry.
10
10
  */
11
11
  export interface BackendRequest extends Request {
12
+ debug: CommonLogFunction;
12
13
  log: CommonLogFunction;
13
14
  warn: CommonLogFunction;
14
15
  error: CommonLogFunction;
@@ -31,6 +32,7 @@ export type BackendRouter = IRouter;
31
32
  export type BackendApplication = Application;
32
33
  declare module 'http' {
33
34
  interface IncomingMessage {
35
+ debug: CommonLogFunction;
34
36
  log: CommonLogFunction;
35
37
  warn: CommonLogFunction;
36
38
  error: CommonLogFunction;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.30.3",
4
+ "version": "9.31.0",
5
5
  "peerDependencies": {
6
6
  "@sentry/node": "^10"
7
7
  },
@@ -29,7 +29,7 @@
29
29
  "@sentry/node": "^10",
30
30
  "@types/ejs": "^3",
31
31
  "fastify": "^5",
32
- "@naturalcycles/dev-lib": "19.34.0"
32
+ "@naturalcycles/dev-lib": "18.4.2"
33
33
  },
34
34
  "exports": {
35
35
  ".": "./dist/index.js",
@@ -123,6 +123,7 @@ export class SentrySharedService {
123
123
  */
124
124
  getCommonLogger(): CommonLogger {
125
125
  return {
126
+ debug: () => {}, // noop
126
127
  log: () => {}, // noop
127
128
  warn: () => {}, // noop
128
129
  error: (...args) => {
@@ -53,6 +53,7 @@ export function getRequestLogger(): CommonLogger {
53
53
  * @experimental
54
54
  */
55
55
  export const requestLogger: CommonLogger = {
56
+ debug: (...args) => getRequestLogger().debug(...args),
56
57
  log: (...args) => getRequestLogger().log(...args),
57
58
  warn: (...args) => getRequestLogger().warn(...args),
58
59
  error: (...args) => getRequestLogger().error(...args),
@@ -1,6 +1,6 @@
1
1
  import { inspect } from 'node:util'
2
2
  import type { CommonLogger } from '@naturalcycles/js-lib/log'
3
- import type { AnyObject } from '@naturalcycles/js-lib/types'
3
+ import { _objectAssign, type AnyObject } from '@naturalcycles/js-lib/types'
4
4
  import { _inspect } from '@naturalcycles/nodejs-lib'
5
5
  import { dimGrey } from '@naturalcycles/nodejs-lib/colors'
6
6
  import type { BackendRequestHandler } from './server.model.js'
@@ -19,6 +19,7 @@ let reqCounter = 0
19
19
  * To be used in outside-of-request situations (otherwise req.log should be used).
20
20
  */
21
21
  export const gcpStructuredLogger: CommonLogger = {
22
+ debug: (...args) => writeGCPStructuredLog({ severity: 'DEBUG' }, args),
22
23
  log: (...args) => writeGCPStructuredLog({}, args),
23
24
  warn: (...args) => writeGCPStructuredLog({ severity: 'WARNING' }, args),
24
25
  error: (...args) => writeGCPStructuredLog({ severity: 'ERROR' }, args),
@@ -29,6 +30,7 @@ export const gcpStructuredLogger: CommonLogger = {
29
30
  * (otherwise req.log should be used).
30
31
  */
31
32
  export const devLogger: CommonLogger = {
33
+ debug: (...args) => logToDev(null, args),
32
34
  log: (...args) => logToDev(null, args),
33
35
  warn: (...args) => logToDev(null, args),
34
36
  error: (...args) => logToDev(null, args),
@@ -38,6 +40,7 @@ export const devLogger: CommonLogger = {
38
40
  * Same as devLogger, but without colors (e.g to not confuse Sentry).
39
41
  */
40
42
  export const ciLogger: CommonLogger = {
43
+ debug: (...args) => logToCI(args),
41
44
  log: (...args) => logToCI(args),
42
45
  warn: (...args) => logToCI(args),
43
46
  error: (...args) => logToCI(args),
@@ -99,11 +102,12 @@ export function logMiddleware(): BackendRequestHandler {
99
102
  meta['appengine.googleapis.com/request_id'] = req.header('x-appengine-request-log-id')
100
103
  }
101
104
 
102
- Object.assign(req, {
105
+ _objectAssign(req, {
106
+ debug: (...args: any[]) => writeGCPStructuredLog({ ...meta, severity: 'DEBUG' }, args),
103
107
  log: (...args: any[]) => writeGCPStructuredLog({ ...meta, severity: 'INFO' }, args),
104
108
  warn: (...args: any[]) => writeGCPStructuredLog({ ...meta, severity: 'WARNING' }, args),
105
109
  error: (...args: any[]) => writeGCPStructuredLog({ ...meta, severity: 'ERROR' }, args),
106
- })
110
+ } satisfies CommonLogger)
107
111
 
108
112
  next()
109
113
  }
@@ -114,7 +118,11 @@ export function logMiddleware(): BackendRequestHandler {
114
118
  return function devLogHandler(req, _res, next) {
115
119
  // Local machine
116
120
  req.requestId = String(++reqCounter)
117
- req.log = req.warn = req.error = (...args: any[]) => logToDev(req.requestId!, args)
121
+ req.debug =
122
+ req.log =
123
+ req.warn =
124
+ req.error =
125
+ (...args: any[]) => logToDev(req.requestId!, args)
118
126
  next()
119
127
  }
120
128
  }
@@ -122,7 +130,7 @@ export function logMiddleware(): BackendRequestHandler {
122
130
  // Otherwise, return "simple" logger
123
131
  // This includes: unit tests, CI environments
124
132
  return function simpleLogHandler(req, _res, next) {
125
- req.log = req.warn = req.error = (...args: any[]) => logToCI(args)
133
+ req.debug = req.log = req.warn = req.error = (...args: any[]) => logToCI(args)
126
134
  next()
127
135
  }
128
136
  }
@@ -10,6 +10,7 @@ import type { Application, IRouter, NextFunction, Request, Response } from 'expr
10
10
  * Previous name `ExpressRequest` was clashing with Sentry.
11
11
  */
12
12
  export interface BackendRequest extends Request {
13
+ debug: CommonLogFunction
13
14
  log: CommonLogFunction
14
15
  warn: CommonLogFunction
15
16
  error: CommonLogFunction
@@ -49,6 +50,7 @@ export type BackendApplication = Application
49
50
 
50
51
  declare module 'http' {
51
52
  interface IncomingMessage {
53
+ debug: CommonLogFunction
52
54
  log: CommonLogFunction
53
55
  warn: CommonLogFunction
54
56
  error: CommonLogFunction