@thi.ng/rstream-log 4.1.101 → 5.0.1
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/CHANGELOG.md +18 -1
- package/README.md +22 -27
- package/api.d.ts +1 -10
- package/logger.d.ts +10 -17
- package/logger.js +25 -48
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-02-
|
|
3
|
+
- **Last updated**: 2024-02-16T20:48:02Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,23 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [5.0.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream-log@5.0.1) (2024-02-16)
|
|
13
|
+
|
|
14
|
+
#### 🩹 Bug fixes
|
|
15
|
+
|
|
16
|
+
- fix Logger.logEntry() & .childLogger() impls ([3484617](https://github.com/thi-ng/umbrella/commit/3484617))
|
|
17
|
+
|
|
18
|
+
# [5.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream-log@5.0.0) (2024-02-16)
|
|
19
|
+
|
|
20
|
+
#### 🛑 Breaking changes
|
|
21
|
+
|
|
22
|
+
- update Logger impl, remove obsolete types ([36c8649](https://github.com/thi-ng/umbrella/commit/36c8649))
|
|
23
|
+
- BREAKING CHANGE: update Logger, remove obsolete types
|
|
24
|
+
- Logger now a subclass of `ALogger` & implementing `ISubscriber` interface
|
|
25
|
+
- instead of extending rstream `StreamMerge`, now exposes a `Stream` via `.stream`
|
|
26
|
+
- adding child loggers now handled via `ILogger.childLogger()` or `ILogger.addChild()`
|
|
27
|
+
- update tests
|
|
28
|
+
|
|
12
29
|
### [4.1.84](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream-log@4.1.84) (2023-11-24)
|
|
13
30
|
|
|
14
31
|
#### 🩹 Bug fixes
|
package/README.md
CHANGED
|
@@ -44,10 +44,10 @@ infrastructure, with logged values transformable via
|
|
|
44
44
|
[@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers).
|
|
45
45
|
Several built-in transformers are provided.
|
|
46
46
|
|
|
47
|
-
The `Logger` class
|
|
48
|
-
[@thi.ng/
|
|
47
|
+
The `Logger` class in this package implements the
|
|
48
|
+
[@thi.ng/logger](https://github.com/thi-ng/umbrella/tree/develop/packages/logger)
|
|
49
49
|
`ILogger` interface and uses `LogLevel` enums to configure levels /
|
|
50
|
-
filtering.
|
|
50
|
+
filtering. See that package for more details.
|
|
51
51
|
|
|
52
52
|
## Status
|
|
53
53
|
|
|
@@ -61,7 +61,7 @@ filtering.
|
|
|
61
61
|
|
|
62
62
|
## Related packages
|
|
63
63
|
|
|
64
|
-
- [@thi.ng/logger](https://github.com/thi-ng/umbrella/tree/develop/packages/logger) -
|
|
64
|
+
- [@thi.ng/logger](https://github.com/thi-ng/umbrella/tree/develop/packages/logger) - Basis types for arbitrary & hierarchical logging
|
|
65
65
|
|
|
66
66
|
## Installation
|
|
67
67
|
|
|
@@ -83,13 +83,12 @@ For Node.js REPL:
|
|
|
83
83
|
const rstreamLog = await import("@thi.ng/rstream-log");
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
86
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 715 bytes
|
|
87
87
|
|
|
88
88
|
## Dependencies
|
|
89
89
|
|
|
90
90
|
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
91
91
|
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
92
|
-
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
|
|
93
92
|
- [@thi.ng/logger](https://github.com/thi-ng/umbrella/tree/develop/packages/logger)
|
|
94
93
|
- [@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/develop/packages/rstream)
|
|
95
94
|
- [@thi.ng/strings](https://github.com/thi-ng/umbrella/tree/develop/packages/strings)
|
|
@@ -99,42 +98,38 @@ Package sizes (brotli'd, pre-treeshake): ESM: 857 bytes
|
|
|
99
98
|
|
|
100
99
|
[Generated API docs](https://docs.thi.ng/umbrella/rstream-log/)
|
|
101
100
|
|
|
102
|
-
```ts
|
|
103
|
-
import { LogLevel } from "@thi.ng/
|
|
104
|
-
import
|
|
101
|
+
```ts tangle:export/readme.ts
|
|
102
|
+
import { LogLevel } from "@thi.ng/logger";
|
|
103
|
+
import { Logger, formatString, writeConsole } from "@thi.ng/rstream-log";
|
|
105
104
|
|
|
106
|
-
const logger = new
|
|
105
|
+
const logger = new Logger("main");
|
|
107
106
|
// or with min level
|
|
108
|
-
const logger = new
|
|
107
|
+
const logger = new Logger("main", LogLevel.DEBUG);
|
|
108
|
+
// or min level given as string
|
|
109
|
+
const logger = new Logger("main", "DEBUG");
|
|
109
110
|
|
|
110
111
|
// add console output w/ string formatter (a transducer)
|
|
111
|
-
logger
|
|
112
|
+
// each logger instance has a rstream Stream instance
|
|
113
|
+
// allowing for downstream processing
|
|
114
|
+
logger.stream.transform(formatString()).subscribe(writeConsole());
|
|
112
115
|
|
|
113
116
|
logger.debug("hello world");
|
|
114
|
-
// [DEBUG]
|
|
117
|
+
// [DEBUG] main: 2024-02-16T20:38:11.143Z hello world
|
|
115
118
|
|
|
116
119
|
logger.warn("eek");
|
|
117
|
-
// [WARN]
|
|
120
|
+
// [WARN] main: 2024-02-16T20:38:11.144Z eek
|
|
118
121
|
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const mod1 = new log.Logger("module-1", LogLevel.INFO);
|
|
123
|
-
// pipe mod1 into main logger
|
|
124
|
-
logger.add(mod1);
|
|
122
|
+
// loggers can form hierarchies by creating/attaching child loggers
|
|
123
|
+
const child = logger.childLogger("child", LogLevel.INFO);
|
|
125
124
|
|
|
126
125
|
import { postWorker } from "@thi.ng/rstream";
|
|
127
126
|
// additionally send messages from this logger to worker
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
mod1.info("hi from sub-module");
|
|
127
|
+
child.stream.subscribe(postWorker("log-worker.js"));
|
|
131
128
|
|
|
132
|
-
|
|
133
|
-
// [INFO]
|
|
129
|
+
child.info("hi from submodule");
|
|
130
|
+
// [INFO] child: 2024-02-16T20:38:11.145Z hi from submodule
|
|
134
131
|
```
|
|
135
132
|
|
|
136
|
-
TODO
|
|
137
|
-
|
|
138
133
|
## Authors
|
|
139
134
|
|
|
140
135
|
- [Karsten Schmidt](https://thi.ng)
|
package/api.d.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import type { IID } from "@thi.ng/api";
|
|
2
|
-
import type { ILogger as APILogger, LogLevel } from "@thi.ng/logger";
|
|
2
|
+
import type { ILogger as APILogger, LogEntry, LogLevel } from "@thi.ng/logger";
|
|
3
3
|
import type { ISubscribable } from "@thi.ng/rstream";
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated moved to thi.ng/logger package
|
|
6
|
-
*/
|
|
7
|
-
export interface LogEntry extends Array<any> {
|
|
8
|
-
[0]: LogLevel;
|
|
9
|
-
[1]: string;
|
|
10
|
-
[2]: number;
|
|
11
|
-
[id: number]: any;
|
|
12
|
-
}
|
|
13
4
|
export interface LogEntryObj extends IID<string> {
|
|
14
5
|
level: LogLevel;
|
|
15
6
|
time: number;
|
package/logger.d.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
constructor();
|
|
8
|
-
constructor(id: string);
|
|
9
|
-
constructor(id: string, level: LogLevel);
|
|
10
|
-
constructor(id: string, sources: Iterable<ISubscribable<LogEntry>>, level?: LogLevel);
|
|
11
|
-
enabled(level: LogLevel): boolean;
|
|
1
|
+
import { ALogger } from "@thi.ng/logger/alogger";
|
|
2
|
+
import { LogLevel, type ILogger, type LogEntry, type LogLevelName } from "@thi.ng/logger/api";
|
|
3
|
+
import { Stream, type ISubscriber } from "@thi.ng/rstream";
|
|
4
|
+
export declare class Logger extends ALogger implements ISubscriber<LogEntry> {
|
|
5
|
+
stream: Stream<LogEntry>;
|
|
6
|
+
constructor(id: string, level?: LogLevel | LogLevelName, parent?: ILogger);
|
|
12
7
|
next(x: LogEntry): void;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
severe(...args: any[]): void;
|
|
18
|
-
protected log(level: LogLevel, args: any[]): void;
|
|
8
|
+
done(): void;
|
|
9
|
+
error(e: Error): boolean;
|
|
10
|
+
logEntry(e: LogEntry): void;
|
|
11
|
+
childLogger(id: string, level?: LogLevel): Logger;
|
|
19
12
|
}
|
|
20
13
|
//# sourceMappingURL=logger.d.ts.map
|
package/logger.js
CHANGED
|
@@ -1,57 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
class Logger extends
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
break;
|
|
15
|
-
case 1:
|
|
16
|
-
id = args[0];
|
|
17
|
-
break;
|
|
18
|
-
case 2:
|
|
19
|
-
[id, level] = args;
|
|
20
|
-
break;
|
|
21
|
-
case 3:
|
|
22
|
-
[id, src, level] = args;
|
|
23
|
-
src = [...src];
|
|
24
|
-
break;
|
|
25
|
-
default:
|
|
26
|
-
illegalArity(args.length);
|
|
27
|
-
}
|
|
28
|
-
id = id || `logger-${__nextID()}`;
|
|
29
|
-
super({ src, id, closeIn: CloseMode.NEVER, closeOut: CloseMode.NEVER });
|
|
30
|
-
this.level = level;
|
|
31
|
-
}
|
|
32
|
-
enabled(level) {
|
|
33
|
-
return this.level <= level;
|
|
1
|
+
import { ALogger } from "@thi.ng/logger/alogger";
|
|
2
|
+
import {
|
|
3
|
+
LogLevel
|
|
4
|
+
} from "@thi.ng/logger/api";
|
|
5
|
+
import { CloseMode, Stream } from "@thi.ng/rstream";
|
|
6
|
+
class Logger extends ALogger {
|
|
7
|
+
stream;
|
|
8
|
+
constructor(id, level, parent) {
|
|
9
|
+
super(id, level, parent);
|
|
10
|
+
this.stream = new Stream({
|
|
11
|
+
id: this.id,
|
|
12
|
+
closeOut: CloseMode.NEVER
|
|
13
|
+
});
|
|
34
14
|
}
|
|
35
15
|
next(x) {
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
fine(...args) {
|
|
39
|
-
this.log(LogLevel.FINE, args);
|
|
16
|
+
this.logEntry(x);
|
|
40
17
|
}
|
|
41
|
-
|
|
42
|
-
this.
|
|
18
|
+
done() {
|
|
19
|
+
this.stream.done();
|
|
43
20
|
}
|
|
44
|
-
|
|
45
|
-
this.
|
|
21
|
+
error(e) {
|
|
22
|
+
return this.stream.error(e);
|
|
46
23
|
}
|
|
47
|
-
|
|
48
|
-
this.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
24
|
+
logEntry(e) {
|
|
25
|
+
if (e[0] >= this.level) {
|
|
26
|
+
this.stream.next(e);
|
|
27
|
+
this.parent && this.parent.logEntry(e);
|
|
28
|
+
}
|
|
52
29
|
}
|
|
53
|
-
|
|
54
|
-
|
|
30
|
+
childLogger(id, level) {
|
|
31
|
+
return new Logger(id, level ?? this.level, this);
|
|
55
32
|
}
|
|
56
33
|
}
|
|
57
34
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rstream-log",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Structured, multilevel & hierarchical loggers based on @thi.ng/rstream",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@thi.ng/api": "^8.9.23",
|
|
39
39
|
"@thi.ng/checks": "^3.4.23",
|
|
40
|
-
"@thi.ng/
|
|
41
|
-
"@thi.ng/
|
|
42
|
-
"@thi.ng/rstream": "^8.3.2",
|
|
40
|
+
"@thi.ng/logger": "^3.0.0",
|
|
41
|
+
"@thi.ng/rstream": "^8.3.3",
|
|
43
42
|
"@thi.ng/strings": "^3.7.14",
|
|
44
|
-
"@thi.ng/transducers": "^8.9.
|
|
43
|
+
"@thi.ng/transducers": "^8.9.2"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
46
|
"@microsoft/api-extractor": "^7.40.1",
|
|
@@ -98,5 +97,5 @@
|
|
|
98
97
|
],
|
|
99
98
|
"year": 2017
|
|
100
99
|
},
|
|
101
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "31173a8ccccdc296c104602d8d9db8b6553fd305\n"
|
|
102
101
|
}
|