@vrplatform/log 2.0.45 → 2.0.47
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/build/main/log/baselog.d.ts +1 -9
- package/build/main/log/baselog.js +19 -9
- package/build/main/log/baselog.js.map +1 -1
- package/build/main/log/index.d.ts +2 -8
- package/build/main/log/index.js +1 -1
- package/build/main/log/index.js.map +1 -1
- package/build/main/log/index.spec.d.ts +1 -0
- package/build/main/log/index.spec.js +57 -0
- package/build/main/log/index.spec.js.map +1 -1
- package/build/main/log/type.d.ts +22 -2
- package/build/main/tsconfig.main.tsbuildinfo +1 -0
- package/build/module/log/baselog.d.ts +1 -9
- package/build/module/log/baselog.js +19 -9
- package/build/module/log/baselog.js.map +1 -1
- package/build/module/log/index.d.ts +2 -8
- package/build/module/log/index.js +1 -1
- package/build/module/log/index.js.map +1 -1
- package/build/module/log/index.spec.d.ts +1 -0
- package/build/module/log/index.spec.js +56 -1
- package/build/module/log/index.spec.js.map +1 -1
- package/build/module/log/type.d.ts +22 -2
- package/build/module/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +8 -11
- package/src/log/baselog.ts +26 -23
- package/src/log/index.ts +5 -8
- package/src/log/type.ts +25 -3
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import type { BaseLog,
|
|
2
|
-
export type ConsoleLogFn = (arg: {
|
|
3
|
-
formatted: string;
|
|
4
|
-
message: string;
|
|
5
|
-
additionalContext: Record<string, any>;
|
|
6
|
-
level: LogLevel;
|
|
7
|
-
error?: Error;
|
|
8
|
-
}) => void;
|
|
9
|
-
export type ConsoleLog = boolean | 'color' | ConsoleLogFn;
|
|
1
|
+
import type { BaseLog, ConsoleLog } from './type';
|
|
10
2
|
export declare function createBaseLog({ token, orgId, dataset, consoleLog, }: {
|
|
11
3
|
token?: string;
|
|
12
4
|
orgId?: string;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createBaseLog = createBaseLog;
|
|
4
4
|
const js_1 = require("@axiomhq/js");
|
|
5
|
-
const serialize_error_1 = require("serialize-error");
|
|
6
5
|
const color_1 = require("./color");
|
|
7
6
|
const common_1 = require("./common");
|
|
8
7
|
let lastMessageTimestamp = undefined;
|
|
@@ -42,15 +41,15 @@ function createBaseLog({ token, orgId = 'vrplatform-mv6k', dataset, consoleLog,
|
|
|
42
41
|
if (arg.request) {
|
|
43
42
|
childContext.request = (0, common_1.requestToContext)(arg.request);
|
|
44
43
|
}
|
|
45
|
-
const baseLog = (level, message,
|
|
44
|
+
const baseLog = (level, message, extra = {}, error) => {
|
|
46
45
|
const cid = arg.correlationId ||
|
|
47
46
|
correlationId ||
|
|
48
47
|
childContext?.correlationId ||
|
|
49
|
-
|
|
48
|
+
extra?.correlationId ||
|
|
50
49
|
correlationId;
|
|
51
50
|
ingest(level, message, {
|
|
52
51
|
...childContext,
|
|
53
|
-
...
|
|
52
|
+
...extra,
|
|
54
53
|
correlationId: cid,
|
|
55
54
|
sessionId: sid,
|
|
56
55
|
});
|
|
@@ -69,8 +68,18 @@ function createBaseLog({ token, orgId = 'vrplatform-mv6k', dataset, consoleLog,
|
|
|
69
68
|
formatted,
|
|
70
69
|
level,
|
|
71
70
|
message,
|
|
72
|
-
|
|
71
|
+
extra,
|
|
73
72
|
error,
|
|
73
|
+
tags: {
|
|
74
|
+
sessionId: sid,
|
|
75
|
+
correlationId: cid,
|
|
76
|
+
environment,
|
|
77
|
+
workerId,
|
|
78
|
+
app,
|
|
79
|
+
version,
|
|
80
|
+
type,
|
|
81
|
+
name,
|
|
82
|
+
},
|
|
74
83
|
});
|
|
75
84
|
else if (consoleLog === 'color')
|
|
76
85
|
color_1.logger
|
|
@@ -90,7 +99,7 @@ function createBaseLog({ token, orgId = 'vrplatform-mv6k', dataset, consoleLog,
|
|
|
90
99
|
.append(message)
|
|
91
100
|
.log();
|
|
92
101
|
else
|
|
93
|
-
console.log(formatted,
|
|
102
|
+
console.log(formatted, extra);
|
|
94
103
|
if (error)
|
|
95
104
|
console.error(error);
|
|
96
105
|
}
|
|
@@ -109,12 +118,13 @@ function createBaseLog({ token, orgId = 'vrplatform-mv6k', dataset, consoleLog,
|
|
|
109
118
|
request,
|
|
110
119
|
context: { ...childContext, ...context },
|
|
111
120
|
}),
|
|
112
|
-
error: (message, error) => {
|
|
121
|
+
error: (message, error, data) => {
|
|
113
122
|
const m = typeof message === 'string'
|
|
114
123
|
? message
|
|
115
124
|
: error?.message || error?.name || 'Error';
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
if (error && error instanceof Error)
|
|
126
|
+
return baseLog('error', m, data, error);
|
|
127
|
+
return baseLog('error', m, error);
|
|
118
128
|
},
|
|
119
129
|
debug: (message, data) => baseLog('debug', message, data),
|
|
120
130
|
warn: (message, data) => baseLog('warn', message, data),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baselog.js","sourceRoot":"src/","sources":["log/baselog.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"baselog.js","sourceRoot":"src/","sources":["log/baselog.ts"],"names":[],"mappings":";;AAcA,sCAiMC;AA/MD,oCAAoC;AAEpC,mCAAiC;AACjC,qCAA8D;AAS9D,IAAI,oBAAoB,GAAuB,SAAS,CAAC;AAEzD,SAAgB,aAAa,CAC3B,EACE,KAAK,EACL,KAAK,GAAG,iBAAiB,EACzB,OAAO,EACP,UAAU,GAMX,EACD,EACE,WAAW,EACX,QAAQ,EACR,GAAG,EACH,OAAO,EACP,OAAO,EACP,IAAI,EACJ,aAAa,EACb,SAAS,EACT,gBAAgB,GAajB;IAED,MAAM,UAAU,GAAwB;QACtC,IAAI,EAAE,IAAI,IAAI,QAAQ;QACtB,WAAW,EAAE,WAAW,IAAI,YAAY;QACxC,MAAM,EAAE;YACN,EAAE,EAAE,QAAQ,IAAI,SAAS;YACzB,GAAG,EAAE,GAAG,IAAI,SAAS;YACrB,OAAO,EAAE,OAAO,IAA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O,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;gBAC9B,MAAM,CAAC,GACL,OAAO,OAAO,KAAK,QAAQ;oBACzB,CAAC,CAAC,OAAO;oBACT,CAAC,CAAC,KAAK,EAAE,OAAO,IAAI,KAAK,EAAE,IAAI,IAAI,OAAO,CAAC;gBAC/C,IAAI,KAAK,IAAI,KAAK,YAAY,KAAK;oBACjC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC1C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;YACpC,CAAC;YACD,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;YACzD,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;YACvD,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;SACxD,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,aAAa,EAAoB,CAAC;IAClD,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE;QACnB,IAAI,gBAAgB,IAAI,KAAK,EAAE,CAAC;YAC9B,gBAAgB,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAC5C,CAAC;aAAM,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import { type ConsoleLog } from './baselog';
|
|
2
1
|
import { requestToContext } from './common';
|
|
3
|
-
import { type LogBindings, type RequestLike, type WorkerLog } from './type';
|
|
2
|
+
import { type ConsoleLog, type LogBindings, type LogTags, type RequestLike, type WorkerLog } from './type';
|
|
4
3
|
export * from './common';
|
|
5
4
|
export * from './baselog';
|
|
6
5
|
export * from './type';
|
|
7
|
-
export declare function useLog({ environment: _environment, name, request, body, env, correlationId: cid, sessionId: sid, version, executionContext, logRequest, consoleLog: _consoleLog, dataset: _dataset, context: initialContext, }: {
|
|
8
|
-
environment?: string;
|
|
9
|
-
name: string;
|
|
6
|
+
export declare function useLog({ environment: _environment, name, request, body, env, correlationId: cid, sessionId: sid, version, executionContext, logRequest, consoleLog: _consoleLog, dataset: _dataset, context: initialContext, }: Partial<LogTags> & {
|
|
10
7
|
request?: RequestLike & {
|
|
11
8
|
cf?: any;
|
|
12
9
|
};
|
|
13
10
|
logRequest?: boolean | ((raw: ReturnType<typeof requestToContext>) => any);
|
|
14
11
|
body?: any;
|
|
15
|
-
correlationId?: string;
|
|
16
|
-
sessionId?: string;
|
|
17
|
-
version?: string;
|
|
18
12
|
dataset?: string;
|
|
19
13
|
env?: LogBindings;
|
|
20
14
|
context?: Record<string, any>;
|
package/build/main/log/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function useLog({ environment: _environment, name, request, body, env, correlati
|
|
|
57
57
|
child: undefined,
|
|
58
58
|
},
|
|
59
59
|
});
|
|
60
|
-
if (logRequest !== false) {
|
|
60
|
+
if (logRequest !== false && request) {
|
|
61
61
|
const { message, ...raw } = typeof logRequest === 'function'
|
|
62
62
|
? logRequest((0, common_1.requestToContext)(request, body))
|
|
63
63
|
: (0, common_1.requestToContext)(request, body);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["log/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["log/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAyBA,wBAqHC;AA9ID,uCAA0C;AAC1C,qCAKkB;AAClB,iCAYgB;AAEhB,2CAAyB;AACz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,EAAE,IAAI;6BACP,KAAK,EAAE;6BACP,IAAI,EAAE;6BACN,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;wBACzB,QAAQ,EAAE,IAAI;wBACd,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,UAAU,EAAE,IAAI,CAAC,UAAU;wBAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;qBACtB;iBACF,CAAC,CAAC;gBAEH,OAAO,IAAI,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,sCAAsC;gBACtC,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE;oBAC1B,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;gBAEH,OAAO,IAAI,QAAQ,CACjB,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EACrE;oBACE,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,MAAM,KAAK,EAAE,KAAK,EAAE,CAAC;QAErB,OAAO,QAAS,CAAC;IACnB,CAAC,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
(0, bun_test_1.test)('log', () => {
|
|
6
|
+
const logs = [];
|
|
7
|
+
const log = (0, _1.useLog)({
|
|
8
|
+
sessionId: '077ed8a6-e464',
|
|
9
|
+
correlationId: 'fc24dc10-5362',
|
|
10
|
+
name: 'test',
|
|
11
|
+
consoleLog(a) {
|
|
12
|
+
logs.push(a);
|
|
13
|
+
},
|
|
14
|
+
context: {
|
|
15
|
+
a: 'b',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
log.info('test', { b: 'c' });
|
|
19
|
+
log.error('test', new Error('test'), { b: 'c' });
|
|
20
|
+
(0, bun_test_1.expect)(logs[0]).toEqual({
|
|
21
|
+
formatted: '[INFO] [test] [077ed8a6-e464/fc24dc10-5362] test',
|
|
22
|
+
level: 'info',
|
|
23
|
+
message: 'test',
|
|
24
|
+
extra: {
|
|
25
|
+
b: 'c',
|
|
26
|
+
},
|
|
27
|
+
error: undefined,
|
|
28
|
+
tags: {
|
|
29
|
+
sessionId: '077ed8a6-e464',
|
|
30
|
+
correlationId: 'fc24dc10-5362',
|
|
31
|
+
environment: 'production',
|
|
32
|
+
workerId: 'test',
|
|
33
|
+
app: 'test',
|
|
34
|
+
version: 'default',
|
|
35
|
+
type: 'worker',
|
|
36
|
+
name: 'test',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
(0, bun_test_1.expect)(logs[1]).toEqual({
|
|
40
|
+
formatted: '[ERROR] [test] [077ed8a6-e464/fc24dc10-5362] test',
|
|
41
|
+
level: 'error',
|
|
42
|
+
message: 'test',
|
|
43
|
+
error: bun_test_1.expect.any(Error),
|
|
44
|
+
extra: {
|
|
45
|
+
b: 'c',
|
|
46
|
+
},
|
|
47
|
+
tags: {
|
|
48
|
+
sessionId: '077ed8a6-e464',
|
|
49
|
+
correlationId: 'fc24dc10-5362',
|
|
50
|
+
environment: 'production',
|
|
51
|
+
workerId: 'test',
|
|
52
|
+
app: 'test',
|
|
53
|
+
version: 'default',
|
|
54
|
+
type: 'worker',
|
|
55
|
+
name: 'test',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
});
|
|
2
59
|
//# sourceMappingURL=index.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","sourceRoot":"src/","sources":["log/index.spec.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.spec.js","sourceRoot":"src/","sources":["log/index.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,wBAA2B;AAE3B,IAAA,eAAI,EAAC,KAAK,EAAE,GAAG,EAAE;IACf,MAAM,IAAI,GAAU,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,IAAA,SAAM,EAAC;QACjB,SAAS,EAAE,eAAe;QAC1B,aAAa,EAAE,eAAe;QAC9B,IAAI,EAAE,MAAM;QACZ,UAAU,CAAC,CAAC;YACV,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACf,CAAC;QACD,OAAO,EAAE;YACP,CAAC,EAAE,GAAG;SACP;KACF,CAAC,CAAC;IACH,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7B,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAEjD,IAAA,iBAAM,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACtB,SAAS,EAAE,kDAAkD;QAC7D,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,MAAM;QACf,KAAK,EAAE;YACL,CAAC,EAAE,GAAG;SACP;QACD,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE;YACJ,SAAS,EAAE,eAAe;YAC1B,aAAa,EAAE,eAAe;YAC9B,WAAW,EAAE,YAAY;YACzB,QAAQ,EAAE,MAAM;YAChB,GAAG,EAAE,MAAM;YACX,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;SACb;KACF,CAAC,CAAC;IACH,IAAA,iBAAM,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACtB,SAAS,EAAE,mDAAmD;QAC9D,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,iBAAM,CAAC,GAAG,CAAC,KAAK,CAAC;QACxB,KAAK,EAAE;YACL,CAAC,EAAE,GAAG;SACP;QACD,IAAI,EAAE;YACJ,SAAS,EAAE,eAAe;YAC1B,aAAa,EAAE,eAAe;YAC9B,WAAW,EAAE,YAAY;YACzB,QAAQ,EAAE,MAAM;YAChB,GAAG,EAAE,MAAM;YACX,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;SACb;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/build/main/log/type.d.ts
CHANGED
|
@@ -18,9 +18,10 @@ export type LogBindings = {
|
|
|
18
18
|
IS_LOCAL_DEV?: string;
|
|
19
19
|
MACHINE_NAME?: string;
|
|
20
20
|
};
|
|
21
|
-
export type LogFn = (message: any,
|
|
21
|
+
export type LogFn = (message: any, extra?: Record<string, any>) => void;
|
|
22
|
+
export type ErrorLogFn = (message: any, error?: Error, extra?: Record<string, any>) => void;
|
|
22
23
|
export type LogFns = {
|
|
23
|
-
error:
|
|
24
|
+
error: ErrorLogFn;
|
|
24
25
|
info: LogFn;
|
|
25
26
|
debug: LogFn;
|
|
26
27
|
warn: LogFn;
|
|
@@ -56,4 +57,23 @@ export type RequestLike = {
|
|
|
56
57
|
url: string;
|
|
57
58
|
json: () => Promise<any>;
|
|
58
59
|
};
|
|
60
|
+
export type LogTags = {
|
|
61
|
+
sessionId: string;
|
|
62
|
+
correlationId: string;
|
|
63
|
+
environment?: 'development' | 'production';
|
|
64
|
+
type?: 'worker' | 'durableObject';
|
|
65
|
+
workerId?: string;
|
|
66
|
+
app?: string;
|
|
67
|
+
version?: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
};
|
|
70
|
+
export type ConsoleLogFn = (arg: {
|
|
71
|
+
formatted: string;
|
|
72
|
+
message: string;
|
|
73
|
+
extra: Record<string, any>;
|
|
74
|
+
tags: LogTags;
|
|
75
|
+
level: LogLevel;
|
|
76
|
+
error?: Error;
|
|
77
|
+
}) => void;
|
|
78
|
+
export type ConsoleLog = boolean | 'color' | ConsoleLogFn;
|
|
59
79
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../../src/index.ts","../../src/log/baselog.ts","../../src/log/color.ts","../../src/log/common.ts","../../src/log/index.spec.ts","../../src/log/index.ts","../../src/log/type.ts","../../src/tracking/index.ts","../../src/tracking/types.ts","../../src/utils/convertkeystosnakecase.ts","../../src/utils/convertvaluestostring.ts","../../src/utils/index.ts","../../src/utils/istest.ts"],"version":"5.6.3"}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import type { BaseLog,
|
|
2
|
-
export type ConsoleLogFn = (arg: {
|
|
3
|
-
formatted: string;
|
|
4
|
-
message: string;
|
|
5
|
-
additionalContext: Record<string, any>;
|
|
6
|
-
level: LogLevel;
|
|
7
|
-
error?: Error;
|
|
8
|
-
}) => void;
|
|
9
|
-
export type ConsoleLog = boolean | 'color' | ConsoleLogFn;
|
|
1
|
+
import type { BaseLog, ConsoleLog } from './type';
|
|
10
2
|
export declare function createBaseLog({ token, orgId, dataset, consoleLog, }: {
|
|
11
3
|
token?: string;
|
|
12
4
|
orgId?: string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Axiom } from '@axiomhq/js';
|
|
2
|
-
import { serializeError } from 'serialize-error';
|
|
3
2
|
import { logger } from './color';
|
|
4
3
|
import { getCorrelationId, requestToContext } from './common';
|
|
5
4
|
let lastMessageTimestamp = undefined;
|
|
@@ -39,15 +38,15 @@ export function createBaseLog({ token, orgId = 'vrplatform-mv6k', dataset, conso
|
|
|
39
38
|
if (arg.request) {
|
|
40
39
|
childContext.request = requestToContext(arg.request);
|
|
41
40
|
}
|
|
42
|
-
const baseLog = (level, message,
|
|
41
|
+
const baseLog = (level, message, extra = {}, error) => {
|
|
43
42
|
const cid = arg.correlationId ||
|
|
44
43
|
correlationId ||
|
|
45
44
|
childContext?.correlationId ||
|
|
46
|
-
|
|
45
|
+
extra?.correlationId ||
|
|
47
46
|
correlationId;
|
|
48
47
|
ingest(level, message, {
|
|
49
48
|
...childContext,
|
|
50
|
-
...
|
|
49
|
+
...extra,
|
|
51
50
|
correlationId: cid,
|
|
52
51
|
sessionId: sid,
|
|
53
52
|
});
|
|
@@ -66,8 +65,18 @@ export function createBaseLog({ token, orgId = 'vrplatform-mv6k', dataset, conso
|
|
|
66
65
|
formatted,
|
|
67
66
|
level,
|
|
68
67
|
message,
|
|
69
|
-
|
|
68
|
+
extra,
|
|
70
69
|
error,
|
|
70
|
+
tags: {
|
|
71
|
+
sessionId: sid,
|
|
72
|
+
correlationId: cid,
|
|
73
|
+
environment,
|
|
74
|
+
workerId,
|
|
75
|
+
app,
|
|
76
|
+
version,
|
|
77
|
+
type,
|
|
78
|
+
name,
|
|
79
|
+
},
|
|
71
80
|
});
|
|
72
81
|
else if (consoleLog === 'color')
|
|
73
82
|
logger
|
|
@@ -87,7 +96,7 @@ export function createBaseLog({ token, orgId = 'vrplatform-mv6k', dataset, conso
|
|
|
87
96
|
.append(message)
|
|
88
97
|
.log();
|
|
89
98
|
else
|
|
90
|
-
console.log(formatted,
|
|
99
|
+
console.log(formatted, extra);
|
|
91
100
|
if (error)
|
|
92
101
|
console.error(error);
|
|
93
102
|
}
|
|
@@ -106,12 +115,13 @@ export function createBaseLog({ token, orgId = 'vrplatform-mv6k', dataset, conso
|
|
|
106
115
|
request,
|
|
107
116
|
context: { ...childContext, ...context },
|
|
108
117
|
}),
|
|
109
|
-
error: (message, error) => {
|
|
118
|
+
error: (message, error, data) => {
|
|
110
119
|
const m = typeof message === 'string'
|
|
111
120
|
? message
|
|
112
121
|
: error?.message || error?.name || 'Error';
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
if (error && error instanceof Error)
|
|
123
|
+
return baseLog('error', m, data, error);
|
|
124
|
+
return baseLog('error', m, error);
|
|
115
125
|
},
|
|
116
126
|
debug: (message, data) => baseLog('debug', message, data),
|
|
117
127
|
warn: (message, data) => baseLog('warn', message, data),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baselog.js","sourceRoot":"src/","sources":["log/baselog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"baselog.js","sourceRoot":"src/","sources":["log/baselog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAS9D,IAAI,oBAAoB,GAAuB,SAAS,CAAC;AAEzD,MAAM,UAAU,aAAa,CAC3B,EACE,KAAK,EACL,KAAK,GAAG,iBAAiB,EACzB,OAAO,EACP,UAAU,GAMX,EACD,EACE,WAAW,EACX,QAAQ,EACR,GAAG,EACH,OAAO,EACP,OAAO,EACP,IAAI,EACJ,aAAa,EACb,SAAS,EACT,gBAAgB,GAajB;IAED,MAAM,UAAU,GAAwB;QACtC,IAAI,EAAE,IAAI,IAAI,QAAQ;QACtB,WAAW,EAAE,WAAW,IAAI,YAAY;QACxC,MAAM,EAAE;YACN,EAAE,EAAE,QAAQ,IAAI,SAAS;YACzB,GAAG,EAAE,GAAG,IAAI,SAAS;YACrB,OAAO,EAAE,OAAO,IAAI,SAAS;YAC7B,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SAClC;QACD,GAAG,OAAO;KACX,CAAC;IAEF,MAAM,KAAK,GAAG,KAAK;QACjB,CAAC,CAAC,IAAI,KAAK,CAAC;YACR,KAAK;YACL,KAAK;YACL,OAAO,CAAC,GAAG;gBACT,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;YAClC,CAAC;SACF,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,KAAK,CAAC,CAAC;gBAC1C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;YACpC,CAAC;YACD,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;YACzD,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;YACvD,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;SACxD,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,aAAa,EAAoB,CAAC;IAClD,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE;QACnB,IAAI,gBAAgB,IAAI,KAAK,EAAE,CAAC;YAC9B,gBAAgB,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAC5C,CAAC;aAAM,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import { type ConsoleLog } from './baselog';
|
|
2
1
|
import { requestToContext } from './common';
|
|
3
|
-
import { type LogBindings, type RequestLike, type WorkerLog } from './type';
|
|
2
|
+
import { type ConsoleLog, type LogBindings, type LogTags, type RequestLike, type WorkerLog } from './type';
|
|
4
3
|
export * from './common';
|
|
5
4
|
export * from './baselog';
|
|
6
5
|
export * from './type';
|
|
7
|
-
export declare function useLog({ environment: _environment, name, request, body, env, correlationId: cid, sessionId: sid, version, executionContext, logRequest, consoleLog: _consoleLog, dataset: _dataset, context: initialContext, }: {
|
|
8
|
-
environment?: string;
|
|
9
|
-
name: string;
|
|
6
|
+
export declare function useLog({ environment: _environment, name, request, body, env, correlationId: cid, sessionId: sid, version, executionContext, logRequest, consoleLog: _consoleLog, dataset: _dataset, context: initialContext, }: Partial<LogTags> & {
|
|
10
7
|
request?: RequestLike & {
|
|
11
8
|
cf?: any;
|
|
12
9
|
};
|
|
13
10
|
logRequest?: boolean | ((raw: ReturnType<typeof requestToContext>) => any);
|
|
14
11
|
body?: any;
|
|
15
|
-
correlationId?: string;
|
|
16
|
-
sessionId?: string;
|
|
17
|
-
version?: string;
|
|
18
12
|
dataset?: string;
|
|
19
13
|
env?: LogBindings;
|
|
20
14
|
context?: Record<string, any>;
|
|
@@ -40,7 +40,7 @@ export function useLog({ environment: _environment, name, request, body, env, co
|
|
|
40
40
|
child: undefined,
|
|
41
41
|
},
|
|
42
42
|
});
|
|
43
|
-
if (logRequest !== false) {
|
|
43
|
+
if (logRequest !== false && request) {
|
|
44
44
|
const { message, ...raw } = typeof logRequest === 'function'
|
|
45
45
|
? logRequest(requestToContext(request, body))
|
|
46
46
|
: requestToContext(request, body);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["log/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["log/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAEhB,OAAO,EAIP,iBAAiB,EACjB,kBAAkB,GAEnB,MAAM,QAAQ,CAAC;AAEhB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AAEvB,MAAM,UAAU,MAAM,CAAC,EACrB,WAAW,EAAE,YAAY,EACzB,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,GAAG,EACH,a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AU,EAAE,IAAI,CAAC,UAAU;wBAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;qBACtB;iBACF,CAAC,CAAC;gBAEH,OAAO,IAAI,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,sCAAsC;gBACtC,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE;oBAC1B,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;gBAEH,OAAO,IAAI,QAAQ,CACjB,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EACrE;oBACE,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,MAAM,KAAK,EAAE,KAAK,EAAE,CAAC;QAErB,OAAO,QAAS,CAAC;IACnB,CAAC,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
import { expect, test } from 'bun:test';
|
|
2
|
+
import { useLog } from '.';
|
|
3
|
+
test('log', () => {
|
|
4
|
+
const logs = [];
|
|
5
|
+
const log = useLog({
|
|
6
|
+
sessionId: '077ed8a6-e464',
|
|
7
|
+
correlationId: 'fc24dc10-5362',
|
|
8
|
+
name: 'test',
|
|
9
|
+
consoleLog(a) {
|
|
10
|
+
logs.push(a);
|
|
11
|
+
},
|
|
12
|
+
context: {
|
|
13
|
+
a: 'b',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
log.info('test', { b: 'c' });
|
|
17
|
+
log.error('test', new Error('test'), { b: 'c' });
|
|
18
|
+
expect(logs[0]).toEqual({
|
|
19
|
+
formatted: '[INFO] [test] [077ed8a6-e464/fc24dc10-5362] test',
|
|
20
|
+
level: 'info',
|
|
21
|
+
message: 'test',
|
|
22
|
+
extra: {
|
|
23
|
+
b: 'c',
|
|
24
|
+
},
|
|
25
|
+
error: undefined,
|
|
26
|
+
tags: {
|
|
27
|
+
sessionId: '077ed8a6-e464',
|
|
28
|
+
correlationId: 'fc24dc10-5362',
|
|
29
|
+
environment: 'production',
|
|
30
|
+
workerId: 'test',
|
|
31
|
+
app: 'test',
|
|
32
|
+
version: 'default',
|
|
33
|
+
type: 'worker',
|
|
34
|
+
name: 'test',
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
expect(logs[1]).toEqual({
|
|
38
|
+
formatted: '[ERROR] [test] [077ed8a6-e464/fc24dc10-5362] test',
|
|
39
|
+
level: 'error',
|
|
40
|
+
message: 'test',
|
|
41
|
+
error: expect.any(Error),
|
|
42
|
+
extra: {
|
|
43
|
+
b: 'c',
|
|
44
|
+
},
|
|
45
|
+
tags: {
|
|
46
|
+
sessionId: '077ed8a6-e464',
|
|
47
|
+
correlationId: 'fc24dc10-5362',
|
|
48
|
+
environment: 'production',
|
|
49
|
+
workerId: 'test',
|
|
50
|
+
app: 'test',
|
|
51
|
+
version: 'default',
|
|
52
|
+
type: 'worker',
|
|
53
|
+
name: 'test',
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
2
57
|
//# sourceMappingURL=index.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","sourceRoot":"src/","sources":["log/index.spec.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.spec.js","sourceRoot":"src/","sources":["log/index.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAE3B,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;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AE,eAAe;YAC9B,WAAW,EAAE,YAAY;YACzB,QAAQ,EAAE,MAAM;YAChB,GAAG,EAAE,MAAM;YACX,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;SACb;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -18,9 +18,10 @@ export type LogBindings = {
|
|
|
18
18
|
IS_LOCAL_DEV?: string;
|
|
19
19
|
MACHINE_NAME?: string;
|
|
20
20
|
};
|
|
21
|
-
export type LogFn = (message: any,
|
|
21
|
+
export type LogFn = (message: any, extra?: Record<string, any>) => void;
|
|
22
|
+
export type ErrorLogFn = (message: any, error?: Error, extra?: Record<string, any>) => void;
|
|
22
23
|
export type LogFns = {
|
|
23
|
-
error:
|
|
24
|
+
error: ErrorLogFn;
|
|
24
25
|
info: LogFn;
|
|
25
26
|
debug: LogFn;
|
|
26
27
|
warn: LogFn;
|
|
@@ -56,4 +57,23 @@ export type RequestLike = {
|
|
|
56
57
|
url: string;
|
|
57
58
|
json: () => Promise<any>;
|
|
58
59
|
};
|
|
60
|
+
export type LogTags = {
|
|
61
|
+
sessionId: string;
|
|
62
|
+
correlationId: string;
|
|
63
|
+
environment?: 'development' | 'production';
|
|
64
|
+
type?: 'worker' | 'durableObject';
|
|
65
|
+
workerId?: string;
|
|
66
|
+
app?: string;
|
|
67
|
+
version?: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
};
|
|
70
|
+
export type ConsoleLogFn = (arg: {
|
|
71
|
+
formatted: string;
|
|
72
|
+
message: string;
|
|
73
|
+
extra: Record<string, any>;
|
|
74
|
+
tags: LogTags;
|
|
75
|
+
level: LogLevel;
|
|
76
|
+
error?: Error;
|
|
77
|
+
}) => void;
|
|
78
|
+
export type ConsoleLog = boolean | 'color' | ConsoleLogFn;
|
|
59
79
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../../src/index.ts","../../src/log/baselog.ts","../../src/log/color.ts","../../src/log/common.ts","../../src/log/index.spec.ts","../../src/log/index.ts","../../src/log/type.ts","../../src/tracking/index.ts","../../src/tracking/types.ts","../../src/utils/convertkeystosnakecase.ts","../../src/utils/convertvaluestostring.ts","../../src/utils/index.ts","../../src/utils/istest.ts"],"version":"5.6.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vrplatform/log",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.47",
|
|
4
4
|
"main": "build/main/index.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,22 +17,20 @@
|
|
|
17
17
|
"LICENSE"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@axiomhq/js": "1.
|
|
21
|
-
"@finalytic/graphql": "1.
|
|
22
|
-
"intercom-client": "6.0.0-beta.3",
|
|
20
|
+
"@axiomhq/js": "1.2.0",
|
|
21
|
+
"@finalytic/graphql": "1.13.44",
|
|
23
22
|
"serialize-error": "11.0.3"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"husky": "^9.0.11",
|
|
30
|
-
"typescript": "5.5.3"
|
|
25
|
+
"@types/bun": "^1.1.13",
|
|
26
|
+
"@biomejs/biome": "^1.9.4",
|
|
27
|
+
"typescript": "5.6.3"
|
|
31
28
|
},
|
|
32
29
|
"trustedDependencies": [
|
|
33
30
|
"@biomejs/biome"
|
|
34
31
|
],
|
|
35
32
|
"scripts": {
|
|
33
|
+
"up": "bunx npm-check-updates --dep prod,dev,optional,overrides --interactive --format group",
|
|
36
34
|
"pub": "bun run build && pnpm version patch --no-commit-hooks --no-git-tag-version && pnpm publish --no-git-checks",
|
|
37
35
|
"pub:alpha": "bun run build && pnpm version prerelease --no-commit-hooks --no-git-tag-version && pnpm publish --no-git-checks --tag alpha",
|
|
38
36
|
"build": "bun build:main & bun build:module",
|
|
@@ -40,8 +38,7 @@
|
|
|
40
38
|
"build:module": "tsc -b tsconfig.esm.json",
|
|
41
39
|
"typecheck": "tsc --noEmit",
|
|
42
40
|
"lint": "biome check .",
|
|
43
|
-
"lint:fix": "biome check --
|
|
44
|
-
"pre-commit": "echo precommit",
|
|
41
|
+
"lint:fix": "biome check --write --unsafe --skip-errors .",
|
|
45
42
|
"pre-push": "bun typecheck && bun lint",
|
|
46
43
|
"post-merge": "bun i"
|
|
47
44
|
},
|
package/src/log/baselog.ts
CHANGED
|
@@ -2,19 +2,16 @@ import { Axiom } from '@axiomhq/js';
|
|
|
2
2
|
import { serializeError } from 'serialize-error';
|
|
3
3
|
import { logger } from './color';
|
|
4
4
|
import { getCorrelationId, requestToContext } from './common';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
BaseLog,
|
|
7
|
+
ChildLogOptions,
|
|
8
|
+
ConsoleLog,
|
|
9
|
+
Log,
|
|
10
|
+
LogLevel,
|
|
11
|
+
} from './type';
|
|
6
12
|
|
|
7
13
|
let lastMessageTimestamp: number | undefined = undefined;
|
|
8
14
|
|
|
9
|
-
export type ConsoleLogFn = (arg: {
|
|
10
|
-
formatted: string;
|
|
11
|
-
message: string;
|
|
12
|
-
additionalContext: Record<string, any>;
|
|
13
|
-
level: LogLevel;
|
|
14
|
-
error?: Error;
|
|
15
|
-
}) => void;
|
|
16
|
-
export type ConsoleLog = boolean | 'color' | ConsoleLogFn;
|
|
17
|
-
|
|
18
15
|
export function createBaseLog(
|
|
19
16
|
{
|
|
20
17
|
token,
|
|
@@ -97,18 +94,18 @@ export function createBaseLog(
|
|
|
97
94
|
const baseLog = (
|
|
98
95
|
level: LogLevel,
|
|
99
96
|
message: any,
|
|
100
|
-
|
|
97
|
+
extra: Record<string, any> = {},
|
|
101
98
|
error?: Error
|
|
102
99
|
) => {
|
|
103
100
|
const cid =
|
|
104
101
|
arg.correlationId ||
|
|
105
102
|
correlationId ||
|
|
106
103
|
childContext?.correlationId ||
|
|
107
|
-
|
|
104
|
+
extra?.correlationId ||
|
|
108
105
|
correlationId;
|
|
109
106
|
ingest(level, message, {
|
|
110
107
|
...childContext,
|
|
111
|
-
...
|
|
108
|
+
...extra,
|
|
112
109
|
correlationId: cid,
|
|
113
110
|
sessionId: sid,
|
|
114
111
|
});
|
|
@@ -131,8 +128,18 @@ export function createBaseLog(
|
|
|
131
128
|
formatted,
|
|
132
129
|
level,
|
|
133
130
|
message,
|
|
134
|
-
|
|
131
|
+
extra,
|
|
135
132
|
error,
|
|
133
|
+
tags: {
|
|
134
|
+
sessionId: sid,
|
|
135
|
+
correlationId: cid,
|
|
136
|
+
environment,
|
|
137
|
+
workerId,
|
|
138
|
+
app,
|
|
139
|
+
version,
|
|
140
|
+
type,
|
|
141
|
+
name,
|
|
142
|
+
},
|
|
136
143
|
});
|
|
137
144
|
else if (consoleLog === 'color')
|
|
138
145
|
logger
|
|
@@ -151,7 +158,7 @@ export function createBaseLog(
|
|
|
151
158
|
.reset()
|
|
152
159
|
.append(message)
|
|
153
160
|
.log();
|
|
154
|
-
else console.log(formatted,
|
|
161
|
+
else console.log(formatted, extra);
|
|
155
162
|
|
|
156
163
|
if (error) console.error(error);
|
|
157
164
|
}
|
|
@@ -177,18 +184,14 @@ export function createBaseLog(
|
|
|
177
184
|
request,
|
|
178
185
|
context: { ...childContext, ...context },
|
|
179
186
|
}),
|
|
180
|
-
error: (message, error) => {
|
|
187
|
+
error: (message, error, data) => {
|
|
181
188
|
const m =
|
|
182
189
|
typeof message === 'string'
|
|
183
190
|
? message
|
|
184
191
|
: error?.message || error?.name || 'Error';
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
m,
|
|
189
|
-
e instanceof Error ? serializeError(e) : e,
|
|
190
|
-
e
|
|
191
|
-
);
|
|
192
|
+
if (error && error instanceof Error)
|
|
193
|
+
return baseLog('error', m, data, error);
|
|
194
|
+
return baseLog('error', m, error);
|
|
192
195
|
},
|
|
193
196
|
debug: (message, data) => baseLog('debug', message, data),
|
|
194
197
|
warn: (message, data) => baseLog('warn', message, data),
|
package/src/log/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createBaseLog } from './baselog';
|
|
2
2
|
import {
|
|
3
3
|
getCorrelationId,
|
|
4
4
|
getEnvironment,
|
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
AXIOM_AUTH_TOKEN_ENV,
|
|
10
10
|
AXIOM_DATASET_ENV,
|
|
11
11
|
AXIOM_ORG_ID_ENV,
|
|
12
|
+
type ConsoleLog,
|
|
12
13
|
LOG_ENV,
|
|
13
14
|
type LogBindings,
|
|
15
|
+
type LogTags,
|
|
14
16
|
type RequestLike,
|
|
15
17
|
TASK_QUEUE_HEADER,
|
|
16
18
|
WORKFLOW_ID_HEADER,
|
|
@@ -35,15 +37,10 @@ export function useLog({
|
|
|
35
37
|
consoleLog: _consoleLog,
|
|
36
38
|
dataset: _dataset,
|
|
37
39
|
context: initialContext = {},
|
|
38
|
-
}: {
|
|
39
|
-
environment?: string;
|
|
40
|
-
name: string;
|
|
40
|
+
}: Partial<LogTags> & {
|
|
41
41
|
request?: RequestLike & { cf?: any };
|
|
42
42
|
logRequest?: boolean | ((raw: ReturnType<typeof requestToContext>) => any);
|
|
43
43
|
body?: any;
|
|
44
|
-
correlationId?: string;
|
|
45
|
-
sessionId?: string;
|
|
46
|
-
version?: string;
|
|
47
44
|
dataset?: string;
|
|
48
45
|
env?: LogBindings;
|
|
49
46
|
context?: Record<string, any>;
|
|
@@ -94,7 +91,7 @@ export function useLog({
|
|
|
94
91
|
}
|
|
95
92
|
) as WorkerLog;
|
|
96
93
|
|
|
97
|
-
if (logRequest !== false) {
|
|
94
|
+
if (logRequest !== false && request) {
|
|
98
95
|
const { message, ...raw } =
|
|
99
96
|
typeof logRequest === 'function'
|
|
100
97
|
? logRequest(requestToContext(request, body))
|
package/src/log/type.ts
CHANGED
|
@@ -24,13 +24,15 @@ export type LogBindings = {
|
|
|
24
24
|
MACHINE_NAME?: string;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export type LogFn = (
|
|
27
|
+
export type LogFn = (message: any, extra?: Record<string, any>) => void;
|
|
28
|
+
export type ErrorLogFn = (
|
|
28
29
|
message: any,
|
|
29
|
-
|
|
30
|
+
error?: Error,
|
|
31
|
+
extra?: Record<string, any>
|
|
30
32
|
) => void;
|
|
31
33
|
|
|
32
34
|
export type LogFns = {
|
|
33
|
-
error:
|
|
35
|
+
error: ErrorLogFn;
|
|
34
36
|
info: LogFn;
|
|
35
37
|
debug: LogFn;
|
|
36
38
|
warn: LogFn;
|
|
@@ -74,3 +76,23 @@ export type RequestLike = {
|
|
|
74
76
|
url: string;
|
|
75
77
|
json: () => Promise<any>;
|
|
76
78
|
};
|
|
79
|
+
|
|
80
|
+
export type LogTags = {
|
|
81
|
+
sessionId: string;
|
|
82
|
+
correlationId: string;
|
|
83
|
+
environment?: 'development' | 'production';
|
|
84
|
+
type?: 'worker' | 'durableObject';
|
|
85
|
+
workerId?: string;
|
|
86
|
+
app?: string;
|
|
87
|
+
version?: string;
|
|
88
|
+
name?: string;
|
|
89
|
+
};
|
|
90
|
+
export type ConsoleLogFn = (arg: {
|
|
91
|
+
formatted: string;
|
|
92
|
+
message: string;
|
|
93
|
+
extra: Record<string, any>;
|
|
94
|
+
tags: LogTags;
|
|
95
|
+
level: LogLevel;
|
|
96
|
+
error?: Error;
|
|
97
|
+
}) => void;
|
|
98
|
+
export type ConsoleLog = boolean | 'color' | ConsoleLogFn;
|