@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/dist/package.json +3 -3
- package/dist/src/environment.d.ts +1 -0
- package/dist/src/environment.js +1 -0
- package/dist/src/environment.js.map +1 -1
- package/dist/src/logging/index.d.ts +1 -1
- package/dist/src/logging/index.js +1 -2
- package/dist/src/logging/index.js.map +1 -1
- package/dist/src/logging/pino/logger.d.ts +2 -3
- package/dist/src/logging/pino/logger.js +124 -138
- package/dist/src/logging/pino/logger.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/environment.ts +1 -0
- package/src/logging/index.ts +1 -1
- package/src/logging/pino/logger.ts +137 -152
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/backend-core",
|
|
3
|
-
"version": "2.5.6-alpha.
|
|
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.
|
|
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": "
|
|
93
|
+
"gitHead": "e971aa3e642cf65ab66fbf07c1c1bcc079de8482"
|
|
94
94
|
}
|
package/src/environment.ts
CHANGED
package/src/logging/index.ts
CHANGED
|
@@ -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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
level:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
25
|
+
if (env.isDev()) {
|
|
26
|
+
pinoOptions.transport = {
|
|
27
|
+
target: "pino-pretty",
|
|
28
|
+
options: {
|
|
29
|
+
singleLine: true,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
}
|
|
44
33
|
|
|
45
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
}
|
|
52
|
+
function isError(obj: any) {
|
|
53
|
+
return obj instanceof Error
|
|
54
|
+
}
|
|
73
55
|
|
|
74
|
-
function isMessage(obj: any) {
|
|
75
|
-
|
|
76
|
-
}
|
|
56
|
+
function isMessage(obj: any) {
|
|
57
|
+
return typeof obj === "string"
|
|
58
|
+
}
|
|
77
59
|
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
function getLogParams(args: any[]): [MergingObject, string] {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
|
|
94
|
+
|
|
95
|
+
const mergingObject = {
|
|
96
|
+
objects: objects.length ? objects : undefined,
|
|
97
|
+
err: error,
|
|
98
|
+
...contextObject,
|
|
96
99
|
}
|
|
97
|
-
})
|
|
98
100
|
|
|
99
|
-
|
|
101
|
+
return [mergingObject, message]
|
|
102
|
+
}
|
|
100
103
|
|
|
101
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
...contextObject,
|
|
135
|
+
console.debug = (...arg: any) => {
|
|
136
|
+
const [obj, msg] = getLogParams(arg)
|
|
137
|
+
pinoInstance?.debug(obj, msg)
|
|
117
138
|
}
|
|
118
139
|
|
|
119
|
-
|
|
120
|
-
}
|
|
140
|
+
// CONTEXT
|
|
121
141
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|