@genesislcap/foundation-logger 15.50.3 → 15.51.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/README.md +25 -0
- package/dist/dts/global-reporters.d.ts +37 -0
- package/dist/dts/global-reporters.d.ts.map +1 -0
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/logger.d.ts +1 -0
- package/dist/dts/logger.d.ts.map +1 -1
- package/dist/esm/global-reporters.js +145 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/logger.js +15 -4
- package/dist/foundation-logger.api.json +46 -0
- package/dist/foundation-logger.d.ts +31 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,31 @@ import { createLogger, TimestampBrowserReporter } from '@genesislcap/foundation-
|
|
|
37
37
|
createLogger('node-side', { reporters: [new TimestampBrowserReporter()] });
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
## Global log reporters
|
|
41
|
+
|
|
42
|
+
Genesis packages (`foundation-comms`, `foundation-state-machine`, etc.) report messages through their own `createLogger()` instances created at import time. Register a global reporter to observe logs from all foundation loggers across the application, including loggers instantiated before registration and loggers created by Module Federation remotes:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { addGlobalLogReporter } from '@genesislcap/foundation-logger';
|
|
46
|
+
|
|
47
|
+
const unsubscribe = addGlobalLogReporter({
|
|
48
|
+
log: ({ type, tag, args }) => {
|
|
49
|
+
if (type !== 'error') return;
|
|
50
|
+
const error = args.find((a) => a instanceof Error);
|
|
51
|
+
error
|
|
52
|
+
? Sentry.captureException(error, { tags: { logger: tag } })
|
|
53
|
+
: Sentry.captureMessage(`${tag}: ${String(args[0])}`, { level: 'error' });
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Remove the reporter when no longer needed:
|
|
58
|
+
unsubscribe();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Logged arguments can hold credentials or personal and business data, so avoid forwarding them to a third-party service. `setupErrorMonitoring` from `@genesislcap/foundation-utils` wires this up and sends only log messages and exceptions.
|
|
62
|
+
|
|
63
|
+
The reporter registry is stored on `globalThis` via `Symbol.for`, so one registration covers every runtime copy of this package that uses the same registry version. A copy built against an older registry shape keeps its own registry rather than breaking this one. Child loggers (`withTag`, `withScope`, `withDefaults`, `create`) are covered too. A reporter that throws is reported on the console instead of breaking the log call, and a logger created with the reporter in its own `reporters` keeps it after unsubscribing.
|
|
64
|
+
|
|
40
65
|
## Installation
|
|
41
66
|
|
|
42
67
|
Add the package to your `package.json` dependencies. After changing dependencies, run `npm run bootstrap` (or your project's equivalent). See [package.json basics](https://learn.genesis.global/secure/web/basics/package-json-basics/) for more information.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ConsolaInstance, ConsolaReporter } from 'consola/core';
|
|
2
|
+
/**
|
|
3
|
+
* Registers a logger instance with the global registry so it receives any currently
|
|
4
|
+
* active and future global log reporters.
|
|
5
|
+
*
|
|
6
|
+
* @param logger - The logger instance to register.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerLogger(logger: ConsolaInstance): void;
|
|
10
|
+
/**
|
|
11
|
+
* Registers a reporter that receives every log from every foundation logger, including loggers
|
|
12
|
+
* created before this call. Returns an unsubscribe function.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* An error thrown by the reporter is written to the console instead of propagating out of the
|
|
16
|
+
* log call. Loggers that were created with the reporter keep it after unsubscribing.
|
|
17
|
+
*
|
|
18
|
+
* @example Register an error monitor.
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { addGlobalLogReporter } from '@genesislcap/foundation-logger';
|
|
21
|
+
*
|
|
22
|
+
* const unsubscribe = addGlobalLogReporter({
|
|
23
|
+
* log: ({ type, tag, args }) => {
|
|
24
|
+
* if (type !== 'error') return;
|
|
25
|
+
* const error = args.find((a) => a instanceof Error);
|
|
26
|
+
* error ? Sentry.captureException(error, { tags: { logger: tag } })
|
|
27
|
+
* : Sentry.captureMessage(`${tag}: ${String(args[0])}`, { level: 'error' });
|
|
28
|
+
* },
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param reporter - The Consola reporter to register globally.
|
|
33
|
+
* @returns An unsubscribe function that removes the reporter from all loggers.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare function addGlobalLogReporter(reporter: ConsolaReporter): () => void;
|
|
37
|
+
//# sourceMappingURL=global-reporters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-reporters.d.ts","sourceRoot":"","sources":["../../src/global-reporters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AA8GrE;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAS5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI,CA+B1E"}
|
package/dist/dts/index.d.ts
CHANGED
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,8BAA8B,CAAC"}
|
package/dist/dts/logger.d.ts
CHANGED
package/dist/dts/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,cAAc,EAGf,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,cAAc,EAGf,MAAM,cAAc,CAAC;AAKtB;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAc,SAAQ,OAAO,CAAC,cAAc,CAAC;IAC5D;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C;;;;;;;;;;;;;;;;;;;OAmBG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvF;AAED;;;GAGG;AACH,MAAM,WAAW,MAAO,SAAQ,eAAe;CAAG;AAElD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAKlC,CAAC;AA8CF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAM9E"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared across every copy of this module (including Module Federation remotes that
|
|
3
|
+
* bundled their own `@genesislcap/foundation-logger`). Storing on `globalThis` via
|
|
4
|
+
* `Symbol.for` ensures that reporters registered in one copy receive logs from loggers
|
|
5
|
+
* created in any other copy. The version suffix changes whenever the stored shapes do, so a
|
|
6
|
+
* copy built against another shape keeps its own registry instead of misreading this one.
|
|
7
|
+
*/
|
|
8
|
+
const GLOBAL_REPORTERS_KEY = Symbol.for('@genesislcap/foundation-logger:global-reporters:v2');
|
|
9
|
+
const GLOBAL_LOGGERS_KEY = Symbol.for('@genesislcap/foundation-logger:global-loggers:v2');
|
|
10
|
+
const MIN_PRUNE_SIZE = 1024;
|
|
11
|
+
function createLoggerRef(logger) {
|
|
12
|
+
return typeof WeakRef !== 'undefined' ? new WeakRef(logger) : { deref: () => logger };
|
|
13
|
+
}
|
|
14
|
+
let pruneAtSize = MIN_PRUNE_SIZE;
|
|
15
|
+
function getGlobalReporters() {
|
|
16
|
+
let reporters = Reflect.get(globalThis, GLOBAL_REPORTERS_KEY);
|
|
17
|
+
if (!(reporters instanceof Map)) {
|
|
18
|
+
reporters = new Map();
|
|
19
|
+
Reflect.set(globalThis, GLOBAL_REPORTERS_KEY, reporters);
|
|
20
|
+
}
|
|
21
|
+
return reporters;
|
|
22
|
+
}
|
|
23
|
+
function getGlobalLoggerRefs() {
|
|
24
|
+
let refs = Reflect.get(globalThis, GLOBAL_LOGGERS_KEY);
|
|
25
|
+
if (!(refs instanceof Set)) {
|
|
26
|
+
refs = new Set();
|
|
27
|
+
Reflect.set(globalThis, GLOBAL_LOGGERS_KEY, refs);
|
|
28
|
+
}
|
|
29
|
+
return refs;
|
|
30
|
+
}
|
|
31
|
+
function isRegistration(value) {
|
|
32
|
+
var _a;
|
|
33
|
+
const registration = value;
|
|
34
|
+
return typeof (registration === null || registration === void 0 ? void 0 : registration.count) === 'number' && typeof ((_a = registration.guarded) === null || _a === void 0 ? void 0 : _a.log) === 'function';
|
|
35
|
+
}
|
|
36
|
+
function guardReporter(reporter) {
|
|
37
|
+
return {
|
|
38
|
+
log: (logObj, ctx) => {
|
|
39
|
+
try {
|
|
40
|
+
reporter.log(logObj, ctx);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
// The unwrapped console, so a consola that has wrapped `console` can't loop back here.
|
|
44
|
+
const { __error, error: consoleError } = console;
|
|
45
|
+
(__error || consoleError)('A global log reporter threw', error);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function attachReporter(logger, reporter, { guarded }) {
|
|
51
|
+
const { reporters } = logger.options;
|
|
52
|
+
if (!reporters.includes(reporter) && !reporters.includes(guarded)) {
|
|
53
|
+
logger.addReporter(guarded);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function forEachLiveLogger(refs, callback) {
|
|
57
|
+
for (const ref of refs) {
|
|
58
|
+
const logger = ref.deref();
|
|
59
|
+
if (logger) {
|
|
60
|
+
callback(logger);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
refs.delete(ref);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function pruneDeadLoggerRefs(refs) {
|
|
68
|
+
if (refs.size < pruneAtSize) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
forEachLiveLogger(refs, () => { });
|
|
72
|
+
pruneAtSize = Math.max(MIN_PRUNE_SIZE, refs.size * 2);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Registers a logger instance with the global registry so it receives any currently
|
|
76
|
+
* active and future global log reporters.
|
|
77
|
+
*
|
|
78
|
+
* @param logger - The logger instance to register.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
export function registerLogger(logger) {
|
|
82
|
+
const refs = getGlobalLoggerRefs();
|
|
83
|
+
refs.add(createLoggerRef(logger));
|
|
84
|
+
pruneDeadLoggerRefs(refs);
|
|
85
|
+
for (const [reporter, registration] of getGlobalReporters()) {
|
|
86
|
+
if (isRegistration(registration)) {
|
|
87
|
+
attachReporter(logger, reporter, registration);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Registers a reporter that receives every log from every foundation logger, including loggers
|
|
93
|
+
* created before this call. Returns an unsubscribe function.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* An error thrown by the reporter is written to the console instead of propagating out of the
|
|
97
|
+
* log call. Loggers that were created with the reporter keep it after unsubscribing.
|
|
98
|
+
*
|
|
99
|
+
* @example Register an error monitor.
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { addGlobalLogReporter } from '@genesislcap/foundation-logger';
|
|
102
|
+
*
|
|
103
|
+
* const unsubscribe = addGlobalLogReporter({
|
|
104
|
+
* log: ({ type, tag, args }) => {
|
|
105
|
+
* if (type !== 'error') return;
|
|
106
|
+
* const error = args.find((a) => a instanceof Error);
|
|
107
|
+
* error ? Sentry.captureException(error, { tags: { logger: tag } })
|
|
108
|
+
* : Sentry.captureMessage(`${tag}: ${String(args[0])}`, { level: 'error' });
|
|
109
|
+
* },
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param reporter - The Consola reporter to register globally.
|
|
114
|
+
* @returns An unsubscribe function that removes the reporter from all loggers.
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export function addGlobalLogReporter(reporter) {
|
|
118
|
+
if (!reporter || typeof reporter.log !== 'function') {
|
|
119
|
+
return () => { };
|
|
120
|
+
}
|
|
121
|
+
const reporters = getGlobalReporters();
|
|
122
|
+
const refs = getGlobalLoggerRefs();
|
|
123
|
+
const existing = reporters.get(reporter);
|
|
124
|
+
const registration = isRegistration(existing)
|
|
125
|
+
? existing
|
|
126
|
+
: { count: 0, guarded: guardReporter(reporter) };
|
|
127
|
+
registration.count += 1;
|
|
128
|
+
if (registration.count === 1) {
|
|
129
|
+
reporters.set(reporter, registration);
|
|
130
|
+
forEachLiveLogger(refs, (logger) => attachReporter(logger, reporter, registration));
|
|
131
|
+
}
|
|
132
|
+
let active = true;
|
|
133
|
+
return () => {
|
|
134
|
+
if (!active) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
active = false;
|
|
138
|
+
registration.count -= 1;
|
|
139
|
+
if (registration.count > 0) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
reporters.delete(reporter);
|
|
143
|
+
forEachLiveLogger(refs, (logger) => logger.removeReporter(registration.guarded));
|
|
144
|
+
};
|
|
145
|
+
}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/logger.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createConsola as createConsolaBrowser } from 'consola/browser';
|
|
2
2
|
import { LogLevels, createConsola as createConsolaCore, } from 'consola/core';
|
|
3
|
+
import { registerLogger } from './global-reporters';
|
|
3
4
|
import { TimestampBrowserReporter } from './timestamp-browser-reporter';
|
|
4
5
|
/**
|
|
5
6
|
* Used to set the logging level.
|
|
@@ -45,6 +46,19 @@ function resolveLoggerOptions(options, isBrowser) {
|
|
|
45
46
|
}
|
|
46
47
|
return resolved;
|
|
47
48
|
}
|
|
49
|
+
function attachDeprecated(logger) {
|
|
50
|
+
logger.deprecated = (symbol, instruction = 'Consult docs for better alternative.', removalVersionTarget) => {
|
|
51
|
+
logger.warn(`Deprecated symbol used '${symbol}'. ${instruction}`, `${removalVersionTarget ? `Will be removed in version ${removalVersionTarget}.` : ''}`);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function configureLogger(logger) {
|
|
55
|
+
attachDeprecated(logger);
|
|
56
|
+
const createChild = logger.create.bind(logger);
|
|
57
|
+
// consola's withTag, withScope and withDefaults all build their child through `this.create`.
|
|
58
|
+
logger.create = (options) => configureLogger(createChild(options));
|
|
59
|
+
registerLogger(logger);
|
|
60
|
+
return logger;
|
|
61
|
+
}
|
|
48
62
|
/**
|
|
49
63
|
* Creates a logger with the given name and options.
|
|
50
64
|
*
|
|
@@ -88,8 +102,5 @@ export function createLogger(name, options = {}) {
|
|
|
88
102
|
const createConsola = isBrowser ? createConsolaBrowser : createConsolaCore;
|
|
89
103
|
const logger = createConsola(resolveLoggerOptions(options, isBrowser)).withTag(name);
|
|
90
104
|
const typedLogger = logger;
|
|
91
|
-
|
|
92
|
-
typedLogger.warn(`Deprecated symbol used '${symbol}'. ${instruction}`, `${removalVersionTarget ? `Will be removed in version ${removalVersionTarget}.` : ''}`);
|
|
93
|
-
};
|
|
94
|
-
return typedLogger;
|
|
105
|
+
return configureLogger(typedLogger);
|
|
95
106
|
}
|
|
@@ -172,6 +172,52 @@
|
|
|
172
172
|
"name": "",
|
|
173
173
|
"preserveMemberOrder": false,
|
|
174
174
|
"members": [
|
|
175
|
+
{
|
|
176
|
+
"kind": "Function",
|
|
177
|
+
"canonicalReference": "@genesislcap/foundation-logger!addGlobalLogReporter:function(1)",
|
|
178
|
+
"docComment": "/**\n * Registers a reporter that receives every log from every foundation logger, including loggers created before this call. Returns an unsubscribe function.\n *\n * @remarks\n *\n * An error thrown by the reporter is written to the console instead of propagating out of the log call. Loggers that were created with the reporter keep it after unsubscribing.\n *\n * @param reporter - The Consola reporter to register globally.\n *\n * @returns An unsubscribe function that removes the reporter from all loggers.\n *\n * @example\n *\n * Register an error monitor.\n * ```ts\n * import { addGlobalLogReporter } from '@genesislcap/foundation-logger';\n *\n * const unsubscribe = addGlobalLogReporter({\n * log: ({ type, tag, args }) => {\n * if (type !== 'error') return;\n * const error = args.find((a) => a instanceof Error);\n * error ? Sentry.captureException(error, { tags: { logger: tag } })\n * : Sentry.captureMessage(`${tag}: ${String(args[0])}`, { level: 'error' });\n * },\n * });\n * ```\n *\n * @public\n */\n",
|
|
179
|
+
"excerptTokens": [
|
|
180
|
+
{
|
|
181
|
+
"kind": "Content",
|
|
182
|
+
"text": "export declare function addGlobalLogReporter(reporter: "
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"kind": "Reference",
|
|
186
|
+
"text": "ConsolaReporter",
|
|
187
|
+
"canonicalReference": "consola!ConsolaReporter:interface"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"kind": "Content",
|
|
191
|
+
"text": "): "
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"kind": "Content",
|
|
195
|
+
"text": "() => void"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"kind": "Content",
|
|
199
|
+
"text": ";"
|
|
200
|
+
}
|
|
201
|
+
],
|
|
202
|
+
"fileUrlPath": "src/global-reporters.ts",
|
|
203
|
+
"returnTypeTokenRange": {
|
|
204
|
+
"startIndex": 3,
|
|
205
|
+
"endIndex": 4
|
|
206
|
+
},
|
|
207
|
+
"releaseTag": "Public",
|
|
208
|
+
"overloadIndex": 1,
|
|
209
|
+
"parameters": [
|
|
210
|
+
{
|
|
211
|
+
"parameterName": "reporter",
|
|
212
|
+
"parameterTypeTokenRange": {
|
|
213
|
+
"startIndex": 1,
|
|
214
|
+
"endIndex": 2
|
|
215
|
+
},
|
|
216
|
+
"isOptional": false
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
"name": "addGlobalLogReporter"
|
|
220
|
+
},
|
|
175
221
|
{
|
|
176
222
|
"kind": "Function",
|
|
177
223
|
"canonicalReference": "@genesislcap/foundation-logger!areLogTimestampsEnabled:function(1)",
|
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import { ConsolaInstance } from 'consola/core';
|
|
2
2
|
import { ConsolaOptions } from 'consola/core';
|
|
3
|
-
import
|
|
3
|
+
import { ConsolaReporter } from 'consola/core';
|
|
4
4
|
import { LogLevel } from 'consola/core';
|
|
5
5
|
import { LogLevels } from 'consola/core';
|
|
6
6
|
import type { LogObject } from 'consola/core';
|
|
7
7
|
import { LogType } from 'consola/core';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Registers a reporter that receives every log from every foundation logger, including loggers
|
|
11
|
+
* created before this call. Returns an unsubscribe function.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* An error thrown by the reporter is written to the console instead of propagating out of the
|
|
15
|
+
* log call. Loggers that were created with the reporter keep it after unsubscribing.
|
|
16
|
+
*
|
|
17
|
+
* @example Register an error monitor.
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { addGlobalLogReporter } from '@genesislcap/foundation-logger';
|
|
20
|
+
*
|
|
21
|
+
* const unsubscribe = addGlobalLogReporter({
|
|
22
|
+
* log: ({ type, tag, args }) => {
|
|
23
|
+
* if (type !== 'error') return;
|
|
24
|
+
* const error = args.find((a) => a instanceof Error);
|
|
25
|
+
* error ? Sentry.captureException(error, { tags: { logger: tag } })
|
|
26
|
+
* : Sentry.captureMessage(`${tag}: ${String(args[0])}`, { level: 'error' });
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param reporter - The Consola reporter to register globally.
|
|
32
|
+
* @returns An unsubscribe function that removes the reporter from all loggers.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare function addGlobalLogReporter(reporter: ConsolaReporter): () => void;
|
|
36
|
+
|
|
9
37
|
/**
|
|
10
38
|
* Returns whether the global timestamp prefix is currently enabled.
|
|
11
39
|
*
|
|
@@ -14,6 +42,8 @@ import { LogType } from 'consola/core';
|
|
|
14
42
|
*/
|
|
15
43
|
export declare function areLogTimestampsEnabled(): boolean;
|
|
16
44
|
|
|
45
|
+
export { ConsolaReporter }
|
|
46
|
+
|
|
17
47
|
/**
|
|
18
48
|
* Creates a logger with the given name and options.
|
|
19
49
|
*
|
package/package.json
CHANGED