@dxos/log 0.8.4-main.84f28bd → 0.8.4-main.ae835ea
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 +16 -11
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +22 -15
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/config.d.ts +2 -3
- package/dist/types/src/config.d.ts.map +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/decorators.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/platform/node/index.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/src/processors/file-processor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/config.ts +2 -2
- package/src/context.ts +2 -3
- package/src/decorators.ts +2 -1
- package/src/experimental/classes.test.ts +2 -1
- package/src/index.ts +1 -1
- package/src/log.test.ts +15 -9
- package/src/log.ts +3 -4
- package/src/options.ts +1 -1
- package/src/platform/node/index.ts +2 -1
- package/src/processors/browser-processor.ts +6 -2
- package/src/processors/console-processor.ts +11 -7
- package/src/processors/file-processor.ts +2 -1
- package/src/scope.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/log",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.ae835ea",
|
|
4
4
|
"description": "Logger",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"types": "./dist/types/src/index.d.ts",
|
|
13
14
|
"browser": "./dist/lib/browser/index.mjs",
|
|
14
15
|
"node": {
|
|
15
16
|
"require": "./dist/lib/node/index.cjs",
|
|
16
17
|
"default": "./dist/lib/node-esm/index.mjs"
|
|
17
|
-
}
|
|
18
|
-
"types": "./dist/types/src/index.d.ts"
|
|
18
|
+
}
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"browser": {
|
|
@@ -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.4-main.
|
|
39
|
-
"@dxos/util": "0.8.4-main.
|
|
38
|
+
"@dxos/node-std": "0.8.4-main.ae835ea",
|
|
39
|
+
"@dxos/util": "0.8.4-main.ae835ea"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/js-yaml": "^4.0.5",
|
package/src/config.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { type LogProcessor } from './context';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Standard levels.
|
|
9
|
+
* NOTE: Keep aligned with LogLevel in @dxos/protocols.
|
|
9
10
|
*/
|
|
10
|
-
// NOTE: Keep aligned with LogLevel in @dxos/protocols.
|
|
11
11
|
// TODO(burdon): Update numbers?
|
|
12
12
|
export enum LogLevel {
|
|
13
13
|
TRACE = 5,
|
|
@@ -18,7 +18,7 @@ export enum LogLevel {
|
|
|
18
18
|
ERROR = 14,
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const levels:
|
|
21
|
+
export const levels: Record<string, LogLevel> = {
|
|
22
22
|
trace: LogLevel.TRACE,
|
|
23
23
|
debug: LogLevel.DEBUG,
|
|
24
24
|
verbose: LogLevel.VERBOSE,
|
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/decorators.ts
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import { debugInfo, ownershipClass } from './ownership';
|
|
8
7
|
import { log } from '../log';
|
|
9
8
|
|
|
9
|
+
import { debugInfo, ownershipClass } from './ownership';
|
|
10
|
+
|
|
10
11
|
describe('classes', function () {
|
|
11
12
|
test('field instance', function () {
|
|
12
13
|
@ownershipClass
|
package/src/index.ts
CHANGED
package/src/log.test.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
|
|
6
7
|
import { describe, test } from 'vitest';
|
|
7
8
|
|
|
8
9
|
import { LogLevel } from './config';
|
|
@@ -28,10 +29,10 @@ log.config({
|
|
|
28
29
|
filter: LogLevel.DEBUG,
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
/* eslint-disable
|
|
32
|
+
/* eslint-disable prefer-arrow-functions/prefer-arrow-functions */
|
|
32
33
|
|
|
33
|
-
describe('log',
|
|
34
|
-
test('throws an error',
|
|
34
|
+
describe('log', () => {
|
|
35
|
+
test('throws an error', () => {
|
|
35
36
|
try {
|
|
36
37
|
throw new LogError('Test failed', { value: 1 });
|
|
37
38
|
} catch (err: any) {
|
|
@@ -39,7 +40,7 @@ describe('log', function () {
|
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
42
|
|
|
42
|
-
test('throws an error showing stacktrace',
|
|
43
|
+
test('throws an error showing stacktrace', () => {
|
|
43
44
|
try {
|
|
44
45
|
throw new LogError('Test failed', { value: 2 });
|
|
45
46
|
} catch (err: any) {
|
|
@@ -47,7 +48,7 @@ describe('log', function () {
|
|
|
47
48
|
}
|
|
48
49
|
});
|
|
49
50
|
|
|
50
|
-
test('catches an error',
|
|
51
|
+
test('catches an error', () => {
|
|
51
52
|
try {
|
|
52
53
|
throw new LogError('ERROR ON LINE 21', { value: 3 });
|
|
53
54
|
} catch (err: any) {
|
|
@@ -55,7 +56,7 @@ describe('log', function () {
|
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
58
|
|
|
58
|
-
test('config',
|
|
59
|
+
test('config', () => {
|
|
59
60
|
log.config({
|
|
60
61
|
filter: LogLevel.INFO,
|
|
61
62
|
});
|
|
@@ -65,7 +66,7 @@ describe('log', function () {
|
|
|
65
66
|
log.warn('Warn level log message');
|
|
66
67
|
});
|
|
67
68
|
|
|
68
|
-
test('config file',
|
|
69
|
+
test('config file', () => {
|
|
69
70
|
log.config({
|
|
70
71
|
file: path.join('packages/common/log/test-config.yml'),
|
|
71
72
|
});
|
|
@@ -75,7 +76,7 @@ describe('log', function () {
|
|
|
75
76
|
log.warn('Warn level log message');
|
|
76
77
|
});
|
|
77
78
|
|
|
78
|
-
test('levels',
|
|
79
|
+
test('levels', () => {
|
|
79
80
|
log('Default level log message');
|
|
80
81
|
log.debug('Debug level log message');
|
|
81
82
|
log.info('Info level log message');
|
|
@@ -83,10 +84,15 @@ describe('log', function () {
|
|
|
83
84
|
log.error('Error level log message');
|
|
84
85
|
});
|
|
85
86
|
|
|
86
|
-
test('context',
|
|
87
|
+
test('context', () => {
|
|
87
88
|
log.info('Message with context', {
|
|
88
89
|
title: 'test',
|
|
89
90
|
context: 123,
|
|
90
91
|
});
|
|
91
92
|
});
|
|
93
|
+
|
|
94
|
+
test('error', function () {
|
|
95
|
+
const myError = new Error('Test error', { cause: new Error('Cause') });
|
|
96
|
+
log.catch(myError);
|
|
97
|
+
});
|
|
92
98
|
});
|
package/src/log.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type LogConfig, LogLevel, type LogOptions } from './config';
|
|
|
6
6
|
import { type LogContext, type LogProcessor } from './context';
|
|
7
7
|
import { createFunctionLogDecorator, createMethodLogDecorator } from './decorators';
|
|
8
8
|
import { type CallMetadata } from './meta';
|
|
9
|
-
import {
|
|
9
|
+
import { DEFAULT_PROCESSORS, getConfig } from './options';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Logging function.
|
|
@@ -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,
|
package/src/options.ts
CHANGED
|
@@ -7,7 +7,7 @@ import defaultsDeep from 'lodash.defaultsdeep';
|
|
|
7
7
|
import { type LogConfig, type LogFilter, LogLevel, type LogOptions, LogProcessorType, levels } from './config';
|
|
8
8
|
import { type LogProcessor } from './context';
|
|
9
9
|
import { loadOptions } from './platform';
|
|
10
|
-
import { CONSOLE_PROCESSOR, DEBUG_PROCESSOR
|
|
10
|
+
import { BROWSER_PROCESSOR, CONSOLE_PROCESSOR, DEBUG_PROCESSOR } from './processors';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Processor variants.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { getDebugName, safariCheck } from '@dxos/util';
|
|
6
6
|
|
|
7
7
|
import { LogLevel } from '../config';
|
|
8
|
-
import {
|
|
8
|
+
import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
|
|
9
9
|
|
|
10
10
|
const getRelativeFilename = (filename: string) => {
|
|
11
11
|
// TODO(burdon): Hack uses "packages" as an anchor (pre-parse NX?)
|
|
@@ -66,12 +66,16 @@ 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) {
|
|
73
75
|
if (Object.keys(context).length === 1 && 'error' in context) {
|
|
74
76
|
args.push(context.error);
|
|
77
|
+
} else if (Object.keys(context).length === 1 && 'err' in context) {
|
|
78
|
+
args.push(context.err);
|
|
75
79
|
} else {
|
|
76
80
|
args.push(context);
|
|
77
81
|
}
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import chalk from 'chalk';
|
|
6
5
|
import { inspect } from 'node:util';
|
|
7
6
|
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
|
|
8
9
|
import { getPrototypeSpecificInstanceId, pickBy } from '@dxos/util';
|
|
9
10
|
|
|
10
|
-
import { getRelativeFilename } from './common';
|
|
11
11
|
import { type LogConfig, LogLevel, shortLevelName } from '../config';
|
|
12
|
-
import {
|
|
12
|
+
import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
|
|
13
|
+
|
|
14
|
+
import { getRelativeFilename } from './common';
|
|
13
15
|
|
|
14
16
|
const LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {
|
|
15
17
|
[LogLevel.TRACE]: 'gray',
|
|
@@ -21,7 +23,7 @@ const LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {
|
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
export const truncate = (text?: string, length = 0, right = false) => {
|
|
24
|
-
const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : text ?? '';
|
|
26
|
+
const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : (text ?? '');
|
|
25
27
|
return right ? str.padStart(length, ' ') : str.padEnd(length, ' ');
|
|
26
28
|
};
|
|
27
29
|
|
|
@@ -32,7 +34,7 @@ export type FormatParts = {
|
|
|
32
34
|
line?: number;
|
|
33
35
|
timestamp?: string;
|
|
34
36
|
level: LogLevel;
|
|
35
|
-
message
|
|
37
|
+
message?: string;
|
|
36
38
|
context?: any;
|
|
37
39
|
error?: Error;
|
|
38
40
|
scope?: any;
|
|
@@ -50,8 +52,10 @@ export const DEFAULT_FORMATTER: Formatter = (
|
|
|
50
52
|
let instance;
|
|
51
53
|
if (scope) {
|
|
52
54
|
const prototype = Object.getPrototypeOf(scope);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
if (prototype !== null) {
|
|
56
|
+
const id = getPrototypeSpecificInstanceId(scope);
|
|
57
|
+
instance = chalk.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
58
|
+
}
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
const formattedTimestamp = config.options?.formatter?.timestamp ? new Date().toISOString() : undefined;
|
|
@@ -7,10 +7,11 @@ import { dirname } from 'node:path';
|
|
|
7
7
|
|
|
8
8
|
import { jsonlogify } from '@dxos/util';
|
|
9
9
|
|
|
10
|
-
import { getRelativeFilename } from './common';
|
|
11
10
|
import { type LogFilter, LogLevel } from '../config';
|
|
12
11
|
import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
|
|
13
12
|
|
|
13
|
+
import { getRelativeFilename } from './common';
|
|
14
|
+
|
|
14
15
|
// Amount of time to retry writing after encountering EAGAIN before giving up.
|
|
15
16
|
const EAGAIN_MAX_DURATION = 1000;
|
|
16
17
|
/**
|
package/src/scope.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const gatherLogInfoFromScope = (scope: any): Record<string, any> => {
|
|
|
33
33
|
const res: Record<string, any> = {};
|
|
34
34
|
|
|
35
35
|
const prototype = Object.getPrototypeOf(scope);
|
|
36
|
-
const infoProps = prototype[logInfoProperties] ?? [];
|
|
36
|
+
const infoProps = (typeof prototype === 'object' && prototype !== null ? prototype[logInfoProperties] : []) ?? [];
|
|
37
37
|
for (const prop of infoProps) {
|
|
38
38
|
try {
|
|
39
39
|
res[prop] = typeof scope[prop] === 'function' ? scope[prop]() : scope[prop];
|