@dxos/log 0.8.4-main.fffef41 → 0.8.4-staging.ac66bdf99f
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/chunk-DTUPLFUN.mjs +311 -0
- package/dist/lib/browser/chunk-DTUPLFUN.mjs.map +7 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs +23 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +187 -199
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/platform/browser/index.mjs +26 -0
- package/dist/lib/browser/platform/browser/index.mjs.map +7 -0
- package/dist/lib/browser/platform/node/index.mjs +21 -0
- package/dist/lib/browser/platform/node/index.mjs.map +7 -0
- package/dist/lib/browser/processors/console-processor.mjs +102 -0
- package/dist/lib/browser/processors/console-processor.mjs.map +7 -0
- package/dist/lib/browser/processors/console-stub.mjs +9 -0
- package/dist/lib/browser/processors/console-stub.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KOTHKRYW.mjs +313 -0
- package/dist/lib/node-esm/chunk-KOTHKRYW.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +189 -288
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/platform/browser/index.mjs +27 -0
- package/dist/lib/node-esm/platform/browser/index.mjs.map +7 -0
- package/dist/lib/node-esm/platform/node/index.mjs +22 -0
- package/dist/lib/node-esm/platform/node/index.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-processor.mjs +103 -0
- package/dist/lib/node-esm/processors/console-processor.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-stub.mjs +10 -0
- package/dist/lib/node-esm/processors/console-stub.mjs.map +7 -0
- package/dist/types/src/context.d.ts +78 -2
- package/dist/types/src/context.d.ts.map +1 -1
- package/dist/types/src/dbg.d.ts +23 -0
- package/dist/types/src/dbg.d.ts.map +1 -0
- package/dist/types/src/decorators.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/log-buffer.d.ts +40 -0
- package/dist/types/src/log-buffer.d.ts.map +1 -0
- package/dist/types/src/log-buffer.test.d.ts +2 -0
- package/dist/types/src/log-buffer.test.d.ts.map +1 -0
- package/dist/types/src/log.d.ts +3 -1
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/options.d.ts.map +1 -1
- package/dist/types/src/platform/index.d.ts +1 -1
- package/dist/types/src/platform/index.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.map +1 -1
- package/dist/types/src/processors/file-processor.d.ts.map +1 -1
- package/dist/types/src/processors/index.d.ts +3 -3
- package/dist/types/src/processors/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +30 -12
- package/src/context.ts +242 -2
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +1 -2
- package/src/experimental/classes.test.ts +0 -1
- package/src/index.ts +3 -3
- package/src/log-buffer.test.ts +158 -0
- package/src/log-buffer.ts +110 -0
- package/src/log.test.ts +0 -1
- package/src/log.ts +7 -12
- package/src/options.ts +3 -1
- package/src/platform/index.ts +1 -1
- package/src/platform/node/index.ts +1 -2
- package/src/processors/browser-processor.ts +27 -28
- package/src/processors/console-processor.ts +5 -13
- package/src/processors/file-processor.ts +7 -9
- package/src/processors/index.ts +3 -3
package/src/log.ts
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type LogConfig, LogLevel, type LogOptions } from './config';
|
|
6
|
-
import { type LogContext, type LogProcessor } from './context';
|
|
6
|
+
import { type LogContext, LogEntry, type LogProcessor } from './context';
|
|
7
7
|
import { createFunctionLogDecorator, createMethodLogDecorator } from './decorators';
|
|
8
8
|
import { type CallMetadata } from './meta';
|
|
9
9
|
import { createConfig } from './options';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Accessible from browser console.
|
|
13
|
+
* Example: `DX_LOG.config({ filter: 'ERROR' })`
|
|
14
|
+
* NOTE: File level filtering isn't supported in storybooks.
|
|
13
15
|
*/
|
|
14
16
|
declare global {
|
|
15
17
|
const DX_LOG: Log;
|
|
@@ -24,7 +26,7 @@ type LogFunction = (message: string, context?: LogContext, meta?: CallMetadata)
|
|
|
24
26
|
* Logging methods.
|
|
25
27
|
*/
|
|
26
28
|
export interface LogMethods {
|
|
27
|
-
config: (options
|
|
29
|
+
config: (options?: LogOptions) => Log;
|
|
28
30
|
addProcessor: (processor: LogProcessor, addDefault?: boolean) => () => void;
|
|
29
31
|
|
|
30
32
|
trace: LogFunction;
|
|
@@ -96,15 +98,8 @@ export const createLog = (): LogImp => {
|
|
|
96
98
|
error?: Error,
|
|
97
99
|
) => {
|
|
98
100
|
// TODO(burdon): Do the filter matching upstream (here) rather than in each processor?
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
level,
|
|
102
|
-
message,
|
|
103
|
-
context,
|
|
104
|
-
meta,
|
|
105
|
-
error,
|
|
106
|
-
}),
|
|
107
|
-
);
|
|
101
|
+
const entry = new LogEntry({ level, message, context, meta, error });
|
|
102
|
+
log._config.processors.forEach((processor) => processor(log._config, entry));
|
|
108
103
|
};
|
|
109
104
|
|
|
110
105
|
/**
|
|
@@ -116,7 +111,7 @@ export const createLog = (): LogImp => {
|
|
|
116
111
|
* NOTE: Preserves any processors that were already added to this logger instance
|
|
117
112
|
* unless an explicit processor option is provided.
|
|
118
113
|
*/
|
|
119
|
-
config: ({ processor, ...options }) => {
|
|
114
|
+
config: ({ processor, ...options } = {}) => {
|
|
120
115
|
const config = createConfig(options);
|
|
121
116
|
// TODO(burdon): This could be buggy since the behavior is not reentrant.
|
|
122
117
|
const processors = processor ? config.processors : log._config.processors;
|
package/src/options.ts
CHANGED
|
@@ -18,7 +18,9 @@ export const processors: Record<string, LogProcessor> = {
|
|
|
18
18
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const browser =
|
|
21
|
+
const browser =
|
|
22
|
+
(typeof window !== 'undefined' || typeof navigator !== 'undefined') &&
|
|
23
|
+
!(typeof process !== 'undefined' && process?.env?.VITEST);
|
|
22
24
|
|
|
23
25
|
export const DEFAULT_PROCESSORS = [browser ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR];
|
|
24
26
|
|
package/src/platform/index.ts
CHANGED
|
@@ -2,23 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { safariCheck } from '@dxos/util';
|
|
6
6
|
|
|
7
7
|
import { LogLevel } from '../config';
|
|
8
8
|
import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
|
|
9
9
|
|
|
10
|
-
const getRelativeFilename = (filename: string) => {
|
|
11
|
-
// TODO(burdon): Hack uses "packages" as an anchor (pre-parse NX?)
|
|
12
|
-
// Including `packages/` part of the path so that excluded paths (e.g. from dist) are clickable in vscode.
|
|
13
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
14
|
-
if (match) {
|
|
15
|
-
const [, filePath] = match;
|
|
16
|
-
return filePath;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return filename;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
10
|
type Config = {
|
|
23
11
|
useTestProcessor: boolean;
|
|
24
12
|
printFileLinks: boolean;
|
|
@@ -47,23 +35,26 @@ const APP_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {
|
|
|
47
35
|
// const LOG_BROWSER_CSS = ['color:gray; font-size:10px; padding-bottom: 4px', 'color:#B97852; font-size:14px;'];
|
|
48
36
|
const LOG_BROWSER_CSS: string[] = [];
|
|
49
37
|
|
|
38
|
+
const { filename, line: lineNumber, context: scopeDebugName } = entry.computedMeta;
|
|
39
|
+
|
|
50
40
|
let link = '';
|
|
51
|
-
if (
|
|
52
|
-
const filename = getRelativeFilename(entry.meta.F);
|
|
41
|
+
if (filename !== undefined && lineNumber !== undefined) {
|
|
53
42
|
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, '')}/${filename}`;
|
|
54
43
|
// TODO(burdon): Line numbers not working for app link, even with colons.
|
|
55
44
|
// https://stackoverflow.com/a/54459820/2804332
|
|
56
|
-
link = `${filepath}#L${
|
|
45
|
+
link = `${filepath}#L${lineNumber}`;
|
|
57
46
|
}
|
|
58
47
|
|
|
59
48
|
let args = [];
|
|
60
49
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const scopeName = scope.name ||
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
50
|
+
const scope = entry.meta?.S;
|
|
51
|
+
if (scope) {
|
|
52
|
+
const scopeName = scope.name || scopeDebugName;
|
|
53
|
+
if (scopeName) {
|
|
54
|
+
const processPrefix = scope.hostSessionId ? '[worker] ' : '';
|
|
55
|
+
// TODO(dmaretskyi): Those can be made clickable with a custom formatter.
|
|
56
|
+
args.push(`%c${processPrefix}${scopeName}`, 'color:#C026D3;font-weight:bold');
|
|
57
|
+
}
|
|
67
58
|
}
|
|
68
59
|
|
|
69
60
|
if (entry.message) {
|
|
@@ -73,9 +64,9 @@ const APP_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {
|
|
|
73
64
|
const context = getContextFromEntry(entry);
|
|
74
65
|
if (context) {
|
|
75
66
|
if (Object.keys(context).length === 1 && 'error' in context) {
|
|
76
|
-
args.push(context.error);
|
|
67
|
+
args.push(unwrapEffectError(context.error));
|
|
77
68
|
} else if (Object.keys(context).length === 1 && 'err' in context) {
|
|
78
|
-
args.push(context.err);
|
|
69
|
+
args.push(unwrapEffectError(context.err));
|
|
79
70
|
} else {
|
|
80
71
|
args.push(context);
|
|
81
72
|
}
|
|
@@ -114,10 +105,8 @@ const TEST_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {
|
|
|
114
105
|
return;
|
|
115
106
|
}
|
|
116
107
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
path = `${getRelativeFilename(entry.meta.F)}:${entry.meta.L}`;
|
|
120
|
-
}
|
|
108
|
+
const { filename, line: lineNumber } = entry.computedMeta;
|
|
109
|
+
const path = filename !== undefined && lineNumber !== undefined ? `${filename}:${lineNumber}` : '';
|
|
121
110
|
|
|
122
111
|
let args = [];
|
|
123
112
|
|
|
@@ -148,3 +137,13 @@ const TEST_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {
|
|
|
148
137
|
};
|
|
149
138
|
|
|
150
139
|
export const BROWSER_PROCESSOR: LogProcessor = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
140
|
+
|
|
141
|
+
// effect-specific
|
|
142
|
+
const originalSymbol = Symbol.for('effect/OriginalAnnotation');
|
|
143
|
+
|
|
144
|
+
const unwrapEffectError = (error: any) => {
|
|
145
|
+
if (typeof error === 'object' && error !== null && originalSymbol in error) {
|
|
146
|
+
return error[originalSymbol];
|
|
147
|
+
}
|
|
148
|
+
return error;
|
|
149
|
+
};
|
|
@@ -2,17 +2,14 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { inspect } from 'node:util';
|
|
6
|
-
|
|
7
5
|
import chalk from 'chalk';
|
|
6
|
+
import { inspect } from 'node:util';
|
|
8
7
|
|
|
9
8
|
import { getPrototypeSpecificInstanceId, pickBy } from '@dxos/util';
|
|
10
9
|
|
|
11
10
|
import { type LogConfig, LogLevel, shortLevelName } from '../config';
|
|
12
11
|
import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
|
|
13
12
|
|
|
14
|
-
import { getRelativeFilename } from './common';
|
|
15
|
-
|
|
16
13
|
const LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {
|
|
17
14
|
[LogLevel.TRACE]: 'gray',
|
|
18
15
|
[LogLevel.DEBUG]: 'gray',
|
|
@@ -95,22 +92,17 @@ export const CONSOLE_PROCESSOR: LogProcessor = (config, entry) => {
|
|
|
95
92
|
return;
|
|
96
93
|
}
|
|
97
94
|
|
|
95
|
+
const { filename, line: lineNumber } = entry.computedMeta;
|
|
98
96
|
const parts: FormatParts = {
|
|
99
97
|
level,
|
|
100
98
|
message,
|
|
101
99
|
error,
|
|
102
|
-
path:
|
|
103
|
-
line:
|
|
104
|
-
scope:
|
|
100
|
+
path: filename,
|
|
101
|
+
line: lineNumber,
|
|
102
|
+
scope: meta?.S,
|
|
105
103
|
context: undefined,
|
|
106
104
|
};
|
|
107
105
|
|
|
108
|
-
if (meta) {
|
|
109
|
-
parts.path = getRelativeFilename(meta.F);
|
|
110
|
-
parts.line = meta.L;
|
|
111
|
-
parts.scope = meta.S;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
106
|
const context = getContextFromEntry(entry);
|
|
115
107
|
if (context) {
|
|
116
108
|
// Remove undefined fields.
|
|
@@ -5,12 +5,8 @@
|
|
|
5
5
|
import { appendFileSync, mkdirSync, openSync } from 'node:fs';
|
|
6
6
|
import { dirname } from 'node:path';
|
|
7
7
|
|
|
8
|
-
import { jsonlogify } from '@dxos/util';
|
|
9
|
-
|
|
10
8
|
import { type LogFilter, LogLevel } from '../config';
|
|
11
|
-
import { type LogProcessor,
|
|
12
|
-
|
|
13
|
-
import { getRelativeFilename } from './common';
|
|
9
|
+
import { type LogProcessor, shouldLog } from '../context';
|
|
14
10
|
|
|
15
11
|
// Amount of time to retry writing after encountering EAGAIN before giving up.
|
|
16
12
|
const EAGAIN_MAX_DURATION = 1000;
|
|
@@ -50,10 +46,12 @@ export const createFileProcessor = ({
|
|
|
50
46
|
}
|
|
51
47
|
|
|
52
48
|
const record = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
level: entry.level,
|
|
50
|
+
message: entry.message,
|
|
51
|
+
timestamp: entry.timestamp,
|
|
52
|
+
meta: entry.computedMeta,
|
|
53
|
+
context: entry.computedContext,
|
|
54
|
+
error: entry.computedError,
|
|
57
55
|
};
|
|
58
56
|
let retryTS: number = 0;
|
|
59
57
|
|
package/src/processors/index.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './console-processor';
|
|
6
|
-
export * from './debug-processor';
|
|
7
5
|
export * from './browser-processor';
|
|
8
|
-
export * from './file-processor';
|
|
9
6
|
export * from './common';
|
|
7
|
+
export * from '#console-processor';
|
|
8
|
+
export * from './debug-processor';
|
|
9
|
+
export * from './file-processor';
|