@logtape/logtape 0.4.0-dev.33 → 0.4.0
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 +15 -3
- package/esm/logger.js +8 -2
- package/package.json +1 -1
- package/script/logger.js +31 -2
- package/types/logger.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ sinks.](#sinks)
|
|
|
47
47
|

|
|
48
48
|
|
|
49
49
|
[JSR]: https://jsr.io/@logtape/logtape
|
|
50
|
-
[JSR badge]: https://jsr.io/badges/@logtape/logtape
|
|
50
|
+
[JSR badge]: https://jsr.io/badges/@logtape/logtape
|
|
51
51
|
[npm]: https://www.npmjs.com/package/@logtape/logtape
|
|
52
52
|
[npm badge]: https://img.shields.io/npm/v/@logtape/logtape?logo=npm
|
|
53
53
|
[GitHub Actions]: https://github.com/dahlia/logtape/actions/workflows/main.yaml
|
|
@@ -352,12 +352,13 @@ text formatter is:
|
|
|
352
352
|
export type TextFormatter = (record: LogRecord) => string;
|
|
353
353
|
~~~~
|
|
354
354
|
|
|
355
|
-
Here's an example of a text formatter that writes log messages in a JSON
|
|
355
|
+
Here's an example of a text formatter that writes log messages in a [JSON Lines]
|
|
356
|
+
format:
|
|
356
357
|
|
|
357
358
|
~~~~ typescript
|
|
358
359
|
await configure({
|
|
359
360
|
sinks: {
|
|
360
|
-
stream:
|
|
361
|
+
stream: getFileSink("log.jsonl", {
|
|
361
362
|
formatter(log) {
|
|
362
363
|
return JSON.stringify(log) + "\n",
|
|
363
364
|
}
|
|
@@ -367,6 +368,17 @@ await configure({
|
|
|
367
368
|
})
|
|
368
369
|
~~~~
|
|
369
370
|
|
|
371
|
+
> [!TIP]
|
|
372
|
+
> If you want to monitor log messages formatted in JSON Lines in real-time
|
|
373
|
+
> readably, you can utilize the `tail` and [`jq`] commands:
|
|
374
|
+
>
|
|
375
|
+
> ~~~~ sh
|
|
376
|
+
> tail -f log.jsonl | jq .
|
|
377
|
+
> ~~~~
|
|
378
|
+
|
|
379
|
+
[JSON Lines]: https://jsonlines.org/
|
|
380
|
+
[`jq`]: https://jqlang.github.io/jq/
|
|
381
|
+
|
|
370
382
|
### Disposable sink
|
|
371
383
|
|
|
372
384
|
> [!TIP]
|
package/esm/logger.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as dntShim from "./_dnt.shims.js";
|
|
1
2
|
/**
|
|
2
3
|
* Get a logger with the given category.
|
|
3
4
|
*
|
|
@@ -14,17 +15,22 @@ export function getLogger(category = []) {
|
|
|
14
15
|
return LoggerImpl.getLogger(category);
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
|
-
* The root logger.
|
|
18
|
+
* The symbol for the global root logger.
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
const globalRootLoggerSymbol = Symbol.for("logtape.rootLogger");
|
|
20
21
|
/**
|
|
21
22
|
* A logger implementation. Do not use this directly; use {@link getLogger}
|
|
22
23
|
* instead. This class is exported for testing purposes.
|
|
23
24
|
*/
|
|
24
25
|
export class LoggerImpl {
|
|
25
26
|
static getLogger(category = []) {
|
|
27
|
+
let rootLogger = globalRootLoggerSymbol in dntShim.dntGlobalThis
|
|
28
|
+
? dntShim.dntGlobalThis[globalRootLoggerSymbol] ?? null
|
|
29
|
+
: null;
|
|
26
30
|
if (rootLogger == null) {
|
|
27
31
|
rootLogger = new LoggerImpl(null, []);
|
|
32
|
+
dntShim.dntGlobalThis[globalRootLoggerSymbol] =
|
|
33
|
+
rootLogger;
|
|
28
34
|
}
|
|
29
35
|
if (typeof category === "string")
|
|
30
36
|
return rootLogger.getChild(category);
|
package/package.json
CHANGED
package/script/logger.js
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.renderMessage = exports.parseMessageTemplate = exports.LoggerImpl = exports.getLogger = void 0;
|
|
27
|
+
const dntShim = __importStar(require("./_dnt.shims.js"));
|
|
4
28
|
/**
|
|
5
29
|
* Get a logger with the given category.
|
|
6
30
|
*
|
|
@@ -18,17 +42,22 @@ function getLogger(category = []) {
|
|
|
18
42
|
}
|
|
19
43
|
exports.getLogger = getLogger;
|
|
20
44
|
/**
|
|
21
|
-
* The root logger.
|
|
45
|
+
* The symbol for the global root logger.
|
|
22
46
|
*/
|
|
23
|
-
|
|
47
|
+
const globalRootLoggerSymbol = Symbol.for("logtape.rootLogger");
|
|
24
48
|
/**
|
|
25
49
|
* A logger implementation. Do not use this directly; use {@link getLogger}
|
|
26
50
|
* instead. This class is exported for testing purposes.
|
|
27
51
|
*/
|
|
28
52
|
class LoggerImpl {
|
|
29
53
|
static getLogger(category = []) {
|
|
54
|
+
let rootLogger = globalRootLoggerSymbol in dntShim.dntGlobalThis
|
|
55
|
+
? dntShim.dntGlobalThis[globalRootLoggerSymbol] ?? null
|
|
56
|
+
: null;
|
|
30
57
|
if (rootLogger == null) {
|
|
31
58
|
rootLogger = new LoggerImpl(null, []);
|
|
59
|
+
dntShim.dntGlobalThis[globalRootLoggerSymbol] =
|
|
60
|
+
rootLogger;
|
|
32
61
|
}
|
|
33
62
|
if (typeof category === "string")
|
|
34
63
|
return rootLogger.getChild(category);
|
package/types/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAErC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,CACN,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,GACvE,MAAM,CAAC;IAEV;;;;;;;;;OASG;IACH,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI,CAAC;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