@holz/core 0.10.1-rc.6.sha-c824ebd → 0.10.1-rc.7.sha-a01a6d1
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/README.md +3 -3
- package/dist/functions-DALPLIbM.js +5 -0
- package/dist/functions.d.ts +2 -0
- package/dist/functions.js +1 -0
- package/dist/holz-core.d.ts +6 -132
- package/dist/holz-core.js +5 -6
- package/dist/index-BwPlyye8.d.ts +132 -0
- package/package.json +7 -2
- package/src/functions/combine.ts +11 -0
- package/src/{operators.ts → functions/filter.ts} +1 -11
- package/src/functions/index.ts +2 -0
- package/src/index.ts +8 -1
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ Holz provides a set of off-the-shelf plugins for logging to various destinations
|
|
|
91
91
|
|
|
92
92
|
Holz's plugin system is designed to be flexible and extensible. If none of the provided plugins meet your needs, you can easily create your own plugin and still build on plugins from the rest of the ecosystem. Check out the [`@holz/logger`](https://github.com/PsychoLlama/holz/tree/main/packages/holz-logger) package for a bundled example of Holz's logging plugins.
|
|
93
93
|
|
|
94
|
-
##
|
|
94
|
+
## Functions
|
|
95
95
|
|
|
96
96
|
In addition to the core `Logger` class, `@holz/core` provides some utility processors that you can use to extend the functionality of your logging solution. These processors are optional and can be combined with each other or with third-party processors as needed.
|
|
97
97
|
|
|
@@ -100,7 +100,7 @@ In addition to the core `Logger` class, `@holz/core` provides some utility proce
|
|
|
100
100
|
The `combine` processor takes an array of log processors and returns a single log processor that forwards each log to all of the input processors. This is useful when you want to send a single log to multiple log destinations.
|
|
101
101
|
|
|
102
102
|
```typescript
|
|
103
|
-
import { combine } from '@holz/core';
|
|
103
|
+
import { combine } from '@holz/core/functions';
|
|
104
104
|
import {
|
|
105
105
|
consoleBackend,
|
|
106
106
|
fileBackend,
|
|
@@ -117,7 +117,7 @@ const logger = createLogger(
|
|
|
117
117
|
The `filter` processor takes a filter function and another log processor as input. If the filter function returns `true` for a log, it is forwarded to the second processor. If the filter function returns `false`, the log is discarded. This is useful when you want to selectively forward logs based on some criteria.
|
|
118
118
|
|
|
119
119
|
```typescript
|
|
120
|
-
import { filter } from '@holz/core';
|
|
120
|
+
import { filter } from '@holz/core/functions';
|
|
121
121
|
|
|
122
122
|
const debugLogFilter = filter(
|
|
123
123
|
(log) => log.level > level.debug,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as combine, t as filter } from "./functions-DALPLIbM.js";
|
package/dist/holz-core.d.ts
CHANGED
|
@@ -1,134 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* A logger is made up of log processors. These processors take structured
|
|
3
|
-
* logs and do something with them. Examples are logging backends (console,
|
|
4
|
-
* file, uploads) and operators (filtering, transforming, aggregating).
|
|
5
|
-
*/
|
|
6
|
-
interface LogProcessor {
|
|
7
|
-
/** Do something with a log message. */
|
|
8
|
-
(log: Log): unknown;
|
|
9
|
-
}
|
|
10
|
-
/** A log message where variables are carried as structured data. */
|
|
11
|
-
interface Log {
|
|
12
|
-
/** Unix timestamp. Includes milliseconds. */
|
|
13
|
-
readonly timestamp: number;
|
|
14
|
-
/** The verbatim log message. Should not contain interpolated data. */
|
|
15
|
-
readonly message: string;
|
|
16
|
-
/** Log severity. One of `levels.*`. */
|
|
17
|
-
readonly level: LogLevel;
|
|
18
|
-
/**
|
|
19
|
-
* Where the log message originated. Usually starts with a library or app name,
|
|
20
|
-
* followed by something more specific.
|
|
21
|
-
*
|
|
22
|
-
* @example ['logger-library', 'ConsoleBackend']
|
|
23
|
-
*/
|
|
24
|
-
readonly origin: ReadonlyArray<string>;
|
|
25
|
-
/**
|
|
26
|
-
* Key-value pairs that provide additional context for the log message. If
|
|
27
|
-
* you're tempted to interpolate data into the message, consider using log
|
|
28
|
-
* context instead.
|
|
29
|
-
*
|
|
30
|
-
* These values must be JSON serializable.
|
|
31
|
-
*
|
|
32
|
-
* @example { userId: 123, reason: 'disconnect' }
|
|
33
|
-
*/
|
|
34
|
-
readonly context: LogContext;
|
|
35
|
-
}
|
|
36
|
-
export declare const level: {
|
|
37
|
-
/** A critical failure happened and the program must exit. */
|
|
38
|
-
readonly fatal: 60;
|
|
39
|
-
/** Something failed, but we can keep going. */
|
|
40
|
-
readonly error: 50;
|
|
41
|
-
/** Cause for concern, but we can keep going. */
|
|
42
|
-
readonly warn: 40;
|
|
43
|
-
/** High-level progress updates. */
|
|
44
|
-
readonly info: 30;
|
|
45
|
-
/** Verbose update about events or control flow (usually hidden). */
|
|
46
|
-
readonly debug: 20;
|
|
47
|
-
/** Extremely detailed progress updates (usually hidden). */
|
|
48
|
-
readonly trace: 10;
|
|
49
|
-
};
|
|
50
|
-
type LogLevel = (typeof level)[keyof typeof level];
|
|
51
|
-
type JsonPrimitive = string | number | boolean | null | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* Any JSON-serializable value. Supports nested objects and arrays so log
|
|
54
|
-
* context can carry structured data.
|
|
55
|
-
*/
|
|
56
|
-
type JsonValue = JsonPrimitive | ReadonlyArray<JsonValue> | {
|
|
57
|
-
readonly [key: string]: JsonValue;
|
|
58
|
-
};
|
|
59
|
-
interface JsonContext {
|
|
60
|
-
[key: string]: JsonValue;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Custom values allowed in log context. These values don't have to be JSON.
|
|
64
|
-
* The most common case is errors, which support richer error tracking in
|
|
65
|
-
* backends that support it.
|
|
66
|
-
*
|
|
67
|
-
* This is part of the public API. Backends may use declaration merging to
|
|
68
|
-
* extend the standard attributes. It's recommended to use symbols as keys for
|
|
69
|
-
* custom features, but not required.
|
|
70
|
-
*/
|
|
71
|
-
interface CustomContext {
|
|
72
|
-
/**
|
|
73
|
-
* Error instance associated with the log message. This supports error
|
|
74
|
-
* tracking and shows prominently in visual backends like TTY output.
|
|
75
|
-
*/
|
|
76
|
-
error: Error;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* A type narrowing constraint designed for generic constraints. Controls
|
|
80
|
-
* what fields are allowed in `log.context`, sourcing from `CustomContext`
|
|
81
|
-
* first, then falling back to any JSON value.
|
|
82
|
-
*/
|
|
83
|
-
type StrictContext<Input> = { [Key in keyof Input]: Key extends keyof CustomContext ? CustomContext[Key] : JsonValue; };
|
|
84
|
-
/**
|
|
85
|
-
* A more general type expected by logging backends. Supports type narrowing,
|
|
86
|
-
* so if a known field exists, it will be used instead of the generic JSON
|
|
87
|
-
* type.
|
|
88
|
-
*/
|
|
89
|
-
type LogContext = Partial<CustomContext> & JsonContext;
|
|
90
|
-
/**
|
|
91
|
-
* This is the public API which generates and sends `Log` events through the
|
|
92
|
-
* user-defined processing pipeline.
|
|
93
|
-
*/
|
|
94
|
-
interface Logger {
|
|
95
|
-
readonly owner: ReadonlyArray<string>;
|
|
96
|
-
/** Extend the logger to attach a class or module name to logs. */
|
|
97
|
-
namespace: (owner: string) => Logger;
|
|
98
|
-
/**
|
|
99
|
-
* Create a new logger which runs all logs through a middleware function.
|
|
100
|
-
* Useful for adding default context, doing ad-hoc filtering, or
|
|
101
|
-
* registering plugins. Only applies to this logger and its descendants.
|
|
102
|
-
*/
|
|
103
|
-
withMiddleware: (middleware: (next: LogProcessor) => LogProcessor) => Logger;
|
|
104
|
-
/** Log a verbose and frequent update. */
|
|
105
|
-
trace: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
106
|
-
/** Log a frequent and verbose progress update. */
|
|
107
|
-
debug: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
108
|
-
/** Log a high-level progress update. */
|
|
109
|
-
info: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
110
|
-
/** Log something concerning. */
|
|
111
|
-
warn: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
112
|
-
/** Log a failure. */
|
|
113
|
-
error: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
114
|
-
/** Log a catastrophic failure. */
|
|
115
|
-
fatal: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Combine several log processors into a single log processor. Each one is
|
|
119
|
-
* called in sequence. Useful for sending a single log to multiple log
|
|
120
|
-
* destinations.
|
|
121
|
-
*/
|
|
122
|
-
export declare const combine: (processors: Array<LogProcessor>) => LogProcessor;
|
|
123
|
-
/**
|
|
124
|
-
* Filter logs based on a filter function. If the function returns true, the
|
|
125
|
-
* log is kept and forwarded onto the next processor, otherwise it is
|
|
126
|
-
* discarded.
|
|
127
|
-
*
|
|
128
|
-
* @param predicate Returns `true` to forward the log.
|
|
129
|
-
* @param processor Where to send the log if it passes the filter.
|
|
130
|
-
*/
|
|
131
|
-
export declare const filter: (predicate: (log: Log) => boolean, processor: LogProcessor) => LogProcessor;
|
|
1
|
+
import { a as LogContext, c as Logger, i as Log, l as level, n as combine$1, o as LogLevel, r as CustomContext, s as LogProcessor, t as filter$1 } from "./index-BwPlyye8.js";
|
|
132
2
|
/**
|
|
133
3
|
* Create a new logger. The processor is up to you. There are plugins for
|
|
134
4
|
* filtering, formatting, combining multiple processors together, and more.
|
|
@@ -136,4 +6,8 @@ export declare const filter: (predicate: (log: Log) => boolean, processor: LogPr
|
|
|
136
6
|
* If you wish to use more than one processor, `combine(...)` them first.
|
|
137
7
|
*/
|
|
138
8
|
export declare const createLogger: (processor: LogProcessor) => Logger;
|
|
139
|
-
|
|
9
|
+
/** @deprecated Import from `@holz/core/functions` instead. */
|
|
10
|
+
export declare const combine: typeof combine$1;
|
|
11
|
+
/** @deprecated Import from `@holz/core/functions` instead. */
|
|
12
|
+
export declare const filter: typeof filter$1;
|
|
13
|
+
export { type CustomContext, type Log, type LogContext, type LogLevel, type LogProcessor, type Logger, level };
|
package/dist/holz-core.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}, n = {
|
|
1
|
+
import { n as e, t } from "./functions-DALPLIbM.js";
|
|
2
|
+
// src/types.ts
|
|
3
|
+
var n = {
|
|
5
4
|
fatal: 60,
|
|
6
5
|
error: 50,
|
|
7
6
|
warn: 40,
|
|
@@ -41,5 +40,5 @@ var e = (e) => (t) => e.forEach((e) => e(t)), t = (e, t) => (n) => {
|
|
|
41
40
|
error: o,
|
|
42
41
|
fatal: o
|
|
43
42
|
});
|
|
44
|
-
}, i = (e) => r(e, []);
|
|
45
|
-
export {
|
|
43
|
+
}, i = (e) => r(e, []), a = e, o = t;
|
|
44
|
+
export { a as combine, i as createLogger, o as filter, n as level };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A logger is made up of log processors. These processors take structured
|
|
3
|
+
* logs and do something with them. Examples are logging backends (console,
|
|
4
|
+
* file, uploads) and operators (filtering, transforming, aggregating).
|
|
5
|
+
*/
|
|
6
|
+
interface LogProcessor {
|
|
7
|
+
/** Do something with a log message. */
|
|
8
|
+
(log: Log): unknown;
|
|
9
|
+
}
|
|
10
|
+
/** A log message where variables are carried as structured data. */
|
|
11
|
+
interface Log {
|
|
12
|
+
/** Unix timestamp. Includes milliseconds. */
|
|
13
|
+
readonly timestamp: number;
|
|
14
|
+
/** The verbatim log message. Should not contain interpolated data. */
|
|
15
|
+
readonly message: string;
|
|
16
|
+
/** Log severity. One of `levels.*`. */
|
|
17
|
+
readonly level: LogLevel;
|
|
18
|
+
/**
|
|
19
|
+
* Where the log message originated. Usually starts with a library or app name,
|
|
20
|
+
* followed by something more specific.
|
|
21
|
+
*
|
|
22
|
+
* @example ['logger-library', 'ConsoleBackend']
|
|
23
|
+
*/
|
|
24
|
+
readonly origin: ReadonlyArray<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Key-value pairs that provide additional context for the log message. If
|
|
27
|
+
* you're tempted to interpolate data into the message, consider using log
|
|
28
|
+
* context instead.
|
|
29
|
+
*
|
|
30
|
+
* These values must be JSON serializable.
|
|
31
|
+
*
|
|
32
|
+
* @example { userId: 123, reason: 'disconnect' }
|
|
33
|
+
*/
|
|
34
|
+
readonly context: LogContext;
|
|
35
|
+
}
|
|
36
|
+
declare const level: {
|
|
37
|
+
/** A critical failure happened and the program must exit. */
|
|
38
|
+
readonly fatal: 60;
|
|
39
|
+
/** Something failed, but we can keep going. */
|
|
40
|
+
readonly error: 50;
|
|
41
|
+
/** Cause for concern, but we can keep going. */
|
|
42
|
+
readonly warn: 40;
|
|
43
|
+
/** High-level progress updates. */
|
|
44
|
+
readonly info: 30;
|
|
45
|
+
/** Verbose update about events or control flow (usually hidden). */
|
|
46
|
+
readonly debug: 20;
|
|
47
|
+
/** Extremely detailed progress updates (usually hidden). */
|
|
48
|
+
readonly trace: 10;
|
|
49
|
+
};
|
|
50
|
+
type LogLevel = (typeof level)[keyof typeof level];
|
|
51
|
+
type JsonPrimitive = string | number | boolean | null | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Any JSON-serializable value. Supports nested objects and arrays so log
|
|
54
|
+
* context can carry structured data.
|
|
55
|
+
*/
|
|
56
|
+
type JsonValue = JsonPrimitive | ReadonlyArray<JsonValue> | {
|
|
57
|
+
readonly [key: string]: JsonValue;
|
|
58
|
+
};
|
|
59
|
+
interface JsonContext {
|
|
60
|
+
[key: string]: JsonValue;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Custom values allowed in log context. These values don't have to be JSON.
|
|
64
|
+
* The most common case is errors, which support richer error tracking in
|
|
65
|
+
* backends that support it.
|
|
66
|
+
*
|
|
67
|
+
* This is part of the public API. Backends may use declaration merging to
|
|
68
|
+
* extend the standard attributes. It's recommended to use symbols as keys for
|
|
69
|
+
* custom features, but not required.
|
|
70
|
+
*/
|
|
71
|
+
interface CustomContext {
|
|
72
|
+
/**
|
|
73
|
+
* Error instance associated with the log message. This supports error
|
|
74
|
+
* tracking and shows prominently in visual backends like TTY output.
|
|
75
|
+
*/
|
|
76
|
+
error: Error;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A type narrowing constraint designed for generic constraints. Controls
|
|
80
|
+
* what fields are allowed in `log.context`, sourcing from `CustomContext`
|
|
81
|
+
* first, then falling back to any JSON value.
|
|
82
|
+
*/
|
|
83
|
+
type StrictContext<Input> = { [Key in keyof Input]: Key extends keyof CustomContext ? CustomContext[Key] : JsonValue; };
|
|
84
|
+
/**
|
|
85
|
+
* A more general type expected by logging backends. Supports type narrowing,
|
|
86
|
+
* so if a known field exists, it will be used instead of the generic JSON
|
|
87
|
+
* type.
|
|
88
|
+
*/
|
|
89
|
+
type LogContext = Partial<CustomContext> & JsonContext;
|
|
90
|
+
/**
|
|
91
|
+
* This is the public API which generates and sends `Log` events through the
|
|
92
|
+
* user-defined processing pipeline.
|
|
93
|
+
*/
|
|
94
|
+
interface Logger {
|
|
95
|
+
readonly owner: ReadonlyArray<string>;
|
|
96
|
+
/** Extend the logger to attach a class or module name to logs. */
|
|
97
|
+
namespace: (owner: string) => Logger;
|
|
98
|
+
/**
|
|
99
|
+
* Create a new logger which runs all logs through a middleware function.
|
|
100
|
+
* Useful for adding default context, doing ad-hoc filtering, or
|
|
101
|
+
* registering plugins. Only applies to this logger and its descendants.
|
|
102
|
+
*/
|
|
103
|
+
withMiddleware: (middleware: (next: LogProcessor) => LogProcessor) => Logger;
|
|
104
|
+
/** Log a verbose and frequent update. */
|
|
105
|
+
trace: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
106
|
+
/** Log a frequent and verbose progress update. */
|
|
107
|
+
debug: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
108
|
+
/** Log a high-level progress update. */
|
|
109
|
+
info: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
110
|
+
/** Log something concerning. */
|
|
111
|
+
warn: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
112
|
+
/** Log a failure. */
|
|
113
|
+
error: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
114
|
+
/** Log a catastrophic failure. */
|
|
115
|
+
fatal: <Context extends StrictContext<Context>>(message: string, context?: Context) => void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Combine several log processors into a single log processor. Each one is
|
|
119
|
+
* called in sequence. Useful for sending a single log to multiple log
|
|
120
|
+
* destinations.
|
|
121
|
+
*/
|
|
122
|
+
declare const combine: (processors: Array<LogProcessor>) => LogProcessor;
|
|
123
|
+
/**
|
|
124
|
+
* Filter logs based on a filter function. If the function returns true, the
|
|
125
|
+
* log is kept and forwarded onto the next processor, otherwise it is
|
|
126
|
+
* discarded.
|
|
127
|
+
*
|
|
128
|
+
* @param predicate Returns `true` to forward the log.
|
|
129
|
+
* @param processor Where to send the log if it passes the filter.
|
|
130
|
+
*/
|
|
131
|
+
declare const filter: (predicate: (log: Log) => boolean, processor: LogProcessor) => LogProcessor;
|
|
132
|
+
export { LogContext as a, Logger as c, Log as i, level as l, combine as n, LogLevel as o, CustomContext as r, LogProcessor as s, filter as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holz/core",
|
|
3
|
-
"version": "0.10.1-rc.
|
|
3
|
+
"version": "0.10.1-rc.7.sha-a01a6d1",
|
|
4
4
|
"description": "A structured and composable logger",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"source": "./src/index.ts",
|
|
14
14
|
"types": "./dist/holz-core.d.ts",
|
|
15
15
|
"default": "./dist/holz-core.js"
|
|
16
|
+
},
|
|
17
|
+
"./functions": {
|
|
18
|
+
"source": "./src/functions/index.ts",
|
|
19
|
+
"types": "./dist/functions.d.ts",
|
|
20
|
+
"default": "./dist/functions.js"
|
|
16
21
|
}
|
|
17
22
|
},
|
|
18
23
|
"publishConfig": {
|
|
@@ -45,5 +50,5 @@
|
|
|
45
50
|
"vite": "^8.0.0",
|
|
46
51
|
"vitest": "^5.0.0"
|
|
47
52
|
},
|
|
48
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "a01a6d1c1041410bbad0df8f073894e27937cff4"
|
|
49
54
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Log, LogProcessor } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Combine several log processors into a single log processor. Each one is
|
|
5
|
+
* called in sequence. Useful for sending a single log to multiple log
|
|
6
|
+
* destinations.
|
|
7
|
+
*/
|
|
8
|
+
export const combine =
|
|
9
|
+
(processors: Array<LogProcessor>): LogProcessor =>
|
|
10
|
+
(log: Log) =>
|
|
11
|
+
processors.forEach((processor) => processor(log));
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import type { Log, LogProcessor } from '
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Combine several log processors into a single log processor. Each one is
|
|
5
|
-
* called in sequence. Useful for sending a single log to multiple log
|
|
6
|
-
* destinations.
|
|
7
|
-
*/
|
|
8
|
-
export const combine =
|
|
9
|
-
(processors: Array<LogProcessor>): LogProcessor =>
|
|
10
|
-
(log: Log) =>
|
|
11
|
-
processors.forEach((processor) => processor(log));
|
|
1
|
+
import type { Log, LogProcessor } from '../types';
|
|
12
2
|
|
|
13
3
|
/**
|
|
14
4
|
* Filter logs based on a filter function. If the function returns true, the
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { combine as combineFn, filter as filterFn } from './functions';
|
|
2
|
+
|
|
3
|
+
/** @deprecated Import from `@holz/core/functions` instead. */
|
|
4
|
+
export const combine: typeof combineFn = combineFn;
|
|
5
|
+
|
|
6
|
+
/** @deprecated Import from `@holz/core/functions` instead. */
|
|
7
|
+
export const filter: typeof filterFn = filterFn;
|
|
8
|
+
|
|
2
9
|
export { createLogger } from './logger';
|
|
3
10
|
export { level } from './types';
|
|
4
11
|
export type {
|