@dxos/log 0.8.3 → 0.8.4-main.3f58842
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/lib/browser/index.mjs +21 -21
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +21 -21
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/context.d.ts +1 -1
- package/dist/types/src/context.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/processors/browser-processor.d.ts.map +1 -1
- package/dist/types/src/processors/console-processor.d.ts +1 -1
- package/dist/types/src/processors/console-processor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/context.ts +2 -3
- package/src/index.ts +1 -1
- package/src/log.test.ts +14 -9
- package/src/log.ts +2 -3
- package/src/processors/browser-processor.ts +3 -1
- package/src/processors/console-processor.ts +2 -2
- package/dist/lib/node/index.cjs +0 -695
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/log",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.3f58842",
|
|
4
4
|
"description": "Logger",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"js-yaml": "^4.1.0",
|
|
36
36
|
"lodash.defaultsdeep": "^4.6.1",
|
|
37
37
|
"lodash.omit": "^4.5.0",
|
|
38
|
-
"@dxos/node-std": "0.8.
|
|
39
|
-
"@dxos/util": "0.8.
|
|
38
|
+
"@dxos/node-std": "0.8.4-main.3f58842",
|
|
39
|
+
"@dxos/util": "0.8.4-main.3f58842"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/js-yaml": "^4.0.5",
|
package/src/context.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type LogContext = Record<string, any> | Error | any;
|
|
|
16
16
|
*/
|
|
17
17
|
export interface LogEntry {
|
|
18
18
|
level: LogLevel;
|
|
19
|
-
message
|
|
19
|
+
message?: string;
|
|
20
20
|
context?: LogContext;
|
|
21
21
|
meta?: CallMetadata;
|
|
22
22
|
error?: Error;
|
|
@@ -64,8 +64,7 @@ export const getContextFromEntry = (entry: LogEntry): Record<string, any> | unde
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
if (entry.error) {
|
|
67
|
-
|
|
68
|
-
context = Object.assign(context ?? {}, { error: entry.error, ...errorContext });
|
|
67
|
+
context = Object.assign(context ?? {}, { error: entry.error });
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
return context && Object.keys(context).length > 0 ? context : undefined;
|
package/src/index.ts
CHANGED
package/src/log.test.ts
CHANGED
|
@@ -28,10 +28,10 @@ log.config({
|
|
|
28
28
|
filter: LogLevel.DEBUG,
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
/* eslint-disable
|
|
31
|
+
/* eslint-disable prefer-arrow-functions/prefer-arrow-functions */
|
|
32
32
|
|
|
33
|
-
describe('log',
|
|
34
|
-
test('throws an error',
|
|
33
|
+
describe('log', () => {
|
|
34
|
+
test('throws an error', () => {
|
|
35
35
|
try {
|
|
36
36
|
throw new LogError('Test failed', { value: 1 });
|
|
37
37
|
} catch (err: any) {
|
|
@@ -39,7 +39,7 @@ describe('log', function () {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
test('throws an error showing stacktrace',
|
|
42
|
+
test('throws an error showing stacktrace', () => {
|
|
43
43
|
try {
|
|
44
44
|
throw new LogError('Test failed', { value: 2 });
|
|
45
45
|
} catch (err: any) {
|
|
@@ -47,7 +47,7 @@ describe('log', function () {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
test('catches an error',
|
|
50
|
+
test('catches an error', () => {
|
|
51
51
|
try {
|
|
52
52
|
throw new LogError('ERROR ON LINE 21', { value: 3 });
|
|
53
53
|
} catch (err: any) {
|
|
@@ -55,7 +55,7 @@ describe('log', function () {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
test('config',
|
|
58
|
+
test('config', () => {
|
|
59
59
|
log.config({
|
|
60
60
|
filter: LogLevel.INFO,
|
|
61
61
|
});
|
|
@@ -65,7 +65,7 @@ describe('log', function () {
|
|
|
65
65
|
log.warn('Warn level log message');
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
test('config file',
|
|
68
|
+
test('config file', () => {
|
|
69
69
|
log.config({
|
|
70
70
|
file: path.join('packages/common/log/test-config.yml'),
|
|
71
71
|
});
|
|
@@ -75,7 +75,7 @@ describe('log', function () {
|
|
|
75
75
|
log.warn('Warn level log message');
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
test('levels',
|
|
78
|
+
test('levels', () => {
|
|
79
79
|
log('Default level log message');
|
|
80
80
|
log.debug('Debug level log message');
|
|
81
81
|
log.info('Info level log message');
|
|
@@ -83,10 +83,15 @@ describe('log', function () {
|
|
|
83
83
|
log.error('Error level log message');
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
test('context',
|
|
86
|
+
test('context', () => {
|
|
87
87
|
log.info('Message with context', {
|
|
88
88
|
title: 'test',
|
|
89
89
|
context: 123,
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
|
+
|
|
93
|
+
test('error', function () {
|
|
94
|
+
const myError = new Error('Test error', { cause: new Error('Cause') });
|
|
95
|
+
log.catch(myError);
|
|
96
|
+
});
|
|
92
97
|
});
|
package/src/log.ts
CHANGED
|
@@ -78,8 +78,7 @@ const createLog = (): LogImp => {
|
|
|
78
78
|
log.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
79
79
|
|
|
80
80
|
// Catch only shows error message, not stacktrace.
|
|
81
|
-
log.catch = (error: Error | any, context, meta) =>
|
|
82
|
-
processLog(LogLevel.ERROR, error?.message ?? String(error), context, meta, error);
|
|
81
|
+
log.catch = (error: Error | any, context, meta) => processLog(LogLevel.ERROR, undefined, context, meta, error);
|
|
83
82
|
|
|
84
83
|
// Show break.
|
|
85
84
|
log.break = () => log.info('——————————————————————————————————————————————————');
|
|
@@ -95,7 +94,7 @@ const createLog = (): LogImp => {
|
|
|
95
94
|
*/
|
|
96
95
|
const processLog = (
|
|
97
96
|
level: LogLevel,
|
|
98
|
-
message: string,
|
|
97
|
+
message: string | undefined,
|
|
99
98
|
context: LogContext = {},
|
|
100
99
|
meta?: CallMetadata,
|
|
101
100
|
error?: Error,
|
|
@@ -66,7 +66,9 @@ const APP_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {
|
|
|
66
66
|
args.push(`%c${processPrefix}${scopeName}`, 'color:#C026D3;font-weight:bold');
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
if (entry.message) {
|
|
70
|
+
args.push(entry.message);
|
|
71
|
+
}
|
|
70
72
|
|
|
71
73
|
const context = getContextFromEntry(entry);
|
|
72
74
|
if (context) {
|
|
@@ -21,7 +21,7 @@ const LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export const truncate = (text?: string, length = 0, right = false) => {
|
|
24
|
-
const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : text ?? '';
|
|
24
|
+
const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : (text ?? '');
|
|
25
25
|
return right ? str.padStart(length, ' ') : str.padEnd(length, ' ');
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -32,7 +32,7 @@ export type FormatParts = {
|
|
|
32
32
|
line?: number;
|
|
33
33
|
timestamp?: string;
|
|
34
34
|
level: LogLevel;
|
|
35
|
-
message
|
|
35
|
+
message?: string;
|
|
36
36
|
context?: any;
|
|
37
37
|
error?: Error;
|
|
38
38
|
scope?: any;
|