@logtape/logtape 0.2.0 → 0.2.2
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 +30 -5
- package/esm/config.js +8 -0
- package/package.json +1 -1
- package/script/config.js +8 -0
- package/types/config.d.ts.map +1 -1
- package/types/mod.d.ts +1 -1
- package/types/mod.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -12,9 +12,33 @@ LogTape
|
|
|
12
12
|
> LogTape is still in the early stage of development. The API is not stable
|
|
13
13
|
> yet. Please be careful when using it in production.
|
|
14
14
|
|
|
15
|
-
LogTape is a
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
LogTape is a logging library for JavaScript and TypeScript. It provides a
|
|
16
|
+
simple and flexible logging system that is easy to use and easy to extend.
|
|
17
|
+
The highlights of LogTape are:
|
|
18
|
+
|
|
19
|
+
- *Zero dependencies*: LogTape has zero dependencies. You can use LogTape
|
|
20
|
+
without worrying about the dependencies of LogTape.
|
|
21
|
+
|
|
22
|
+
- *Library support*: LogTape is designed to be used in libraries as well
|
|
23
|
+
as applications. You can use LogTape in libraries to provide logging
|
|
24
|
+
capabilities to users of the libraries.
|
|
25
|
+
|
|
26
|
+
- *Runtime diversity*: LogTape supports Deno, Node.js, Bun, edge functions,
|
|
27
|
+
and browsers. You can use LogTape in various environments without
|
|
28
|
+
changing the code.
|
|
29
|
+
|
|
30
|
+
- *Structured logging*: You can log messages with structured data.
|
|
31
|
+
|
|
32
|
+
- *Hierarchical categories*: LogTape uses a hierarchical category system
|
|
33
|
+
to manage loggers. You can control the verbosity of log messages by
|
|
34
|
+
setting the log level of loggers at different levels of the category
|
|
35
|
+
hierarchy.
|
|
36
|
+
|
|
37
|
+
- *Template literals*: LogTape supports template literals for log messages.
|
|
38
|
+
You can use template literals to log messages with placeholders and
|
|
39
|
+
values.
|
|
40
|
+
|
|
41
|
+
- *Dead simple sinks*: You can easily add your own sinks to LogTape.
|
|
18
42
|
|
|
19
43
|
Currently, LogTape provides only few sinks, but [you can easily add your own
|
|
20
44
|
sinks.](#sinks)
|
|
@@ -23,7 +47,7 @@ sinks.](#sinks)
|
|
|
23
47
|

|
|
24
48
|
|
|
25
49
|
[JSR]: https://jsr.io/@logtape/logtape
|
|
26
|
-
[JSR badge]: https://jsr.io/badges/@logtape/logtape?v=0.2.
|
|
50
|
+
[JSR badge]: https://jsr.io/badges/@logtape/logtape?v=0.2.1
|
|
27
51
|
[npm]: https://www.npmjs.com/package/@logtape/logtape
|
|
28
52
|
[npm badge]: https://img.shields.io/npm/v/@logtape/logtape?logo=npm
|
|
29
53
|
[GitHub Actions]: https://github.com/dahlia/logtape/actions/workflows/main.yaml
|
|
@@ -100,7 +124,8 @@ logger.error `This is an error message with ${value}.`;
|
|
|
100
124
|
logger.fatal `This is a fatal message with ${value}.`;
|
|
101
125
|
~~~~
|
|
102
126
|
|
|
103
|
-
You can also log messages with a function call
|
|
127
|
+
You can also log messages with a function call. In this case, log messages
|
|
128
|
+
are structured data:
|
|
104
129
|
|
|
105
130
|
~~~~ typescript
|
|
106
131
|
logger.debug("This is a debug message with {value}.", { value });
|
package/esm/config.js
CHANGED
|
@@ -6,6 +6,12 @@ import { getConsoleSink } from "./sink.js";
|
|
|
6
6
|
* Whether the loggers are configured.
|
|
7
7
|
*/
|
|
8
8
|
let configured = false;
|
|
9
|
+
/**
|
|
10
|
+
* Strong references to the loggers.
|
|
11
|
+
* This is to prevent the loggers from being garbage collected so that their
|
|
12
|
+
* sinks and filters are not removed.
|
|
13
|
+
*/
|
|
14
|
+
const strongRefs = new Set();
|
|
9
15
|
/**
|
|
10
16
|
* Disposables to dispose when resetting the configuration.
|
|
11
17
|
*/
|
|
@@ -87,6 +93,7 @@ export async function configure(config) {
|
|
|
87
93
|
}
|
|
88
94
|
logger.filters.push(toFilter(filter));
|
|
89
95
|
}
|
|
96
|
+
strongRefs.add(logger);
|
|
90
97
|
}
|
|
91
98
|
for (const sink of Object.values(config.sinks)) {
|
|
92
99
|
if (Symbol.asyncDispose in sink) {
|
|
@@ -129,6 +136,7 @@ export async function configure(config) {
|
|
|
129
136
|
export async function reset() {
|
|
130
137
|
await dispose();
|
|
131
138
|
LoggerImpl.getLogger([]).resetDescendants();
|
|
139
|
+
strongRefs.clear();
|
|
132
140
|
configured = false;
|
|
133
141
|
}
|
|
134
142
|
/**
|
package/package.json
CHANGED
package/script/config.js
CHANGED
|
@@ -32,6 +32,12 @@ const sink_js_1 = require("./sink.js");
|
|
|
32
32
|
* Whether the loggers are configured.
|
|
33
33
|
*/
|
|
34
34
|
let configured = false;
|
|
35
|
+
/**
|
|
36
|
+
* Strong references to the loggers.
|
|
37
|
+
* This is to prevent the loggers from being garbage collected so that their
|
|
38
|
+
* sinks and filters are not removed.
|
|
39
|
+
*/
|
|
40
|
+
const strongRefs = new Set();
|
|
35
41
|
/**
|
|
36
42
|
* Disposables to dispose when resetting the configuration.
|
|
37
43
|
*/
|
|
@@ -113,6 +119,7 @@ async function configure(config) {
|
|
|
113
119
|
}
|
|
114
120
|
logger.filters.push((0, filter_js_1.toFilter)(filter));
|
|
115
121
|
}
|
|
122
|
+
strongRefs.add(logger);
|
|
116
123
|
}
|
|
117
124
|
for (const sink of Object.values(config.sinks)) {
|
|
118
125
|
if (Symbol.asyncDispose in sink) {
|
|
@@ -156,6 +163,7 @@ exports.configure = configure;
|
|
|
156
163
|
async function reset() {
|
|
157
164
|
await dispose();
|
|
158
165
|
logger_js_1.LoggerImpl.getLogger([]).resetDescendants();
|
|
166
|
+
strongRefs.clear();
|
|
159
167
|
configured = false;
|
|
160
168
|
}
|
|
161
169
|
exports.reset = reset;
|
package/types/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,C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C;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;IAE5C;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAC3B,OAAO,SAAS,MAAM,EACtB,SAAS,SAAS,MAAM;IAExB;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE5B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IAEtB;;;OAGG;IACH,KAAK,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;CACzB;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,SAAS,CAC7B,OAAO,SAAS,MAAM,EACtB,SAAS,SAAS,MAAM,EACxB,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA+EnD;AAED;;GAEG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAK3C;AAED;;GAEG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAS7C;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;;;OAGG;gBACS,OAAO,EAAE,MAAM;CAI5B"}
|
package/types/mod.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { type Filter, type FilterLike, getLevelFilter, toFilter, } from "./filte
|
|
|
4
4
|
export { type ConsoleFormatter, defaultConsoleFormatter, defaultTextFormatter, type TextFormatter, } from "./formatter.js";
|
|
5
5
|
export { getLogger, type Logger } from "./logger.js";
|
|
6
6
|
export type { LogLevel, LogRecord } from "./record.js";
|
|
7
|
-
export { type ConsoleSinkOptions, type
|
|
7
|
+
export { type ConsoleSinkOptions, type FileSinkOptions, getConsoleSink, getStreamSink, type RotatingFileSinkOptions, type Sink, type StreamSinkOptions, } from "./sink.js";
|
|
8
8
|
//# sourceMappingURL=mod.d.ts.map
|
package/types/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,WAAW,EACX,SAAS,EACT,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,GACN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,cAAc,EACd,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,WAAW,EACX,SAAS,EACT,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,GACN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,cAAc,EACd,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS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