@steve31415/baselib 3.13.0 → 3.14.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/dist/log-core.d.ts +4 -0
- package/dist/log-core.js +27 -0
- package/dist/log.d.ts +2 -2
- package/dist/log.js +4 -1
- package/package.json +1 -1
package/dist/log-core.d.ts
CHANGED
|
@@ -152,5 +152,9 @@ export declare function shapeMeta(meta: Record<string, unknown>): {
|
|
|
152
152
|
issues: ShapeIssue[];
|
|
153
153
|
leaves: number;
|
|
154
154
|
};
|
|
155
|
+
/** Toggle strict shape checking — for tests that exercise the rewrite/WARN
|
|
156
|
+
* behavior itself. Restore with setLogShapeStrict(true) (or leave it: vitest
|
|
157
|
+
* isolates module state per file). */
|
|
158
|
+
export declare function setLogShapeStrict(on: boolean): void;
|
|
155
159
|
/** Forget which sites have been flagged (tests). */
|
|
156
160
|
export declare function resetLogShapeWarnings(): void;
|
package/dist/log-core.js
CHANGED
|
@@ -377,6 +377,12 @@ function buildEvent(opts, level, message, meta) {
|
|
|
377
377
|
* the shape rules in this process, a WARN `kind=log-shape` naming the site. */
|
|
378
378
|
export function makeEvents(opts, level, message, meta) {
|
|
379
379
|
const { event, issues } = buildEvent(opts, level, message, meta);
|
|
380
|
+
if (issues.length > 0 && strict) {
|
|
381
|
+
throw new Error(`log-shape (strict): "${message}" — ${issues.map(describeIssue).join('; ')}. ` +
|
|
382
|
+
'Fix the logging site: keys are columns (OPERATIONS.md). ' +
|
|
383
|
+
'(Strict mode is on under vitest so shape bugs fail tests instead of ' +
|
|
384
|
+
'shipping as rewrites; setLogShapeStrict(false) to test the rewrite itself.)');
|
|
385
|
+
}
|
|
380
386
|
const fresh = issues.filter((i) => {
|
|
381
387
|
const key = `${i.kind}\n${message}`;
|
|
382
388
|
if (flagged.has(key))
|
|
@@ -457,6 +463,27 @@ export function shapeMeta(meta) {
|
|
|
457
463
|
// Sites already flagged in this process, by issue kind and message: the
|
|
458
464
|
// first offending event is worth a WARN, the ten-thousandth is not.
|
|
459
465
|
const flagged = new Set();
|
|
466
|
+
// Strict mode: makeEvents throws on a shape issue instead of rewriting.
|
|
467
|
+
// On by default under vitest so a shape bug fails the suite that exercises
|
|
468
|
+
// the logging site rather than reaching production as a rewritten event
|
|
469
|
+
// with a once-per-process WARN. LOG_SHAPE_STRICT=1/0 overrides the default
|
|
470
|
+
// either way (production stays permissive: a logger must never throw there).
|
|
471
|
+
function strictDefault() {
|
|
472
|
+
// log-core is shared with the browser build; no bare `process` access.
|
|
473
|
+
if (typeof process === 'undefined' || !process.env)
|
|
474
|
+
return false;
|
|
475
|
+
const explicit = process.env.LOG_SHAPE_STRICT;
|
|
476
|
+
if (explicit !== undefined && explicit !== '')
|
|
477
|
+
return explicit !== '0';
|
|
478
|
+
return process.env.VITEST !== undefined;
|
|
479
|
+
}
|
|
480
|
+
let strict = strictDefault();
|
|
481
|
+
/** Toggle strict shape checking — for tests that exercise the rewrite/WARN
|
|
482
|
+
* behavior itself. Restore with setLogShapeStrict(true) (or leave it: vitest
|
|
483
|
+
* isolates module state per file). */
|
|
484
|
+
export function setLogShapeStrict(on) {
|
|
485
|
+
strict = on;
|
|
486
|
+
}
|
|
460
487
|
/** Forget which sites have been flagged (tests). */
|
|
461
488
|
export function resetLogShapeWarnings() {
|
|
462
489
|
flagged.clear();
|
package/dist/log.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Logger, LogShipper, ShipperOptions } from './log-core.js';
|
|
2
|
-
export { LogShipper, serializeError, truncate } from './log-core.js';
|
|
3
|
-
export type { Logger, LogEvent, LogLevel, ShipperOptions, ShippedBatch, ShipFailureReason, } from './log-core.js';
|
|
2
|
+
export { LogShipper, makeEvent, makeEvents, serializeError, setLogShapeStrict, truncate } from './log-core.js';
|
|
3
|
+
export type { EventFactoryOptions, Logger, LogEvent, LogLevel, ShipperOptions, ShippedBatch, ShipFailureReason, } from './log-core.js';
|
|
4
4
|
export interface LoggerOptions {
|
|
5
5
|
/** App name, e.g. 'auth'. Becomes the `app` field queried in Axiom. */
|
|
6
6
|
app: string;
|
package/dist/log.js
CHANGED
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
// log-core's key-shape guard rewrites offenders and WARNs once per site.
|
|
10
10
|
import { writeSync } from 'node:fs';
|
|
11
11
|
import { LogShipper, makeEvents, truncate, } from './log-core.js';
|
|
12
|
-
|
|
12
|
+
// makeEvent/makeEvents are exported for app test fakes: routing a recording
|
|
13
|
+
// logger's calls through makeEvents applies the key-shape guard (strict under
|
|
14
|
+
// vitest) to fake-logged sites too.
|
|
15
|
+
export { LogShipper, makeEvent, makeEvents, serializeError, setLogShapeStrict, truncate } from './log-core.js';
|
|
13
16
|
// Registry of every shipper created here (plus any registered explicitly),
|
|
14
17
|
// used by flushAllLoggers and graceful shutdown. Shipper-level on purpose:
|
|
15
18
|
// with() children share their root's shipper, so registering loggers leaked
|
package/package.json
CHANGED