@dxos/log 0.4.10-main.fa5a270 → 0.4.10-main.fd4f2a3
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 +49 -18
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +61 -28
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/decorators.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 +10 -3
- package/dist/types/src/processors/file-processor.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/context.ts +1 -1
- package/src/decorators.ts +100 -24
- package/src/log.ts +1 -1
- package/src/processors/browser-processor.ts +1 -1
- package/src/processors/console-processor.ts +9 -8
- package/src/processors/file-processor.ts +27 -8
|
@@ -7,21 +7,40 @@ import { dirname } from 'node:path';
|
|
|
7
7
|
|
|
8
8
|
import { jsonify } from '@dxos/util';
|
|
9
9
|
|
|
10
|
-
import { LogLevel } from '../config';
|
|
11
|
-
import { type LogProcessor, getContextFromEntry } from '../context';
|
|
10
|
+
import { type LogFilter, LogLevel } from '../config';
|
|
11
|
+
import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Create a file processor.
|
|
15
|
+
* @param path - Path to log file to create or append to, or existing open file descriptor e.g. stdout.
|
|
16
|
+
* @param levels - Log levels to process. Takes preference over Filters.
|
|
17
|
+
* @param filters - Filters to apply.
|
|
18
|
+
*/
|
|
19
|
+
export const createFileProcessor = ({
|
|
20
|
+
pathOrFd,
|
|
21
|
+
levels,
|
|
22
|
+
filters,
|
|
23
|
+
}: {
|
|
24
|
+
pathOrFd: string | number;
|
|
25
|
+
levels: LogLevel[];
|
|
26
|
+
filters?: LogFilter[];
|
|
27
|
+
}): LogProcessor => {
|
|
14
28
|
let fd: number | undefined;
|
|
15
29
|
|
|
16
30
|
return (config, entry) => {
|
|
17
|
-
if (!levels.includes(entry.level)) {
|
|
31
|
+
if (levels.length > 0 && !levels.includes(entry.level)) {
|
|
18
32
|
return;
|
|
19
33
|
}
|
|
20
|
-
if (!
|
|
34
|
+
if (!shouldLog(entry, filters)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (typeof pathOrFd === 'number') {
|
|
38
|
+
fd = pathOrFd;
|
|
39
|
+
} else {
|
|
21
40
|
try {
|
|
22
|
-
mkdirSync(dirname(
|
|
41
|
+
mkdirSync(dirname(pathOrFd));
|
|
23
42
|
} catch {}
|
|
24
|
-
fd = openSync(
|
|
43
|
+
fd = openSync(pathOrFd, 'w');
|
|
25
44
|
}
|
|
26
45
|
|
|
27
46
|
const record = {
|
|
@@ -47,6 +66,6 @@ const getLogFilePath = () => {
|
|
|
47
66
|
};
|
|
48
67
|
|
|
49
68
|
export const FILE_PROCESSOR: LogProcessor = createFileProcessor({
|
|
50
|
-
|
|
69
|
+
pathOrFd: getLogFilePath(),
|
|
51
70
|
levels: [LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO, LogLevel.TRACE],
|
|
52
71
|
});
|