@budibase/backend-core 2.5.6-alpha.42 → 2.5.6-alpha.44

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/backend-core",
3
- "version": "2.5.6-alpha.42",
3
+ "version": "2.5.6-alpha.44",
4
4
  "description": "Budibase backend core libraries used in server and worker",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@budibase/nano": "10.1.2",
26
26
  "@budibase/pouchdb-replication-stream": "1.2.10",
27
- "@budibase/types": "2.5.6-alpha.42",
27
+ "@budibase/types": "2.5.6-alpha.44",
28
28
  "@shopify/jest-koa-mocks": "5.0.1",
29
29
  "@techpass/passport-openidconnect": "0.3.2",
30
30
  "aws-cloudfront-sign": "2.2.0",
@@ -90,5 +90,5 @@
90
90
  "tsconfig-paths": "4.0.0",
91
91
  "typescript": "4.7.3"
92
92
  },
93
- "gitHead": "e11b03273c6a691698b672901736eb38a5132be2"
93
+ "gitHead": "e971aa3e642cf65ab66fbf07c1c1bcc079de8482"
94
94
  }
@@ -154,6 +154,7 @@ const environment = {
154
154
  ? process.env.ENABLE_SSO_MAINTENANCE_MODE
155
155
  : false,
156
156
  VERSION: findVersion(),
157
+ DISABLE_PINO_LOGGER: process.env.DISABLE_PINO_LOGGER,
157
158
  _set(key: any, value: any) {
158
159
  process.env[key] = value
159
160
  // @ts-ignore
@@ -1,5 +1,5 @@
1
1
  export * as correlation from "./correlation/correlation"
2
- export { logger, disableLogger } from "./pino/logger"
2
+ export { logger } from "./pino/logger"
3
3
  export * from "./alerts"
4
4
 
5
5
  // turn off or on context logging i.e. tenantId, appId etc
@@ -5,184 +5,169 @@ import * as correlation from "../correlation"
5
5
  import { IdentityType } from "@budibase/types"
6
6
  import { LOG_CONTEXT } from "../index"
7
7
 
8
- // CORE LOGGERS - for disabling
9
-
10
- const BUILT_INS = {
11
- log: console.log,
12
- error: console.error,
13
- info: console.info,
14
- warn: console.warn,
15
- trace: console.trace,
16
- debug: console.debug,
17
- }
18
-
19
8
  // LOGGER
20
9
 
21
- const pinoOptions: LoggerOptions = {
22
- level: env.LOG_LEVEL,
23
- formatters: {
24
- level: label => {
25
- return { level: label.toUpperCase() }
26
- },
27
- bindings: () => {
28
- return {}
29
- },
30
- },
31
- timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
32
- }
33
-
34
- if (env.isDev()) {
35
- pinoOptions.transport = {
36
- target: "pino-pretty",
37
- options: {
38
- singleLine: true,
10
+ let pinoInstance: pino.Logger | undefined
11
+ if (!env.DISABLE_PINO_LOGGER) {
12
+ const pinoOptions: LoggerOptions = {
13
+ level: env.LOG_LEVEL,
14
+ formatters: {
15
+ level: label => {
16
+ return { level: label.toUpperCase() }
17
+ },
18
+ bindings: () => {
19
+ return {}
20
+ },
39
21
  },
22
+ timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
40
23
  }
41
- }
42
24
 
43
- export const logger = pino(pinoOptions)
25
+ if (env.isDev()) {
26
+ pinoOptions.transport = {
27
+ target: "pino-pretty",
28
+ options: {
29
+ singleLine: true,
30
+ },
31
+ }
32
+ }
44
33
 
45
- export function disableLogger() {
46
- console.log = BUILT_INS.log
47
- console.error = BUILT_INS.error
48
- console.info = BUILT_INS.info
49
- console.warn = BUILT_INS.warn
50
- console.trace = BUILT_INS.trace
51
- console.debug = BUILT_INS.debug
52
- }
34
+ pinoInstance = pino(pinoOptions)
53
35
 
54
- // CONSOLE OVERRIDES
36
+ // CONSOLE OVERRIDES
55
37
 
56
- interface MergingObject {
57
- objects?: any[]
58
- tenantId?: string
59
- appId?: string
60
- identityId?: string
61
- identityType?: IdentityType
62
- correlationId?: string
63
- err?: Error
64
- }
38
+ interface MergingObject {
39
+ objects?: any[]
40
+ tenantId?: string
41
+ appId?: string
42
+ identityId?: string
43
+ identityType?: IdentityType
44
+ correlationId?: string
45
+ err?: Error
46
+ }
65
47
 
66
- function isPlainObject(obj: any) {
67
- return typeof obj === "object" && obj !== null && !(obj instanceof Error)
68
- }
48
+ function isPlainObject(obj: any) {
49
+ return typeof obj === "object" && obj !== null && !(obj instanceof Error)
50
+ }
69
51
 
70
- function isError(obj: any) {
71
- return obj instanceof Error
72
- }
52
+ function isError(obj: any) {
53
+ return obj instanceof Error
54
+ }
73
55
 
74
- function isMessage(obj: any) {
75
- return typeof obj === "string"
76
- }
56
+ function isMessage(obj: any) {
57
+ return typeof obj === "string"
58
+ }
77
59
 
78
- /**
79
- * Backwards compatibility between console logging statements
80
- * and pino logging requirements.
81
- */
82
- function getLogParams(args: any[]): [MergingObject, string] {
83
- let error = undefined
84
- let objects: any[] = []
85
- let message = ""
86
-
87
- args.forEach(arg => {
88
- if (isMessage(arg)) {
89
- message = `${message} ${arg}`.trimStart()
90
- }
91
- if (isPlainObject(arg)) {
92
- objects.push(arg)
60
+ /**
61
+ * Backwards compatibility between console logging statements
62
+ * and pino logging requirements.
63
+ */
64
+ function getLogParams(args: any[]): [MergingObject, string] {
65
+ let error = undefined
66
+ let objects: any[] = []
67
+ let message = ""
68
+
69
+ args.forEach(arg => {
70
+ if (isMessage(arg)) {
71
+ message = `${message} ${arg}`.trimStart()
72
+ }
73
+ if (isPlainObject(arg)) {
74
+ objects.push(arg)
75
+ }
76
+ if (isError(arg)) {
77
+ error = arg
78
+ }
79
+ })
80
+
81
+ const identity = getIdentity()
82
+
83
+ let contextObject = {}
84
+
85
+ if (LOG_CONTEXT) {
86
+ contextObject = {
87
+ tenantId: getTenantId(),
88
+ appId: getAppId(),
89
+ identityId: identity?._id,
90
+ identityType: identity?.type,
91
+ correlationId: correlation.getId(),
92
+ }
93
93
  }
94
- if (isError(arg)) {
95
- error = arg
94
+
95
+ const mergingObject = {
96
+ objects: objects.length ? objects : undefined,
97
+ err: error,
98
+ ...contextObject,
96
99
  }
97
- })
98
100
 
99
- const identity = getIdentity()
101
+ return [mergingObject, message]
102
+ }
100
103
 
101
- let contextObject = {}
104
+ console.log = (...arg: any[]) => {
105
+ const [obj, msg] = getLogParams(arg)
106
+ pinoInstance?.info(obj, msg)
107
+ }
108
+ console.info = (...arg: any[]) => {
109
+ const [obj, msg] = getLogParams(arg)
110
+ pinoInstance?.info(obj, msg)
111
+ }
112
+ console.warn = (...arg: any[]) => {
113
+ const [obj, msg] = getLogParams(arg)
114
+ pinoInstance?.warn(obj, msg)
115
+ }
116
+ console.error = (...arg: any[]) => {
117
+ const [obj, msg] = getLogParams(arg)
118
+ pinoInstance?.error(obj, msg)
119
+ }
102
120
 
103
- if (LOG_CONTEXT) {
104
- contextObject = {
105
- tenantId: getTenantId(),
106
- appId: getAppId(),
107
- identityId: identity?._id,
108
- identityType: identity?.type,
109
- correlationId: correlation.getId(),
121
+ /**
122
+ * custom trace impl - this resembles the node trace behaviour rather
123
+ * than traditional trace logging
124
+ * @param arg
125
+ */
126
+ console.trace = (...arg: any[]) => {
127
+ const [obj, msg] = getLogParams(arg)
128
+ if (!obj.err) {
129
+ // to get stack trace
130
+ obj.err = new Error()
110
131
  }
132
+ pinoInstance?.trace(obj, msg)
111
133
  }
112
134
 
113
- const mergingObject = {
114
- objects: objects.length ? objects : undefined,
115
- err: error,
116
- ...contextObject,
135
+ console.debug = (...arg: any) => {
136
+ const [obj, msg] = getLogParams(arg)
137
+ pinoInstance?.debug(obj, msg)
117
138
  }
118
139
 
119
- return [mergingObject, message]
120
- }
140
+ // CONTEXT
121
141
 
122
- console.log = (...arg: any[]) => {
123
- const [obj, msg] = getLogParams(arg)
124
- logger.info(obj, msg)
125
- }
126
- console.info = (...arg: any[]) => {
127
- const [obj, msg] = getLogParams(arg)
128
- logger.info(obj, msg)
129
- }
130
- console.warn = (...arg: any[]) => {
131
- const [obj, msg] = getLogParams(arg)
132
- logger.warn(obj, msg)
133
- }
134
- console.error = (...arg: any[]) => {
135
- const [obj, msg] = getLogParams(arg)
136
- logger.error(obj, msg)
137
- }
138
-
139
- /**
140
- * custom trace impl - this resembles the node trace behaviour rather
141
- * than traditional trace logging
142
- * @param arg
143
- */
144
- console.trace = (...arg: any[]) => {
145
- const [obj, msg] = getLogParams(arg)
146
- if (!obj.err) {
147
- // to get stack trace
148
- obj.err = new Error()
149
- }
150
- logger.trace(obj, msg)
151
- }
152
-
153
- console.debug = (...arg: any) => {
154
- const [obj, msg] = getLogParams(arg)
155
- logger.debug(obj, msg)
156
- }
157
-
158
- // CONTEXT
159
-
160
- const getTenantId = () => {
161
- let tenantId
162
- try {
163
- tenantId = context.getTenantId()
164
- } catch (e: any) {
165
- // do nothing
142
+ const getTenantId = () => {
143
+ let tenantId
144
+ try {
145
+ tenantId = context.getTenantId()
146
+ } catch (e: any) {
147
+ // do nothing
148
+ }
149
+ return tenantId
166
150
  }
167
- return tenantId
168
- }
169
151
 
170
- const getAppId = () => {
171
- let appId
172
- try {
173
- appId = context.getAppId()
174
- } catch (e) {
175
- // do nothing
152
+ const getAppId = () => {
153
+ let appId
154
+ try {
155
+ appId = context.getAppId()
156
+ } catch (e) {
157
+ // do nothing
158
+ }
159
+ return appId
176
160
  }
177
- return appId
178
- }
179
161
 
180
- const getIdentity = () => {
181
- let identity
182
- try {
183
- identity = context.getIdentity()
184
- } catch (e) {
185
- // do nothing
162
+ const getIdentity = () => {
163
+ let identity
164
+ try {
165
+ identity = context.getIdentity()
166
+ } catch (e) {
167
+ // do nothing
168
+ }
169
+ return identity
186
170
  }
187
- return identity
188
171
  }
172
+
173
+ export const logger = pinoInstance