@eventuras/logger 0.7.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.
@@ -0,0 +1,11 @@
1
+ import { LogLevel, LogTransport } from '../types';
2
+ export declare class ConsoleTransport implements LogTransport {
3
+ private readonly bindings;
4
+ /** Create a ConsoleTransport with optional pre-bound context fields. */
5
+ constructor(bindings?: Record<string, unknown>);
6
+ /** Write a log entry to the appropriate `console` method. */
7
+ log(level: LogLevel, data: Record<string, unknown>, msg?: string): void;
8
+ /** Return a new ConsoleTransport with the given bindings merged in. */
9
+ child(bindings: Record<string, unknown>): LogTransport;
10
+ }
11
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/transports/console.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAWvD,qBAAa,gBAAiB,YAAW,YAAY;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0B;IAEnD,wEAAwE;gBAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI9C,6DAA6D;IAC7D,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAcvE,uEAAuE;IACvE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;CAGvD"}
@@ -0,0 +1,24 @@
1
+ import { Logger as PinoLogger, LoggerOptions as PinoLoggerOptions } from 'pino';
2
+ import { LogLevel, LogTransport } from '../types';
3
+ /** Options for creating a PinoTransport. */
4
+ export type PinoTransportOptions = {
5
+ /** Minimum log level. Defaults to `'info'`. */
6
+ level?: LogLevel;
7
+ /** Field paths to redact from output. */
8
+ redact?: string[];
9
+ /** Enable pretty-printed, human-readable output. */
10
+ prettyPrint?: boolean;
11
+ /** File path destination (omit for stdout). */
12
+ destination?: string;
13
+ /** Raw Pino options for advanced tuning (merged after built-in defaults). */
14
+ pinoOptions?: PinoLoggerOptions;
15
+ };
16
+ export declare class PinoTransport implements LogTransport {
17
+ /** The underlying Pino instance. Exposed for advanced integrations only. */
18
+ readonly pino: PinoLogger;
19
+ constructor(options?: PinoTransportOptions);
20
+ log(level: LogLevel, data: Record<string, unknown>, msg?: string): void;
21
+ child(bindings: Record<string, unknown>): LogTransport;
22
+ flush(): Promise<void>;
23
+ }
24
+ //# sourceMappingURL=pino.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pino.d.ts","sourceRoot":"","sources":["../../src/transports/pino.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAa,EAAE,KAAK,MAAM,IAAI,UAAU,EAAE,KAAK,aAAa,IAAI,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAChG,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGvD,4CAA4C;AAC5C,MAAM,MAAM,oBAAoB,GAAG;IACjC,+CAA+C;IAC/C,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,oDAAoD;IACpD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAEF,qBAAa,aAAc,YAAW,YAAY;IAChD,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;gBAEd,OAAO,GAAE,oBAAyB;IAwB9C,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAQvE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;IAKhD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Lightweight pretty-print formatter for development.
3
+ * Zero external dependencies — uses ANSI colors and simple formatting.
4
+ *
5
+ * Produces output like:
6
+ * 12:34:56 INFO (web:auth) → User logged in
7
+ * 12:34:56 ERROR (web:auth) → Failed to authenticate { error: "invalid token" }
8
+ */
9
+ /**
10
+ * Format a Pino JSON log line into a human-readable string.
11
+ * @param line Raw JSON string from Pino
12
+ * @returns Formatted string, or the original line if parsing fails
13
+ */
14
+ export declare function formatLogLine(line: string): string;
15
+ /**
16
+ * Creates a Node.js writable stream that formats Pino JSON output.
17
+ * Used as the destination for PinoTransport when prettyPrint is enabled.
18
+ */
19
+ export declare function createPrettyStream(): NodeJS.WritableStream;
20
+ //# sourceMappingURL=pretty.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pretty.d.ts","sourceRoot":"","sources":["../../src/transports/pretty.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAkEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAwBlD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,cAAc,CAa1D"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Core type definitions for @eventuras/logger.
3
+ *
4
+ * The `LogTransport` interface is the primary extension point — implement it
5
+ * to send logs to any backend (Pino, Winston, console, a test spy, etc.).
6
+ */
7
+ /** Standard log levels ordered by severity (lowest → highest). */
8
+ export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
9
+ /**
10
+ * Pluggable transport interface for log output.
11
+ *
12
+ * Implement this to send structured log data to any backend.
13
+ * The library ships with `PinoTransport` (default) and `ConsoleTransport`.
14
+ *
15
+ * @example
16
+ * // Custom transport
17
+ * const myTransport: LogTransport = {
18
+ * log(level, data, msg) { fetch('/logs', { body: JSON.stringify({ level, ...data, msg }) }); },
19
+ * child(bindings) { return { ...myTransport, log(l, d, m) { myTransport.log(l, { ...bindings, ...d }, m); } }; },
20
+ * };
21
+ */
22
+ export interface LogTransport {
23
+ /** Write a log entry at the given level. */
24
+ log(level: LogLevel, data: Record<string, unknown>, msg?: string): void;
25
+ /** Create a child transport with additional bound fields. */
26
+ child(bindings: Record<string, unknown>): LogTransport;
27
+ /** Flush any buffered log entries. */
28
+ flush?(): Promise<void>;
29
+ /** Graceful shutdown — flush and release resources. */
30
+ shutdown?(): Promise<void>;
31
+ }
32
+ /** Options for creating a scoped Logger instance. */
33
+ export type LoggerOptions = {
34
+ /** If true, only logs in development mode. */
35
+ developerOnly?: boolean;
36
+ /** Namespace for filtering logs (e.g., 'web:admin:events'). */
37
+ namespace?: string;
38
+ /** Minimum log level for this logger instance. */
39
+ level?: LogLevel;
40
+ /** Persistent context fields included in every log entry. */
41
+ context?: Record<string, unknown>;
42
+ /** Correlation ID for request tracing. */
43
+ correlationId?: string;
44
+ };
45
+ /** Extended options for error/fatal log methods. */
46
+ export type ErrorLoggerOptions = LoggerOptions & {
47
+ error?: unknown;
48
+ };
49
+ /** Global logger configuration. */
50
+ export type LoggerConfig = {
51
+ /** Global minimum log level. */
52
+ level?: LogLevel;
53
+ /** Field paths to redact from log output (e.g., ['password', 'token']). */
54
+ redact?: string[];
55
+ /** Enable pretty-printed output (auto-enabled in development). */
56
+ prettyPrint?: boolean;
57
+ /** Optional file path for log output (Pino only). */
58
+ destination?: string;
59
+ /** Custom transport implementation. Defaults to PinoTransport. */
60
+ transport?: LogTransport;
61
+ };
62
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;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O,CAAC;IACtB,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@eventuras/logger",
3
+ "version": "0.7.0",
4
+ "description": "Structured logging with Pino and optional OpenTelemetry integration",
5
+ "keywords": [
6
+ "logger",
7
+ "logging",
8
+ "structured-logging",
9
+ "pino",
10
+ "opentelemetry",
11
+ "otel"
12
+ ],
13
+ "homepage": "https://github.com/losol/eventuras/tree/main/libs/logger#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/losol/eventuras/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/losol/eventuras.git",
20
+ "directory": "libs/logger"
21
+ },
22
+ "license": "Apache-2.0",
23
+ "type": "module",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./node": {
30
+ "types": "./dist/node.d.ts",
31
+ "import": "./dist/node.js"
32
+ },
33
+ "./opentelemetry": {
34
+ "types": "./dist/opentelemetry.d.ts",
35
+ "import": "./dist/opentelemetry.js"
36
+ }
37
+ },
38
+ "main": "./dist/index.js",
39
+ "types": "./dist/index.d.ts",
40
+ "files": [
41
+ "dist"
42
+ ],
43
+ "scripts": {
44
+ "build": "vite build",
45
+ "dev": "vite build --watch",
46
+ "test": "vitest run",
47
+ "test:watch": "vitest"
48
+ },
49
+ "dependencies": {
50
+ "pino": "^10.3.1"
51
+ },
52
+ "devDependencies": {
53
+ "@eventuras/vite-config": "workspace:*",
54
+ "@opentelemetry/api": "^1.9.1",
55
+ "@opentelemetry/api-logs": "^0.214.0",
56
+ "@opentelemetry/instrumentation-pino": "^0.60.0",
57
+ "@opentelemetry/sdk-logs": "^0.214.0",
58
+ "vite": "^8.0.3",
59
+ "vitest": "^4.1.4"
60
+ },
61
+ "peerDependencies": {
62
+ "@opentelemetry/api": "^1.9.0",
63
+ "@opentelemetry/api-logs": ">=0.200.0",
64
+ "@opentelemetry/instrumentation-pino": ">=0.50.0",
65
+ "@opentelemetry/sdk-logs": ">=0.200.0"
66
+ },
67
+ "peerDependenciesMeta": {
68
+ "@opentelemetry/api": {
69
+ "optional": true
70
+ },
71
+ "@opentelemetry/api-logs": {
72
+ "optional": true
73
+ },
74
+ "@opentelemetry/instrumentation-pino": {
75
+ "optional": true
76
+ },
77
+ "@opentelemetry/sdk-logs": {
78
+ "optional": true
79
+ }
80
+ },
81
+ "engines": {
82
+ "node": ">=20"
83
+ }
84
+ }