voltlog-io 1.0.1 → 1.0.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/LICENSE +21 -21
- package/README.md +343 -65
- package/dist/index.d.mts +374 -5
- package/dist/index.d.ts +374 -5
- package/dist/index.js +708 -247
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +592 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +75 -78
package/dist/index.d.mts
CHANGED
|
@@ -19,7 +19,7 @@ declare const LogLevelNameMap: Record<string, number>;
|
|
|
19
19
|
/** Map from numeric value to level name */
|
|
20
20
|
declare const LogLevelValueMap: Record<number, LogLevelName>;
|
|
21
21
|
interface LogEntry<TMeta = Record<string, unknown>> {
|
|
22
|
-
/** Unique log ID
|
|
22
|
+
/** Unique log ID */
|
|
23
23
|
id: string;
|
|
24
24
|
/** Numeric log level */
|
|
25
25
|
level: number;
|
|
@@ -37,12 +37,16 @@ interface LogEntry<TMeta = Record<string, unknown>> {
|
|
|
37
37
|
correlationId?: string;
|
|
38
38
|
/** Error information */
|
|
39
39
|
error?: LogError;
|
|
40
|
+
/** @internal Cached JSON serialization — avoids redundant stringify across transports */
|
|
41
|
+
_json?: string;
|
|
40
42
|
}
|
|
41
43
|
interface LogError {
|
|
42
44
|
message: string;
|
|
43
45
|
stack?: string;
|
|
44
46
|
code?: string;
|
|
45
47
|
name?: string;
|
|
48
|
+
/** Nested cause chain (ES2022 Error.cause support) */
|
|
49
|
+
cause?: LogError;
|
|
46
50
|
}
|
|
47
51
|
interface OcppExchangeMeta {
|
|
48
52
|
/** Charge point / station identity */
|
|
@@ -108,6 +112,12 @@ interface AlertRule<TMeta = Record<string, unknown>> {
|
|
|
108
112
|
/** Callback fired when alert conditions are met */
|
|
109
113
|
onAlert: (entries: LogEntry<TMeta>[]) => void | Promise<void>;
|
|
110
114
|
}
|
|
115
|
+
interface TimerResult<TMeta = Record<string, unknown>> {
|
|
116
|
+
/** End the timer and log the duration */
|
|
117
|
+
done(message: string, meta?: Partial<TMeta>): void;
|
|
118
|
+
/** Get elapsed time in ms without logging */
|
|
119
|
+
elapsed(): number;
|
|
120
|
+
}
|
|
111
121
|
interface LoggerOptions<TMeta = Record<string, unknown>> {
|
|
112
122
|
/** Minimum log level (default: INFO) */
|
|
113
123
|
level?: LogLevelName;
|
|
@@ -138,6 +148,12 @@ interface LoggerOptions<TMeta = Record<string, unknown>> {
|
|
|
138
148
|
exchangeLog?: boolean | "only";
|
|
139
149
|
/** Custom timestamp function (default: Date.now) */
|
|
140
150
|
timestamp?: () => number;
|
|
151
|
+
/**
|
|
152
|
+
* Custom ID generator function.
|
|
153
|
+
* Default: `crypto.randomUUID()` (native, fast).
|
|
154
|
+
* Set to `false` to disable ID generation entirely for max performance.
|
|
155
|
+
*/
|
|
156
|
+
idGenerator?: (() => string) | false;
|
|
141
157
|
}
|
|
142
158
|
interface Logger<TMeta = Record<string, unknown>> {
|
|
143
159
|
trace(message: string, meta?: Partial<TMeta>): void;
|
|
@@ -154,6 +170,16 @@ interface Logger<TMeta = Record<string, unknown>> {
|
|
|
154
170
|
removeTransport(name: string): void;
|
|
155
171
|
/** Add middleware at runtime */
|
|
156
172
|
addMiddleware(middleware: LogMiddleware<TMeta>): void;
|
|
173
|
+
/** Remove middleware by reference */
|
|
174
|
+
removeMiddleware(middleware: LogMiddleware<TMeta>): void;
|
|
175
|
+
/** Change the minimum log level at runtime */
|
|
176
|
+
setLevel(level: LogLevelName): void;
|
|
177
|
+
/** Get the current minimum log level */
|
|
178
|
+
getLevel(): LogLevelName;
|
|
179
|
+
/** Check if a given level would produce output (useful to guard expensive meta computation) */
|
|
180
|
+
isLevelEnabled(level: LogLevelName): boolean;
|
|
181
|
+
/** Start a timer — call `.done(msg)` to log elapsed duration */
|
|
182
|
+
startTimer(level?: LogLevelName): TimerResult<TMeta>;
|
|
157
183
|
/** Flush all transports */
|
|
158
184
|
flush(): Promise<void>;
|
|
159
185
|
/** Close all transports gracefully */
|
|
@@ -354,6 +380,75 @@ declare function createOpenAiErrorAnalyzer(apiKey: string, model?: string, syste
|
|
|
354
380
|
*/
|
|
355
381
|
declare function alertMiddleware<TMeta = Record<string, unknown>>(rules: AlertRule<TMeta>[]): LogMiddleware<TMeta>;
|
|
356
382
|
|
|
383
|
+
/**
|
|
384
|
+
* @module voltlog-io
|
|
385
|
+
* @description AsyncLocalStorage context middleware — automatically propagates
|
|
386
|
+
* context across async boundaries without manual child logger threading.
|
|
387
|
+
*
|
|
388
|
+
* @server-only Requires Node.js 16+ (AsyncLocalStorage).
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* import { createLogger, prettyTransport } from 'voltlog-io';
|
|
393
|
+
* import { asyncContextMiddleware } from 'voltlog-io';
|
|
394
|
+
*
|
|
395
|
+
* const asyncCtx = asyncContextMiddleware();
|
|
396
|
+
*
|
|
397
|
+
* const logger = createLogger({
|
|
398
|
+
* middleware: [asyncCtx.middleware],
|
|
399
|
+
* transports: [prettyTransport()],
|
|
400
|
+
* });
|
|
401
|
+
*
|
|
402
|
+
* // In Express middleware — set context once
|
|
403
|
+
* app.use((req, res, next) => {
|
|
404
|
+
* asyncCtx.runInContext({ requestId: req.id, userId: req.user?.id }, next);
|
|
405
|
+
* });
|
|
406
|
+
*
|
|
407
|
+
* // Anywhere downstream — context is automatic
|
|
408
|
+
* async function processOrder(orderId: string) {
|
|
409
|
+
* logger.info('Processing', { orderId });
|
|
410
|
+
* // → auto-includes: { requestId: 'req-123', userId: 'u-42', orderId: '...' }
|
|
411
|
+
*
|
|
412
|
+
* await chargePayment(orderId);
|
|
413
|
+
* logger.info('Payment charged');
|
|
414
|
+
* // → still has requestId and userId, even after await!
|
|
415
|
+
* }
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
|
|
419
|
+
interface AsyncContextResult<TMeta = Record<string, unknown>> {
|
|
420
|
+
/** Middleware to add to your logger — injects async context into entries */
|
|
421
|
+
middleware: LogMiddleware<TMeta>;
|
|
422
|
+
/**
|
|
423
|
+
* Run a function with the given context.
|
|
424
|
+
* All logs within the function (and any async calls it makes) will
|
|
425
|
+
* automatically include this context in their metadata.
|
|
426
|
+
*/
|
|
427
|
+
runInContext: (context: Record<string, unknown>, fn: () => void) => void;
|
|
428
|
+
/**
|
|
429
|
+
* Get the current async context, or undefined if not inside a runInContext call.
|
|
430
|
+
*/
|
|
431
|
+
getContext: () => Record<string, unknown> | undefined;
|
|
432
|
+
/**
|
|
433
|
+
* Update the current async context by merging new values.
|
|
434
|
+
* Only works inside a runInContext call.
|
|
435
|
+
*/
|
|
436
|
+
updateContext: (updates: Record<string, unknown>) => void;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Creates an AsyncLocalStorage-based context system.
|
|
440
|
+
*
|
|
441
|
+
* Returns a middleware (to add to the logger) and helper functions
|
|
442
|
+
* to manage the async context.
|
|
443
|
+
*
|
|
444
|
+
* How it works:
|
|
445
|
+
* 1. Call `runInContext({ requestId, userId }, handler)` at the start of a request
|
|
446
|
+
* 2. The middleware automatically injects that context into every log entry
|
|
447
|
+
* 3. Context propagates across await, setTimeout, Promise.then, etc.
|
|
448
|
+
* 4. Each request gets its own isolated context (no cross-contamination)
|
|
449
|
+
*/
|
|
450
|
+
declare function asyncContextMiddleware<TMeta = Record<string, unknown>>(): AsyncContextResult<TMeta>;
|
|
451
|
+
|
|
357
452
|
/**
|
|
358
453
|
* @module voltlog-io
|
|
359
454
|
* @description Correlation ID middleware — adds tracing IDs to logs.
|
|
@@ -442,6 +537,78 @@ interface HeapUsageOptions {
|
|
|
442
537
|
*/
|
|
443
538
|
declare function heapUsageMiddleware<TMeta = Record<string, unknown>>(options?: HeapUsageOptions): LogMiddleware<TMeta>;
|
|
444
539
|
|
|
540
|
+
/**
|
|
541
|
+
* @module voltlog-io
|
|
542
|
+
* @description Universal HTTP middleware builder. Allows integration with Express, Fastify, exact node:http, etc.
|
|
543
|
+
* without introducing third-party framework dependencies.
|
|
544
|
+
*/
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Extracts essential logic from a given raw HTTP Request object
|
|
548
|
+
* regardless of the underlying framework (Express, Fastify, etc.)
|
|
549
|
+
*/
|
|
550
|
+
interface HttpRequestMapper<TReq = any> {
|
|
551
|
+
getMethod: (req: TReq) => string;
|
|
552
|
+
getUrl: (req: TReq) => string;
|
|
553
|
+
getIp?: (req: TReq) => string | undefined;
|
|
554
|
+
getUserAgent?: (req: TReq) => string | undefined;
|
|
555
|
+
/** Extract a particular header value */
|
|
556
|
+
getHeader?: (req: TReq, name: string) => string | undefined;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Extracts essential logic from a given raw HTTP Response object
|
|
560
|
+
*/
|
|
561
|
+
interface HttpResponseMapper<TRes = any> {
|
|
562
|
+
getStatusCode: (res: TRes) => number;
|
|
563
|
+
/** Execute callback when response is fully sent to the client */
|
|
564
|
+
onFinish: (res: TRes, callback: () => void) => void;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Options for configuring the HTTP access logger
|
|
568
|
+
*/
|
|
569
|
+
interface HttpLoggerOptions<TReq = any, TRes = any> {
|
|
570
|
+
reqMapper: HttpRequestMapper<TReq>;
|
|
571
|
+
resMapper: HttpResponseMapper<TRes>;
|
|
572
|
+
/** Log level to use for HTTP requests (default: INFO) */
|
|
573
|
+
level?: "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL";
|
|
574
|
+
/** Extract specific dynamic context values from the request to add to meta */
|
|
575
|
+
extractContext?: (req: TReq, res: TRes) => Record<string, unknown>;
|
|
576
|
+
/** Function to skip logging certain requests (e.g., /health) */
|
|
577
|
+
skip?: (req: TReq) => boolean;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Common mappers for the raw Node.js `http.IncomingMessage` and `http.ServerResponse`.
|
|
581
|
+
* Since Express and many others extend these objects, they work universally.
|
|
582
|
+
*/
|
|
583
|
+
declare const nodeHttpMappers: {
|
|
584
|
+
req: HttpRequestMapper;
|
|
585
|
+
res: HttpResponseMapper;
|
|
586
|
+
};
|
|
587
|
+
/**
|
|
588
|
+
* Creates a generic HTTP logging middleware function.
|
|
589
|
+
* Use this inside Express, Fastify, or custom routers.
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts
|
|
593
|
+
* import express from 'express';
|
|
594
|
+
* import { createHttpLogger, nodeHttpMappers, createLogger } from 'voltlog-io';
|
|
595
|
+
*
|
|
596
|
+
* const app = express();
|
|
597
|
+
* const logger = createLogger();
|
|
598
|
+
*
|
|
599
|
+
* const httpLogger = createHttpLogger(logger, {
|
|
600
|
+
* reqMapper: nodeHttpMappers.req,
|
|
601
|
+
* resMapper: nodeHttpMappers.res,
|
|
602
|
+
* });
|
|
603
|
+
*
|
|
604
|
+
* app.use((req, res, next) => {
|
|
605
|
+
* httpLogger(req, res);
|
|
606
|
+
* next();
|
|
607
|
+
* });
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
declare function createHttpLogger<TReq = any, TRes = any>(logger: Logger, options: HttpLoggerOptions<TReq, TRes>): (req: TReq, res: TRes) => void;
|
|
611
|
+
|
|
445
612
|
/**
|
|
446
613
|
* @module voltlog-io
|
|
447
614
|
* @description IP middleware — extracts client IP from headers (x-forwarded-for, etc.).
|
|
@@ -532,6 +699,61 @@ interface OcppMiddlewareOptions {
|
|
|
532
699
|
*/
|
|
533
700
|
declare function ocppMiddleware(options?: OcppMiddlewareOptions): LogMiddleware<OcppExchangeMeta>;
|
|
534
701
|
|
|
702
|
+
/**
|
|
703
|
+
* @module voltlog-io
|
|
704
|
+
* @description OpenTelemetry middleware — automatically picks up the active trace context.
|
|
705
|
+
* Works like Winston's @opentelemetry/instrumentation-winston but as a simple middleware.
|
|
706
|
+
*
|
|
707
|
+
* @server-only Requires `@opentelemetry/api` as an optional peer dependency.
|
|
708
|
+
*
|
|
709
|
+
* When the OpenTelemetry SDK is active (e.g., with SigNoz, Jaeger, Grafana Tempo),
|
|
710
|
+
* this middleware automatically injects traceId, spanId, and traceFlags into every log entry.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* ```ts
|
|
714
|
+
* import { createLogger, otelTraceMiddleware, otelTransport } from 'voltlog-io';
|
|
715
|
+
*
|
|
716
|
+
* const logger = createLogger({
|
|
717
|
+
* middleware: [otelTraceMiddleware()],
|
|
718
|
+
* transports: [
|
|
719
|
+
* otelTransport({
|
|
720
|
+
* endpoint: 'http://localhost:4318',
|
|
721
|
+
* serviceName: 'my-app',
|
|
722
|
+
* }),
|
|
723
|
+
* ],
|
|
724
|
+
* });
|
|
725
|
+
*
|
|
726
|
+
* // If an OTel span is active, every log automatically gets:
|
|
727
|
+
* // { traceId: "abc123...", spanId: "def456...", traceFlags: 1 }
|
|
728
|
+
* logger.info("Processing request");
|
|
729
|
+
* ```
|
|
730
|
+
*/
|
|
731
|
+
|
|
732
|
+
interface OtelTraceMiddlewareOptions {
|
|
733
|
+
/**
|
|
734
|
+
* Custom reference to `@opentelemetry/api` trace module.
|
|
735
|
+
* If not provided, we attempt `require('@opentelemetry/api')` or dynamic import.
|
|
736
|
+
* This allows the middleware to work without a hard dependency.
|
|
737
|
+
*/
|
|
738
|
+
traceApi?: {
|
|
739
|
+
trace: {
|
|
740
|
+
getActiveSpan: () => unknown;
|
|
741
|
+
};
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Middleware that automatically injects OpenTelemetry trace context into log entries.
|
|
746
|
+
*
|
|
747
|
+
* How it works:
|
|
748
|
+
* 1. On each log call, checks for an active OTel span
|
|
749
|
+
* 2. If found, extracts traceId, spanId, and traceFlags
|
|
750
|
+
* 3. Injects them into the log entry's metadata
|
|
751
|
+
*
|
|
752
|
+
* This is the equivalent of Winston's @opentelemetry/instrumentation-winston
|
|
753
|
+
* but implemented as a zero-dependency middleware.
|
|
754
|
+
*/
|
|
755
|
+
declare function otelTraceMiddleware<TMeta = Record<string, unknown>>(options?: OtelTraceMiddlewareOptions): LogMiddleware<TMeta>;
|
|
756
|
+
|
|
535
757
|
/**
|
|
536
758
|
* @module voltlog-io
|
|
537
759
|
* @description Redaction middleware — masks sensitive data in log entries.
|
|
@@ -799,7 +1021,7 @@ declare function discordTransport(options: DiscordTransportOptions): Transport;
|
|
|
799
1021
|
|
|
800
1022
|
/**
|
|
801
1023
|
* @module voltlog-io
|
|
802
|
-
* @description File transformer — writes logs to disk with daily rotation.
|
|
1024
|
+
* @description File transformer — writes logs to disk with daily rotation and optional size-based rotation.
|
|
803
1025
|
* @server-only
|
|
804
1026
|
* This transport relies on the `node:fs` module to write files to the local filesystem.
|
|
805
1027
|
* Browsers do not have direct access to the filesystem for security reasons.
|
|
@@ -815,10 +1037,16 @@ interface FileTransportOptions {
|
|
|
815
1037
|
filename?: string;
|
|
816
1038
|
/** Per-transport level filter */
|
|
817
1039
|
level?: LogLevelName;
|
|
1040
|
+
/**
|
|
1041
|
+
* Maximum file size in bytes before rotating to a new file.
|
|
1042
|
+
* When exceeded, the current file is renamed with a numeric suffix.
|
|
1043
|
+
* Default: no size limit (daily rotation only).
|
|
1044
|
+
*/
|
|
1045
|
+
maxSize?: number;
|
|
818
1046
|
}
|
|
819
1047
|
/**
|
|
820
1048
|
* Creates a file transport that writes newline-delimited JSON.
|
|
821
|
-
* Rotates files daily based on the `%DATE%` pattern.
|
|
1049
|
+
* Rotates files daily based on the `%DATE%` pattern and optionally by size.
|
|
822
1050
|
*/
|
|
823
1051
|
declare function fileTransport(options: FileTransportOptions): Transport;
|
|
824
1052
|
|
|
@@ -885,14 +1113,30 @@ interface LokiTransportOptions {
|
|
|
885
1113
|
basicAuthPassword?: string;
|
|
886
1114
|
/** Tenant ID (header X-Scope-OrgID) */
|
|
887
1115
|
tenantId?: string;
|
|
888
|
-
/**
|
|
1116
|
+
/** Static labels to attach to every stream (e.g. { app: 'volt-server' }) */
|
|
889
1117
|
labels?: Record<string, string>;
|
|
1118
|
+
/**
|
|
1119
|
+
* Extract dynamic labels from each log entry.
|
|
1120
|
+
* These are merged with static labels and used as Loki stream labels.
|
|
1121
|
+
* Keep cardinality low — use only a few well-known values.
|
|
1122
|
+
* @example (entry) => ({ level: entry.levelName, service: entry.context?.service })
|
|
1123
|
+
*/
|
|
1124
|
+
dynamicLabels?: (entry: LogEntry) => Record<string, string | undefined>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Include context, error, and correlationId in the Loki log payload.
|
|
1127
|
+
* Default: true
|
|
1128
|
+
*/
|
|
1129
|
+
includeMetadata?: boolean;
|
|
890
1130
|
/** Transport level filter */
|
|
891
1131
|
level?: LogLevelName;
|
|
892
1132
|
/** Batch size (default: 10) */
|
|
893
1133
|
batchSize?: number;
|
|
894
1134
|
/** Batch interval ms (default: 5000) */
|
|
895
1135
|
interval?: number;
|
|
1136
|
+
/** Enable retry on push failure (default: false) */
|
|
1137
|
+
retry?: boolean;
|
|
1138
|
+
/** Maximum retries (default: 3) */
|
|
1139
|
+
maxRetries?: number;
|
|
896
1140
|
}
|
|
897
1141
|
/**
|
|
898
1142
|
* Pushes logs to Grafana Loki via HTTP API.
|
|
@@ -900,6 +1144,75 @@ interface LokiTransportOptions {
|
|
|
900
1144
|
*/
|
|
901
1145
|
declare function lokiTransport(options: LokiTransportOptions): Transport;
|
|
902
1146
|
|
|
1147
|
+
/**
|
|
1148
|
+
* @module voltlog-io
|
|
1149
|
+
* @description OpenTelemetry OTLP transport — sends logs via OTLP HTTP/JSON protocol.
|
|
1150
|
+
* @server-only Uses `fetch()` to send logs to an OTLP-compatible collector.
|
|
1151
|
+
*
|
|
1152
|
+
* Compatible with: SigNoz, Jaeger, Grafana Alloy, OpenTelemetry Collector, and any OTLP endpoint.
|
|
1153
|
+
*
|
|
1154
|
+
* @example
|
|
1155
|
+
* ```ts
|
|
1156
|
+
* import { createLogger, otelTraceMiddleware, otelTransport } from 'voltlog-io';
|
|
1157
|
+
*
|
|
1158
|
+
* // SigNoz Cloud
|
|
1159
|
+
* const logger = createLogger({
|
|
1160
|
+
* middleware: [otelTraceMiddleware()],
|
|
1161
|
+
* transports: [
|
|
1162
|
+
* otelTransport({
|
|
1163
|
+
* endpoint: 'https://ingest.signoz.io',
|
|
1164
|
+
* headers: { 'signoz-access-token': 'YOUR_TOKEN' },
|
|
1165
|
+
* serviceName: 'my-app',
|
|
1166
|
+
* }),
|
|
1167
|
+
* ],
|
|
1168
|
+
* });
|
|
1169
|
+
*
|
|
1170
|
+
* // Self-hosted OTel Collector
|
|
1171
|
+
* const logger2 = createLogger({
|
|
1172
|
+
* transports: [
|
|
1173
|
+
* otelTransport({
|
|
1174
|
+
* endpoint: 'http://localhost:4318', // OTLP HTTP port
|
|
1175
|
+
* serviceName: 'volt-csms',
|
|
1176
|
+
* resource: {
|
|
1177
|
+
* 'deployment.environment': 'production',
|
|
1178
|
+
* 'service.version': '2.0.0',
|
|
1179
|
+
* },
|
|
1180
|
+
* }),
|
|
1181
|
+
* ],
|
|
1182
|
+
* });
|
|
1183
|
+
*
|
|
1184
|
+
* logger.info('Request processed', { userId: 'u-42' });
|
|
1185
|
+
* // → Sent to SigNoz with traceId, spanId, severity, resource attributes
|
|
1186
|
+
* ```
|
|
1187
|
+
*/
|
|
1188
|
+
|
|
1189
|
+
interface OtelTransportOptions {
|
|
1190
|
+
/**
|
|
1191
|
+
* OTLP HTTP endpoint (e.g. http://localhost:4318 or https://ingest.signoz.io).
|
|
1192
|
+
* The `/v1/logs` path is appended automatically.
|
|
1193
|
+
*/
|
|
1194
|
+
endpoint: string;
|
|
1195
|
+
/** Service name reported to the collector */
|
|
1196
|
+
serviceName: string;
|
|
1197
|
+
/** Additional resource attributes (e.g. deployment.environment, service.version) */
|
|
1198
|
+
resource?: Record<string, string>;
|
|
1199
|
+
/** Extra headers (e.g. signoz-access-token, Authorization) */
|
|
1200
|
+
headers?: Record<string, string>;
|
|
1201
|
+
/** Transport level filter */
|
|
1202
|
+
level?: LogLevelName;
|
|
1203
|
+
/** Batch size before flush (default: 20) */
|
|
1204
|
+
batchSize?: number;
|
|
1205
|
+
/** Batch interval in ms (default: 5000) */
|
|
1206
|
+
interval?: number;
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Creates an OTLP HTTP/JSON transport for OpenTelemetry-compatible backends.
|
|
1210
|
+
*
|
|
1211
|
+
* Sends logs using the OTLP Logs protocol:
|
|
1212
|
+
* https://opentelemetry.io/docs/specs/otlp/#otlphttp-request
|
|
1213
|
+
*/
|
|
1214
|
+
declare function otelTransport(options: OtelTransportOptions): Transport;
|
|
1215
|
+
|
|
903
1216
|
/**
|
|
904
1217
|
* @module voltlog-io
|
|
905
1218
|
* @description Pretty transformer — human-readable colored output with OCPP exchange formatting.
|
|
@@ -939,6 +1252,10 @@ interface PrettyTransportOptions {
|
|
|
939
1252
|
timestamps?: boolean;
|
|
940
1253
|
/** Use colors in output (default: true) */
|
|
941
1254
|
colors?: boolean;
|
|
1255
|
+
/** Hide meta object in output (default: false) */
|
|
1256
|
+
hideMeta?: boolean;
|
|
1257
|
+
/** Pretty-print meta object with indentation (default: false) */
|
|
1258
|
+
prettyMeta?: boolean;
|
|
942
1259
|
}
|
|
943
1260
|
/**
|
|
944
1261
|
* Create a pretty-print transport for dev/debug use.
|
|
@@ -1034,6 +1351,58 @@ interface RedisTransportOptions {
|
|
|
1034
1351
|
*/
|
|
1035
1352
|
declare function redisTransport(options: RedisTransportOptions): Transport;
|
|
1036
1353
|
|
|
1354
|
+
/**
|
|
1355
|
+
* @module voltlog-io
|
|
1356
|
+
* @description Ring buffer transport — stores last N log entries in memory for on-demand retrieval.
|
|
1357
|
+
* @universal Works in all environments.
|
|
1358
|
+
*
|
|
1359
|
+
* Useful for debugging, in-app log viewers, and diagnostic endpoints.
|
|
1360
|
+
*
|
|
1361
|
+
* @example
|
|
1362
|
+
* ```ts
|
|
1363
|
+
* import { createLogger, ringBufferTransport } from 'voltlog-io';
|
|
1364
|
+
*
|
|
1365
|
+
* const ring = ringBufferTransport({ maxSize: 500 });
|
|
1366
|
+
* const logger = createLogger({ transports: [ring] });
|
|
1367
|
+
*
|
|
1368
|
+
* logger.info('Hello');
|
|
1369
|
+
* logger.error('Oops', new Error('fail'));
|
|
1370
|
+
*
|
|
1371
|
+
* // Retrieve buffered entries
|
|
1372
|
+
* const entries = ring.getEntries();
|
|
1373
|
+
* const errors = ring.getEntries({ level: 'ERROR' });
|
|
1374
|
+
* ```
|
|
1375
|
+
*/
|
|
1376
|
+
|
|
1377
|
+
interface RingBufferTransportOptions {
|
|
1378
|
+
/** Maximum number of entries to keep (default: 1000) */
|
|
1379
|
+
maxSize?: number;
|
|
1380
|
+
/** Per-transport level filter */
|
|
1381
|
+
level?: LogLevelName;
|
|
1382
|
+
}
|
|
1383
|
+
interface RingBufferQueryOptions {
|
|
1384
|
+
/** Filter by minimum level */
|
|
1385
|
+
level?: LogLevelName;
|
|
1386
|
+
/** Return only entries after this timestamp */
|
|
1387
|
+
since?: number;
|
|
1388
|
+
/** Maximum entries to return (default: all) */
|
|
1389
|
+
limit?: number;
|
|
1390
|
+
}
|
|
1391
|
+
interface RingBufferTransport extends Transport {
|
|
1392
|
+
/** Retrieve buffered log entries with optional filtering */
|
|
1393
|
+
getEntries(query?: RingBufferQueryOptions): LogEntry[];
|
|
1394
|
+
/** Clear all buffered entries */
|
|
1395
|
+
clear(): void;
|
|
1396
|
+
/** Get current buffer size */
|
|
1397
|
+
size: number;
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Creates a ring buffer (circular buffer) transport.
|
|
1401
|
+
* Stores the most recent `maxSize` entries in memory.
|
|
1402
|
+
* Oldest entries are evicted when the buffer is full.
|
|
1403
|
+
*/
|
|
1404
|
+
declare function ringBufferTransport(options?: RingBufferTransportOptions): RingBufferTransport;
|
|
1405
|
+
|
|
1037
1406
|
/**
|
|
1038
1407
|
* @module voltlog-io
|
|
1039
1408
|
* @description Sentry transformer — pushes errors to Sentry.
|
|
@@ -1139,4 +1508,4 @@ interface WebhookTransportOptions {
|
|
|
1139
1508
|
*/
|
|
1140
1509
|
declare function webhookTransport(options: WebhookTransportOptions): Transport;
|
|
1141
1510
|
|
|
1142
|
-
export { type AiEnrichmentOptions, type AlertRule, type BatchTransportOptions, type BrowserJsonStreamTransportOptions, type ConsoleTransportOptions, type CorrelationIdOptions, type DatadogTransportOptions, type DeduplicationOptions, type DiscordTransportOptions, type FileTransportOptions, type JsonStreamTransportOptions, type LevelOverrideOptions, type LogEntry, type LogError, LogLevel, type LogLevelName, LogLevelNameMap, type LogLevelValue, LogLevelValueMap, type LogMiddleware, type Logger, type LoggerOptions, type LokiTransportOptions, type OcppExchangeMeta, type OcppMiddlewareOptions, type PrettyTransportOptions, type RedactionOptions, type RedisClient, type RedisTransportOptions, type SamplingOptions, type SentryInstance, type SentryTransportOptions, type SlackTransportOptions, type Transport, type UserAgentOptions, type WebhookTransportOptions, aiEnrichmentMiddleware, alertMiddleware, batchTransport, browserJsonStreamTransport, consoleTransport, correlationIdMiddleware, createLogger, createMiddleware, createOpenAiErrorAnalyzer, createTransport, datadogTransport, deduplicationMiddleware, discordTransport, fileTransport, heapUsageMiddleware, ipMiddleware, jsonStreamTransport, levelOverrideMiddleware, lokiTransport, ocppMiddleware, prettyTransport, redactionMiddleware, redisTransport, resolveLevel, samplingMiddleware, sentryTransport, shouldIncludeStack, shouldLog, slackTransport, userAgentMiddleware, webhookTransport };
|
|
1511
|
+
export { type AiEnrichmentOptions, type AlertRule, type AsyncContextResult, type BatchTransportOptions, type BrowserJsonStreamTransportOptions, type ConsoleTransportOptions, type CorrelationIdOptions, type DatadogTransportOptions, type DeduplicationOptions, type DiscordTransportOptions, type FileTransportOptions, type HttpLoggerOptions, type HttpRequestMapper, type HttpResponseMapper, type JsonStreamTransportOptions, type LevelOverrideOptions, type LogEntry, type LogError, LogLevel, type LogLevelName, LogLevelNameMap, type LogLevelValue, LogLevelValueMap, type LogMiddleware, type Logger, type LoggerOptions, type LokiTransportOptions, type OcppExchangeMeta, type OcppMiddlewareOptions, type OtelTraceMiddlewareOptions, type OtelTransportOptions, type PrettyTransportOptions, type RedactionOptions, type RedisClient, type RedisTransportOptions, type RingBufferQueryOptions, type RingBufferTransport, type RingBufferTransportOptions, type SamplingOptions, type SentryInstance, type SentryTransportOptions, type SlackTransportOptions, type TimerResult, type Transport, type UserAgentOptions, type WebhookTransportOptions, aiEnrichmentMiddleware, alertMiddleware, asyncContextMiddleware, batchTransport, browserJsonStreamTransport, consoleTransport, correlationIdMiddleware, createHttpLogger, createLogger, createMiddleware, createOpenAiErrorAnalyzer, createTransport, datadogTransport, deduplicationMiddleware, discordTransport, fileTransport, heapUsageMiddleware, ipMiddleware, jsonStreamTransport, levelOverrideMiddleware, lokiTransport, nodeHttpMappers, ocppMiddleware, otelTraceMiddleware, otelTransport, prettyTransport, redactionMiddleware, redisTransport, resolveLevel, ringBufferTransport, samplingMiddleware, sentryTransport, shouldIncludeStack, shouldLog, slackTransport, userAgentMiddleware, webhookTransport };
|