@dxos/log 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5
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-IEP6GGEX.mjs +23 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
- package/dist/lib/browser/chunk-M2YHSBML.mjs +133 -0
- package/dist/lib/browser/chunk-M2YHSBML.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +227 -184
- 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 +107 -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-62VKC2WQ.mjs +135 -0
- package/dist/lib/node-esm/chunk-62VKC2WQ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +224 -266
- 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 +108 -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/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/dbg.d.ts +23 -0
- package/dist/types/src/dbg.d.ts.map +1 -0
- package/dist/types/src/decorators.d.ts +1 -1
- package/dist/types/src/decorators.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +4 -3
- 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 +14 -18
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/options.d.ts +1 -6
- 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/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/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 +32 -14
- package/src/config.ts +3 -2
- package/src/context.ts +38 -8
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +3 -3
- package/src/experimental/classes.test.ts +1 -1
- package/src/index.ts +4 -4
- package/src/log-buffer.test.ts +155 -0
- package/src/log-buffer.ts +117 -0
- package/src/log.test.ts +58 -23
- package/src/log.ts +104 -59
- package/src/options.ts +27 -11
- package/src/platform/index.ts +1 -1
- package/src/processors/browser-processor.ts +6 -2
- package/src/processors/console-processor.ts +8 -6
- package/src/processors/file-processor.ts +3 -1
- package/src/processors/index.ts +3 -3
- package/src/scope.ts +1 -1
package/src/log.ts
CHANGED
|
@@ -6,7 +6,16 @@ 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 { createConfig } from './options';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Accessible from browser console.
|
|
13
|
+
* Example: `DX_LOG.config({ filter: 'ERROR' })`
|
|
14
|
+
* NOTE: File level filtering isn't supported in storybooks.
|
|
15
|
+
*/
|
|
16
|
+
declare global {
|
|
17
|
+
const DX_LOG: Log;
|
|
18
|
+
}
|
|
10
19
|
|
|
11
20
|
/**
|
|
12
21
|
* Logging function.
|
|
@@ -17,6 +26,9 @@ type LogFunction = (message: string, context?: LogContext, meta?: CallMetadata)
|
|
|
17
26
|
* Logging methods.
|
|
18
27
|
*/
|
|
19
28
|
export interface LogMethods {
|
|
29
|
+
config: (options?: LogOptions) => Log;
|
|
30
|
+
addProcessor: (processor: LogProcessor, addDefault?: boolean) => () => void;
|
|
31
|
+
|
|
20
32
|
trace: LogFunction;
|
|
21
33
|
debug: LogFunction;
|
|
22
34
|
verbose: LogFunction;
|
|
@@ -24,92 +36,133 @@ export interface LogMethods {
|
|
|
24
36
|
warn: LogFunction;
|
|
25
37
|
error: LogFunction;
|
|
26
38
|
catch: (error: Error | any, context?: LogContext, meta?: CallMetadata) => void;
|
|
27
|
-
|
|
28
|
-
stack: (message?: string, context?: never, meta?: CallMetadata) => void;
|
|
39
|
+
|
|
29
40
|
method: (arg0?: never, arg1?: never, meta?: CallMetadata) => MethodDecorator;
|
|
30
|
-
|
|
41
|
+
function: <F extends (...args: any[]) => any>(
|
|
31
42
|
name: string,
|
|
32
43
|
fn: F,
|
|
33
|
-
opts?: {
|
|
44
|
+
opts?: {
|
|
45
|
+
transformOutput?: (result: ReturnType<F>) => Promise<any> | any;
|
|
46
|
+
},
|
|
34
47
|
) => F;
|
|
48
|
+
|
|
49
|
+
break: () => void;
|
|
50
|
+
stack: (message?: string, context?: never, meta?: CallMetadata) => void;
|
|
35
51
|
}
|
|
36
52
|
|
|
37
53
|
/**
|
|
38
54
|
* Properties accessible on the logging function.
|
|
55
|
+
* @internal
|
|
39
56
|
*/
|
|
40
|
-
interface Log extends
|
|
41
|
-
|
|
42
|
-
addProcessor: (processor: LogProcessor) => void;
|
|
43
|
-
runtimeConfig: LogConfig;
|
|
57
|
+
export interface Log extends LogFunction, LogMethods {
|
|
58
|
+
readonly runtimeConfig: LogConfig;
|
|
44
59
|
}
|
|
45
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
46
64
|
interface LogImp extends Log {
|
|
65
|
+
_id: string;
|
|
47
66
|
_config: LogConfig;
|
|
48
67
|
}
|
|
49
68
|
|
|
50
|
-
|
|
51
|
-
const log: LogImp = ((...params) => processLog(LogLevel.DEBUG, ...params)) as LogImp;
|
|
52
|
-
|
|
53
|
-
log._config = getConfig();
|
|
54
|
-
Object.defineProperty(log, 'runtimeConfig', { get: () => log._config });
|
|
55
|
-
|
|
56
|
-
log.addProcessor = (processor: LogProcessor) => {
|
|
57
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
58
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
59
|
-
}
|
|
60
|
-
if (log._config.processors.filter((p) => p === processor).length === 0) {
|
|
61
|
-
log._config.processors.push(processor);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// Set config.
|
|
66
|
-
log.config = (options: LogOptions) => {
|
|
67
|
-
log._config = getConfig(options);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// TODO(burdon): API to set context and separate error object.
|
|
71
|
-
// E.g., log.warn('failed', { key: 123 }, err);
|
|
72
|
-
|
|
73
|
-
log.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
74
|
-
log.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
75
|
-
log.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
76
|
-
log.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
77
|
-
log.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
78
|
-
log.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
69
|
+
let logCount = 0;
|
|
79
70
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Create a logging function with properties.
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export const createLog = (): LogImp => {
|
|
76
|
+
// Default function.
|
|
77
|
+
const log: LogImp = ((...params) => processLog(LogLevel.DEBUG, ...params)) as LogImp;
|
|
86
78
|
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
// Add private properties.
|
|
80
|
+
Object.assign<LogImp, Partial<LogImp>>(log, {
|
|
81
|
+
_id: `log-${++logCount}`,
|
|
82
|
+
_config: createConfig(),
|
|
83
|
+
});
|
|
89
84
|
|
|
90
|
-
|
|
91
|
-
log
|
|
85
|
+
// TODO(burdon): Document.
|
|
86
|
+
Object.defineProperty(log, 'runtimeConfig', {
|
|
87
|
+
get: () => log._config,
|
|
88
|
+
});
|
|
92
89
|
|
|
93
90
|
/**
|
|
94
91
|
* Process the current log call.
|
|
95
92
|
*/
|
|
96
93
|
const processLog = (
|
|
97
94
|
level: LogLevel,
|
|
98
|
-
message: string,
|
|
95
|
+
message: string | undefined,
|
|
99
96
|
context: LogContext = {},
|
|
100
97
|
meta?: CallMetadata,
|
|
101
98
|
error?: Error,
|
|
102
99
|
) => {
|
|
103
|
-
|
|
100
|
+
// TODO(burdon): Do the filter matching upstream (here) rather than in each processor?
|
|
101
|
+
log._config.processors.forEach((processor) =>
|
|
102
|
+
processor(log._config, {
|
|
103
|
+
level,
|
|
104
|
+
message,
|
|
105
|
+
context,
|
|
106
|
+
meta,
|
|
107
|
+
error,
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
104
110
|
};
|
|
105
111
|
|
|
112
|
+
/**
|
|
113
|
+
* API.
|
|
114
|
+
*/
|
|
115
|
+
Object.assign<Log, LogMethods>(log, {
|
|
116
|
+
/**
|
|
117
|
+
* Update config.
|
|
118
|
+
* NOTE: Preserves any processors that were already added to this logger instance
|
|
119
|
+
* unless an explicit processor option is provided.
|
|
120
|
+
*/
|
|
121
|
+
config: ({ processor, ...options } = {}) => {
|
|
122
|
+
const config = createConfig(options);
|
|
123
|
+
// TODO(burdon): This could be buggy since the behavior is not reentrant.
|
|
124
|
+
const processors = processor ? config.processors : log._config.processors;
|
|
125
|
+
log._config = { ...config, processors };
|
|
126
|
+
return log;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Adds a processor to the logger.
|
|
131
|
+
*/
|
|
132
|
+
addProcessor: (processor) => {
|
|
133
|
+
if (log._config.processors.filter((p) => p === processor).length === 0) {
|
|
134
|
+
log._config.processors.push(processor);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return () => {
|
|
138
|
+
log._config.processors = log._config.processors.filter((p) => p !== processor);
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
trace: (...params) => processLog(LogLevel.TRACE, ...params),
|
|
143
|
+
debug: (...params) => processLog(LogLevel.DEBUG, ...params),
|
|
144
|
+
verbose: (...params) => processLog(LogLevel.VERBOSE, ...params),
|
|
145
|
+
info: (...params) => processLog(LogLevel.INFO, ...params),
|
|
146
|
+
warn: (...params) => processLog(LogLevel.WARN, ...params),
|
|
147
|
+
error: (...params) => processLog(LogLevel.ERROR, ...params),
|
|
148
|
+
catch: (error, context, meta) => processLog(LogLevel.ERROR, undefined, context, meta, error),
|
|
149
|
+
|
|
150
|
+
method: createMethodLogDecorator(log),
|
|
151
|
+
function: createFunctionLogDecorator(log),
|
|
152
|
+
|
|
153
|
+
break: () => log.info('-'.repeat(80)),
|
|
154
|
+
stack: (message, context, meta) => {
|
|
155
|
+
return processLog(LogLevel.INFO, `${message ?? 'Stack Dump'}\n${getFormattedStackTrace()}`, context, meta);
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
106
159
|
return log;
|
|
107
160
|
};
|
|
108
161
|
|
|
109
162
|
/**
|
|
110
163
|
* Global logging function.
|
|
111
164
|
*/
|
|
112
|
-
export const log: Log = ((globalThis as any).
|
|
165
|
+
export const log: Log = ((globalThis as any).DX_LOG ??= createLog());
|
|
113
166
|
|
|
114
167
|
const start = Date.now();
|
|
115
168
|
let last = start;
|
|
@@ -129,12 +182,4 @@ export const debug = (label?: any, args?: any) => {
|
|
|
129
182
|
last = Date.now();
|
|
130
183
|
};
|
|
131
184
|
|
|
132
|
-
/**
|
|
133
|
-
* Accessible from browser console.
|
|
134
|
-
*/
|
|
135
|
-
declare global {
|
|
136
|
-
// eslint-disable-next-line camelcase
|
|
137
|
-
const dx_log: Log;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
185
|
const getFormattedStackTrace = () => new Error().stack!.split('\n').slice(3).join('\n');
|
package/src/options.ts
CHANGED
|
@@ -7,37 +7,53 @@ 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.
|
|
14
14
|
*/
|
|
15
|
-
export const processors:
|
|
15
|
+
export const processors: Record<string, LogProcessor> = {
|
|
16
16
|
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
17
17
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
18
18
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const browser =
|
|
22
|
+
(typeof window !== 'undefined' || typeof navigator !== 'undefined') &&
|
|
23
|
+
!(typeof process !== 'undefined' && process?.env?.VITEST);
|
|
22
24
|
|
|
23
|
-
export const DEFAULT_PROCESSORS = [
|
|
25
|
+
export const DEFAULT_PROCESSORS = [browser ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR];
|
|
24
26
|
|
|
27
|
+
const parseLogLevel = (level: string, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
25
32
|
export const parseFilter = (filter: string | string[] | LogLevel): LogFilter[] => {
|
|
26
33
|
if (typeof filter === 'number') {
|
|
27
34
|
return [{ level: filter }];
|
|
28
35
|
}
|
|
29
36
|
|
|
30
|
-
const parseLogLevel = (level: string, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
31
|
-
|
|
32
37
|
const lines = typeof filter === 'string' ? filter.split(/,\s*/) : filter;
|
|
33
38
|
return lines.map((filter) => {
|
|
34
39
|
const [pattern, level] = filter.split(':');
|
|
35
|
-
return level
|
|
40
|
+
return level
|
|
41
|
+
? {
|
|
42
|
+
level: parseLogLevel(level),
|
|
43
|
+
pattern,
|
|
44
|
+
}
|
|
45
|
+
: {
|
|
46
|
+
level: parseLogLevel(pattern),
|
|
47
|
+
};
|
|
36
48
|
});
|
|
37
49
|
};
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export const createConfig = (options?: LogOptions): LogConfig => {
|
|
55
|
+
// Node only.
|
|
56
|
+
const envOptions: LogOptions | undefined =
|
|
41
57
|
'process' in globalThis
|
|
42
58
|
? {
|
|
43
59
|
file: process!.env.LOG_CONFIG,
|
|
@@ -46,12 +62,12 @@ export const getConfig = (options?: LogOptions): LogConfig => {
|
|
|
46
62
|
}
|
|
47
63
|
: undefined;
|
|
48
64
|
|
|
49
|
-
const mergedOptions: LogOptions = defaultsDeep({}, loadOptions(
|
|
65
|
+
const mergedOptions: LogOptions = defaultsDeep({}, loadOptions(envOptions?.file), envOptions, options);
|
|
50
66
|
return {
|
|
51
67
|
options: mergedOptions,
|
|
52
68
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
53
69
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
54
|
-
processors: mergedOptions.processor ? [processors[mergedOptions.processor]] : DEFAULT_PROCESSORS,
|
|
70
|
+
processors: mergedOptions.processor ? [processors[mergedOptions.processor]] : [...DEFAULT_PROCESSORS],
|
|
55
71
|
prefix: mergedOptions.prefix,
|
|
56
72
|
};
|
|
57
73
|
};
|
package/src/platform/index.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -7,9 +7,9 @@ import { inspect } from 'node:util';
|
|
|
7
7
|
|
|
8
8
|
import { getPrototypeSpecificInstanceId, pickBy } from '@dxos/util';
|
|
9
9
|
|
|
10
|
-
import { getRelativeFilename } from './common';
|
|
11
10
|
import { type LogConfig, LogLevel, shortLevelName } from '../config';
|
|
12
|
-
import {
|
|
11
|
+
import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
|
|
12
|
+
import { getRelativeFilename } from './common';
|
|
13
13
|
|
|
14
14
|
const LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {
|
|
15
15
|
[LogLevel.TRACE]: 'gray',
|
|
@@ -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;
|
|
@@ -50,8 +50,10 @@ export const DEFAULT_FORMATTER: Formatter = (
|
|
|
50
50
|
let instance;
|
|
51
51
|
if (scope) {
|
|
52
52
|
const prototype = Object.getPrototypeOf(scope);
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if (prototype !== null) {
|
|
54
|
+
const id = getPrototypeSpecificInstanceId(scope);
|
|
55
|
+
instance = chalk.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
56
|
+
}
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
const formattedTimestamp = config.options?.formatter?.timestamp ? new Date().toISOString() : undefined;
|
|
@@ -7,12 +7,13 @@ 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';
|
|
12
|
+
import { getRelativeFilename } from './common';
|
|
13
13
|
|
|
14
14
|
// Amount of time to retry writing after encountering EAGAIN before giving up.
|
|
15
15
|
const EAGAIN_MAX_DURATION = 1000;
|
|
16
|
+
|
|
16
17
|
/**
|
|
17
18
|
* Create a file processor.
|
|
18
19
|
* @param path - Path to log file to create or append to, or existing open file descriptor e.g. stdout.
|
|
@@ -37,6 +38,7 @@ export const createFileProcessor = ({
|
|
|
37
38
|
if (!shouldLog(entry, filters)) {
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
41
|
+
|
|
40
42
|
if (typeof pathOrFd === 'number') {
|
|
41
43
|
fd = pathOrFd;
|
|
42
44
|
} else {
|
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';
|
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];
|