@dxos/log 0.1.56-main.f3d4052 → 0.1.56-next.71eb10c
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 +37 -73
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +56 -83
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/options.d.ts +1 -1
- package/dist/types/src/options.d.ts.map +1 -1
- package/dist/types/src/processors/console-processor.d.ts +1 -0
- package/dist/types/src/processors/console-processor.d.ts.map +1 -1
- package/package.json +7 -3
- package/src/config.ts +1 -0
- package/src/index.ts +6 -1
- package/src/options.ts +18 -16
- package/src/platform/node/index.ts +1 -1
- package/src/processors/console-processor.ts +22 -2
- package/dist/types/src/invariant.d.ts +0 -12
- package/dist/types/src/invariant.d.ts.map +0 -1
- package/src/invariant.ts +0 -46
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import omit from 'lodash.omit';
|
|
2
|
+
import pick from 'lodash.pick';
|
|
3
|
+
export { omit, pick };
|
|
1
4
|
export * from './config';
|
|
2
5
|
export * from './context';
|
|
3
6
|
export * from './log';
|
|
4
7
|
export { parseFilter } from './options';
|
|
5
8
|
export * from './processors';
|
|
6
9
|
export * from './scope';
|
|
7
|
-
export * from './invariant';
|
|
8
10
|
export * from './meta';
|
|
9
11
|
export { getCurrentOwnershipScope } from './experimental/ownership';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,IAAI,MAAM,aAAa,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAEtB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AAEvB,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -8,5 +8,5 @@ export declare const processors: {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const DEFAULT_PROCESSORS: LogProcessor[];
|
|
10
10
|
export declare const parseFilter: (filter: string | string[] | LogLevel) => LogFilter[];
|
|
11
|
-
export declare const getConfig: (
|
|
11
|
+
export declare const getConfig: (options?: LogOptions) => LogConfig;
|
|
12
12
|
//# sourceMappingURL=options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/options.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAA4B,MAAM,UAAU,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAA;CAIvD,CAAC;AAIF,eAAO,MAAM,kBAAkB,gBAAuD,CAAC;AAEvF,eAAO,MAAM,WAAW,WAAY,MAAM,GAAG,MAAM,EAAE,GAAG,QAAQ,KAAG,SAAS,EAY3E,CAAC;AAEF,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/options.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAA4B,MAAM,UAAU,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAA;CAIvD,CAAC;AAIF,eAAO,MAAM,kBAAkB,gBAAuD,CAAC;AAEvF,eAAO,MAAM,WAAW,WAAY,MAAM,GAAG,MAAM,EAAE,GAAG,QAAQ,KAAG,SAAS,EAY3E,CAAC;AAEF,eAAO,MAAM,SAAS,aAAc,UAAU,KAAG,SAuBhD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console-processor.d.ts","sourceRoot":"","sources":["../../../../src/processors/console-processor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"console-processor.d.ts","sourceRoot":"","sources":["../../../../src/processors/console-processor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,WAAW,CAAC;AAChE,OAAO,EAAuB,YAAY,EAAa,MAAM,YAAY,CAAC;AAU1E,eAAO,MAAM,QAAQ,UAAW,MAAM,6CAGrC,CAAC;AAiBF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;AAE1F,eAAO,MAAM,iBAAiB,EAAE,SAuB/B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,SAI7B,CAAC;AAKF,eAAO,MAAM,iBAAiB,EAAE,YAkC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/log",
|
|
3
|
-
"version": "0.1.56-
|
|
3
|
+
"version": "0.1.56-next.71eb10c",
|
|
4
4
|
"description": "Logger",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -21,15 +21,19 @@
|
|
|
21
21
|
"chalk": "^4.1.0",
|
|
22
22
|
"js-yaml": "^4.1.0",
|
|
23
23
|
"lodash.defaultsdeep": "^4.6.1",
|
|
24
|
+
"lodash.omit": "^4.5.0",
|
|
25
|
+
"lodash.pick": "^4.4.0",
|
|
24
26
|
"lodash.pickby": "^4.6.0",
|
|
25
|
-
"@dxos/node-std": "0.1.56-
|
|
26
|
-
"@dxos/util": "0.1.56-
|
|
27
|
+
"@dxos/node-std": "0.1.56-next.71eb10c",
|
|
28
|
+
"@dxos/util": "0.1.56-next.71eb10c"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
29
31
|
"@swc-node/sourcemap-support": "^0.2.0",
|
|
30
32
|
"@swc/core": "1.3.70",
|
|
31
33
|
"@types/js-yaml": "^4.0.5",
|
|
32
34
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
35
|
+
"@types/lodash.omit": "^4.5.7",
|
|
36
|
+
"@types/lodash.pick": "^4.4.7",
|
|
33
37
|
"@types/lodash.pickby": "^4.6.7",
|
|
34
38
|
"@types/node": "^18.11.9",
|
|
35
39
|
"pirates": "~4.0.5",
|
package/src/config.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// Message helpers.
|
|
6
|
+
import omit from 'lodash.omit';
|
|
7
|
+
import pick from 'lodash.pick';
|
|
8
|
+
|
|
9
|
+
export { omit, pick };
|
|
10
|
+
|
|
5
11
|
export * from './config';
|
|
6
12
|
export * from './context';
|
|
7
13
|
export * from './log';
|
|
8
14
|
export { parseFilter } from './options';
|
|
9
15
|
export * from './processors';
|
|
10
16
|
export * from './scope';
|
|
11
|
-
export * from './invariant';
|
|
12
17
|
export * from './meta';
|
|
13
18
|
|
|
14
19
|
export { getCurrentOwnershipScope } from './experimental/ownership';
|
package/src/options.ts
CHANGED
|
@@ -36,25 +36,27 @@ export const parseFilter = (filter: string | string[] | LogLevel): LogFilter[] =
|
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
export const getConfig = (
|
|
40
|
-
|
|
39
|
+
export const getConfig = (options?: LogOptions): LogConfig => {
|
|
40
|
+
const nodeOptions: LogOptions | undefined =
|
|
41
|
+
'process' in globalThis
|
|
42
|
+
? {
|
|
43
|
+
file: process!.env.LOG_CONFIG,
|
|
44
|
+
filter: process!.env.LOG_FILTER,
|
|
45
|
+
processor: process!.env.LOG_PROCESSOR,
|
|
46
|
+
}
|
|
47
|
+
: undefined;
|
|
48
|
+
|
|
49
|
+
const mergedOptions: LogOptions = defaultsDeep(
|
|
41
50
|
{},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
file: process!.env?.LOG_CONFIG,
|
|
46
|
-
filter: process!.env?.LOG_FILTER,
|
|
47
|
-
processor: process!.env?.LOG_PROCESSOR,
|
|
48
|
-
},
|
|
51
|
+
options,
|
|
52
|
+
nodeOptions && loadOptions(nodeOptions.file),
|
|
53
|
+
nodeOptions,
|
|
49
54
|
);
|
|
50
55
|
|
|
51
|
-
// TODO(burdon): Verbose option.
|
|
52
|
-
// console.log(JSON.stringify(options, undefined, 2));
|
|
53
|
-
options = defaultsDeep({}, loadOptions(options.file), options);
|
|
54
56
|
return {
|
|
55
|
-
options,
|
|
56
|
-
filters: parseFilter(
|
|
57
|
-
processors:
|
|
58
|
-
prefix:
|
|
57
|
+
options: mergedOptions,
|
|
58
|
+
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
59
|
+
processors: mergedOptions.processor ? [processors[mergedOptions.processor]] : DEFAULT_PROCESSORS,
|
|
60
|
+
prefix: mergedOptions.prefix,
|
|
59
61
|
};
|
|
60
62
|
};
|
|
@@ -14,7 +14,7 @@ import { LogOptions } from '../../config';
|
|
|
14
14
|
export const loadOptions = (filepath?: string): LogOptions | undefined => {
|
|
15
15
|
if (filepath) {
|
|
16
16
|
const fullpath = path.join(process.cwd(), filepath);
|
|
17
|
-
console.log(`Log file: ${fullpath}`);
|
|
17
|
+
// console.log(`Log file: ${fullpath}`);
|
|
18
18
|
try {
|
|
19
19
|
const text = fs.readFileSync(fullpath, 'utf-8');
|
|
20
20
|
if (text) {
|
|
@@ -6,6 +6,8 @@ import chalk from 'chalk';
|
|
|
6
6
|
import pickBy from 'lodash.pickby';
|
|
7
7
|
import { inspect } from 'node:util';
|
|
8
8
|
|
|
9
|
+
import { getPrototypeSpecificInstanceId } from '@dxos/util';
|
|
10
|
+
|
|
9
11
|
import { LogConfig, LogLevel, shortLevelName } from '../config';
|
|
10
12
|
import { getContextFromEntry, LogProcessor, shouldLog } from '../context';
|
|
11
13
|
|
|
@@ -44,21 +46,30 @@ export type FormatParts = {
|
|
|
44
46
|
message: string;
|
|
45
47
|
context?: any;
|
|
46
48
|
error?: Error;
|
|
49
|
+
scope?: any;
|
|
47
50
|
};
|
|
48
51
|
|
|
49
52
|
export type Formatter = (config: LogConfig, parts: FormatParts) => (string | undefined)[];
|
|
50
53
|
|
|
51
|
-
export const DEFAULT_FORMATTER: Formatter = (config, { path, line, level, message, context, error }) => {
|
|
54
|
+
export const DEFAULT_FORMATTER: Formatter = (config, { path, line, level, message, context, error, scope }) => {
|
|
52
55
|
const column = config.options?.formatter?.column;
|
|
53
56
|
|
|
54
57
|
const filepath = path !== undefined && line !== undefined ? chalk.grey(`${path}:${line}`) : undefined;
|
|
55
58
|
|
|
59
|
+
let instance;
|
|
60
|
+
if (scope) {
|
|
61
|
+
const prototype = Object.getPrototypeOf(scope);
|
|
62
|
+
const id = getPrototypeSpecificInstanceId(scope);
|
|
63
|
+
instance = chalk.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
return [
|
|
57
67
|
// NOTE: File path must come fist for console hyperlinks.
|
|
58
68
|
// Must not truncate for terminal output.
|
|
59
69
|
filepath,
|
|
60
70
|
column && filepath ? ''.padStart(column - filepath.length) : undefined,
|
|
61
71
|
chalk[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]),
|
|
72
|
+
instance,
|
|
62
73
|
message,
|
|
63
74
|
context,
|
|
64
75
|
error,
|
|
@@ -80,11 +91,20 @@ export const CONSOLE_PROCESSOR: LogProcessor = (config, entry) => {
|
|
|
80
91
|
return;
|
|
81
92
|
}
|
|
82
93
|
|
|
83
|
-
const parts: FormatParts = {
|
|
94
|
+
const parts: FormatParts = {
|
|
95
|
+
level,
|
|
96
|
+
message,
|
|
97
|
+
error,
|
|
98
|
+
path: undefined,
|
|
99
|
+
line: undefined,
|
|
100
|
+
scope: undefined,
|
|
101
|
+
context: undefined,
|
|
102
|
+
};
|
|
84
103
|
|
|
85
104
|
if (meta) {
|
|
86
105
|
parts.path = getRelativeFilename(meta.F);
|
|
87
106
|
parts.line = meta.L;
|
|
107
|
+
parts.scope = meta.S;
|
|
88
108
|
}
|
|
89
109
|
|
|
90
110
|
const context = getContextFromEntry(entry);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { CallMetadata } from './meta';
|
|
2
|
-
export type InvariantFn = (condition: unknown, message?: string, meta?: CallMetadata) => asserts condition;
|
|
3
|
-
/**
|
|
4
|
-
* Asserts that the condition is true.
|
|
5
|
-
*
|
|
6
|
-
* @param message Optional message.
|
|
7
|
-
*/
|
|
8
|
-
export declare const invariant: InvariantFn;
|
|
9
|
-
export declare class InvariantViolation extends Error {
|
|
10
|
-
constructor(message: string);
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../../src/invariant.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,SAAS,CAAC;AAE3G;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,WAwBvB,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAK5B"}
|
package/src/invariant.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { CallMetadata } from './meta';
|
|
6
|
-
|
|
7
|
-
export type InvariantFn = (condition: unknown, message?: string, meta?: CallMetadata) => asserts condition;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Asserts that the condition is true.
|
|
11
|
-
*
|
|
12
|
-
* @param message Optional message.
|
|
13
|
-
*/
|
|
14
|
-
export const invariant: InvariantFn = (
|
|
15
|
-
condition: unknown,
|
|
16
|
-
message?: string,
|
|
17
|
-
meta?: CallMetadata,
|
|
18
|
-
): asserts condition => {
|
|
19
|
-
if (condition) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let errorMessage = 'invariant violation';
|
|
24
|
-
|
|
25
|
-
if (message) {
|
|
26
|
-
errorMessage += `: ${message}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (meta?.A) {
|
|
30
|
-
errorMessage += ` [${meta.A[0]}]`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (meta?.F) {
|
|
34
|
-
errorMessage += ` at ${meta.F}:${meta.L}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
throw new InvariantViolation(errorMessage);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export class InvariantViolation extends Error {
|
|
41
|
-
constructor(message: string) {
|
|
42
|
-
super(message);
|
|
43
|
-
// NOTE: Restores prototype chain (https://stackoverflow.com/a/48342359).
|
|
44
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
45
|
-
}
|
|
46
|
-
}
|