@graphql-markdown/logger 1.0.10 → 1.1.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 +30 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,3 +5,33 @@
|
|
|
5
5
|
[](https://sonarcloud.io/summary/new_code?id=graphql-markdown_logger)
|
|
6
6
|
[](https://sonarcloud.io/summary/new_code?id=graphql-markdown_logger)
|
|
7
7
|
[](https://dashboard.stryker-mutator.io/reports/github.com/graphql-markdown/graphql-markdown/main?module=logger)
|
|
8
|
+
|
|
9
|
+
Singleton logger used across GraphQL-Markdown packages. Defaults to `console`, but can be pointed at any object exposing standard log-level methods (`debug`, `error`, `info`, `log`, `warn`) or a custom module such as `@docusaurus/logger`.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm install @graphql-markdown/logger
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import Logger, { log } from "@graphql-markdown/logger";
|
|
21
|
+
|
|
22
|
+
log("Info message"); // console output "Info message"
|
|
23
|
+
|
|
24
|
+
// Point the logger at a named module
|
|
25
|
+
await Logger("@docusaurus/logger");
|
|
26
|
+
log("Info message", "info"); // Docusaurus log output "Info message"
|
|
27
|
+
|
|
28
|
+
// Or a custom logger instance
|
|
29
|
+
await Logger({ info: (message) => process.stdout.write(message) });
|
|
30
|
+
log("Info message", "info"); // custom logger output "Info message"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
GraphQL-Markdown packages are 100% free and open-source, under the [MIT license](https://github.com/graphql-markdown/graphql-markdown/blob/main/LICENSE).
|
|
36
|
+
|
|
37
|
+
This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/graphql-markdown/graphql-markdown) to thank us for our work. By contributing to the Treeware forest, you'll be creating employment for local families and restoring wildlife habitats.
|
package/dist/index.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ declare const resolveLoggerInstance: (instance: unknown) => LoggerType["instance
|
|
|
49
49
|
* Instantiate a logger module.
|
|
50
50
|
* By default, the logger module uses `globalThis.console`
|
|
51
51
|
*
|
|
52
|
-
* @param moduleName - optional name of the logger package.
|
|
52
|
+
* @param moduleName - optional name of the logger package, or a logger instance to use directly.
|
|
53
53
|
*
|
|
54
54
|
* @example
|
|
55
55
|
* ```js
|
|
@@ -59,10 +59,13 @@ declare const resolveLoggerInstance: (instance: unknown) => LoggerType["instance
|
|
|
59
59
|
*
|
|
60
60
|
* Logger("@docusaurus/logger");
|
|
61
61
|
* log("Info message", "info"); // Expected Docusaurus log output "Info message"
|
|
62
|
+
*
|
|
63
|
+
* Logger({ info: (message) => process.stdout.write(message) }); // Logger instance
|
|
64
|
+
* log("Info message", "info"); // Expected custom logger output "Info message"
|
|
62
65
|
* ```
|
|
63
66
|
*
|
|
64
67
|
*/
|
|
65
|
-
export declare const Logger: (moduleName?: string) => Promise<void>;
|
|
68
|
+
export declare const Logger: (moduleName?: Record<string, unknown> | string) => Promise<void>;
|
|
66
69
|
/**
|
|
67
70
|
* Logs a message by calling the active logger instance.
|
|
68
71
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,oBAAY,QAAQ;IAClB,KAAK,UAAU;IACf,KAAK,UAA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AC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,GAAG,YACL,MAAM,UACR,QAAQ,GAAG,MAAM,OAAO,QAAQ,KACtC,IAGF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU;;;CAA0C,CAAC;AAElE;;GAEG;AACH,aAAa;eACE,MAAM"}
|
package/dist/index.js
CHANGED
|
@@ -75,7 +75,7 @@ const resolveLoggerInstance = (instance) => {
|
|
|
75
75
|
* Instantiate a logger module.
|
|
76
76
|
* By default, the logger module uses `globalThis.console`
|
|
77
77
|
*
|
|
78
|
-
* @param moduleName - optional name of the logger package.
|
|
78
|
+
* @param moduleName - optional name of the logger package, or a logger instance to use directly.
|
|
79
79
|
*
|
|
80
80
|
* @example
|
|
81
81
|
* ```js
|
|
@@ -85,6 +85,9 @@ const resolveLoggerInstance = (instance) => {
|
|
|
85
85
|
*
|
|
86
86
|
* Logger("@docusaurus/logger");
|
|
87
87
|
* log("Info message", "info"); // Expected Docusaurus log output "Info message"
|
|
88
|
+
*
|
|
89
|
+
* Logger({ info: (message) => process.stdout.write(message) }); // Logger instance
|
|
90
|
+
* log("Info message", "info"); // Expected custom logger output "Info message"
|
|
88
91
|
* ```
|
|
89
92
|
*
|
|
90
93
|
*/
|
|
@@ -92,9 +95,13 @@ const Logger = async (moduleName) => {
|
|
|
92
95
|
if (globalThis.logger?.instance && moduleName === undefined) {
|
|
93
96
|
return;
|
|
94
97
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
let moduleExports;
|
|
99
|
+
if (typeof moduleName === "string" && moduleName !== "") {
|
|
100
|
+
moduleExports = await import(moduleName);
|
|
101
|
+
}
|
|
102
|
+
else if (typeof moduleName === "object") {
|
|
103
|
+
moduleExports = moduleName;
|
|
104
|
+
}
|
|
98
105
|
const instance = resolveLoggerInstance(moduleExports) ??
|
|
99
106
|
resolveLoggerInstance(moduleExports?.default) ??
|
|
100
107
|
globalThis.console;
|