@xeno-js/pino 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Xeno.JS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,97 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
+ <img src="logo/logo.png" alt="Xeno.JS Logo" width="140" />
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+ <h1>Xeno.JS Pino</h1>
5
+ <p><strong>A Typescript application framework architecture for Node.js, designed for lower technical debt, and faster infrastructure migrations.</strong></p>
6
+ <p>Build long-lived applications with explicit dependency injection, DDD, CQRS, and transport-independent business logic.</p>
7
+
8
+ <p>
9
+ <a href="https://www.npmjs.com/package/@xeno-js/pino"><img src="https://img.shields.io/npm/v/@xeno-js/pino?style=flat-square" alt="NPM Version" /></a>
10
+ <a href="https://github.com/xeno-js/pino"><img src="https://img.shields.io/badge/Powered%20by-Xeno-blueviolet?style=flat-square" alt="Powered by Xeno" /></a>
11
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="License: MIT" /></a>
12
+ <a href="https://buymeacoffee.com/xenojs">
13
+ <img src="https://img.shields.io/badge/Buy%20Me%20A%20Coffee-Support-FFdd00?style=flat-square&logo=buy-me-a-coffee&logoColor=black" alt="Buy Me A Coffee" />
14
+ </a>
15
+ </p>
16
+ </div>
17
+
18
+ ---
19
+
20
+ ---
21
+
22
+ `@xeno-js/pino` integrates [Pino](https://github.com/pinojs/pino) as the structured logging provider for the Xeno.JS ecosystem. It acts as an adapter implementing core logging contracts, ensuring applications produce high-performance JSON logs with built-in data masking.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ npm install @xeno-js/pino pino pino-pretty
28
+
29
+ ```
30
+
31
+ The package requires `@xeno-js/core` and `@xeno-js/shared` as peer dependencies.
32
+
33
+ ---
34
+
35
+ ## 1. Logger Plugin Configuration and Pino Integration
36
+
37
+ **Problem.** Enterprise applications require fast, structured logging with built-in protection against leaking sensitive data (such as passwords, tokens, and authorization headers) into log files.
38
+
39
+ **Principle.** Logging infrastructure must be configured explicitly through the application builder, decoupling logging providers from business logic while enforcing global redaction and transport options.
40
+
41
+ **Mechanism.** The `withPinoLogger` function exposes a logger plugin that uses `PinoLoggerFactory` to instantiate a configured `PinoLogger` client, registering it into the framework via `LoggerSetup`.
42
+
43
+ **Implementation:**
44
+
45
+ ```ts
46
+ import { XenoAppBuilder } from '@xeno-js/core';
47
+ import { withPinoLogger } from '@xeno-js/pino';
48
+
49
+ const app = await new XenoAppBuilder()
50
+ .addLogger(
51
+ withPinoLogger((options, config) => {
52
+ options.isEnabled = true;
53
+ options.logLevel = 'info';
54
+ options.prettyPrint = true; // Useful for development
55
+ options.destination = 'stdout';
56
+ })
57
+ )
58
+ .build();
59
+
60
+ ```
61
+
62
+ **Behavior:** During bootstrap, the plugin evaluates configuration options, configures default and custom redaction paths (masking fields like `password`, `token`, and `authorization` with `[REDACTED]`), and directs output streams to either standard output or log files.
63
+
64
+ **Boundary:** This package handles logging serialization, formatting, and stream transport. It does not manage log aggregation services or external log collector daemons.
65
+
66
+ ---
67
+
68
+ ## 2. Structured Logging and Level Filtering (`PinoLogger`)
69
+
70
+ **Problem.** Unfiltered log verbosity impacts performance and fills log storage with low-priority debug events during production runs.
71
+
72
+ **Principle.** Log messages must be filtered based on minimum threshold levels and support structured context payloads alongside optional error objects.
73
+
74
+ **Mechanism:** `PinoLogger` implements the `ILoggerClient` interface, mapping severity levels (`DEBUG`, `INFO`, `WARN`, `ERROR`) and filtering out events below the configured `minLevel`. It normalizes error objects using Pino standard serializers.
75
+
76
+ **Implementation:**
77
+
78
+ The logger is resolved automatically by the framework or injected into services:
79
+
80
+ ```ts
81
+ import { TOKENS, LOG_LEVEL } from '@xeno-js/core';
82
+
83
+ // Inside a service or handler
84
+ const logger = container.resolve(TOKENS.LOGGER);
85
+ logger.track(LOG_LEVEL.INFO, 'User logged in successfully', { userId: 'usr_123' });
86
+
87
+ ```
88
+
89
+ **Behavior:** When `track` is invoked, `PinoLogger` checks if the message severity meets or exceeds the minimum threshold. If approved, it merges contextual data, appends serialized errors if present, and delegates output to the underlying Pino instance.
90
+
91
+ **Boundary:** `PinoLogger` translates application log calls into Pino format. It relies on the underlying Pino library for stream writing and output formatting.
92
+
93
+ ---
94
+
95
+ ## License
96
+
97
+ Released under the MIT [License](LICENSE).
package/dist/index.cjs ADDED
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ withPinoLogger: () => withPinoLogger
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/infrastructure/pino.plugin.ts
38
+ var import_core = require("@xeno-js/core");
39
+
40
+ // src/infrastructure/factories/pino-logger.factory.ts
41
+ var fs = __toESM(require("fs"), 1);
42
+ var path = __toESM(require("path"), 1);
43
+ var import_shared2 = require("@xeno-js/shared");
44
+ var import_pino = __toESM(require("pino"), 1);
45
+
46
+ // src/infrastructure/service/pino.logger.ts
47
+ var import_shared = require("@xeno-js/shared");
48
+ var PinoLogger = class {
49
+ /**
50
+ * Constructs a new instance of the PinoTransport class, which takes an optional minimum log level and an optional instance of the Pino logger. If no logger instance is provided, it initializes a new Pino logger with default settings. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.
51
+ * @param _logger The Pino logger instance used for logging messages.
52
+ * @param _minLevel The minimum log level for logging messages. Messages with a log level below this threshold will not be logged. Default is LOG_LEVEL.DEBUG.
53
+ *
54
+ * @author Xeno
55
+ * @version 1.0.0
56
+ * @since 2025-09-30
57
+ * @link https://github.com/xeno-js/xeno-js
58
+ */
59
+ constructor(_logger, _minLevel = import_shared.LOG_LEVEL.DEBUG) {
60
+ this._logger = _logger;
61
+ this._minLevel = _minLevel;
62
+ }
63
+ _logger;
64
+ _minLevel;
65
+ track(level, message, context, error = void 0) {
66
+ if (level < this._minLevel) return;
67
+ const payload = import_shared.Guards.isDefined(error) ? { ...context, error } : context;
68
+ switch (level) {
69
+ case import_shared.LOG_LEVEL.ERROR:
70
+ this._logger.error(payload ?? {}, message);
71
+ break;
72
+ case import_shared.LOG_LEVEL.WARN:
73
+ this._logger.warn(payload ?? {}, message);
74
+ break;
75
+ case import_shared.LOG_LEVEL.DEBUG:
76
+ this._logger.debug(payload ?? {}, message);
77
+ break;
78
+ default:
79
+ this._logger.info(payload ?? {}, message);
80
+ break;
81
+ }
82
+ }
83
+ };
84
+
85
+ // src/infrastructure/factories/pino-logger.factory.ts
86
+ var PinoLoggerFactory = class {
87
+ create(options) {
88
+ const minLevel = options.logLevel ?? import_shared2.LOG_LEVEL.DEBUG;
89
+ const defaultRedactPaths = [
90
+ "password",
91
+ "token",
92
+ "authorization",
93
+ "accessToken",
94
+ "refreshToken",
95
+ "secret",
96
+ "cookie",
97
+ "creditCard",
98
+ "*.password",
99
+ "*.token",
100
+ "headers.authorization",
101
+ "headers.cookie"
102
+ ];
103
+ const userRedact = import_shared2.Guards.isDefined(options.pinoOptions?.redact) ? import_shared2.Guards.isArray(options.pinoOptions.redact) ? options.pinoOptions.redact : options.pinoOptions.redact.paths : [];
104
+ const combinedRedact = Array.from(/* @__PURE__ */ new Set([
105
+ ...defaultRedactPaths,
106
+ ...options.redactPaths ?? [],
107
+ ...userRedact
108
+ ]));
109
+ const destStream = this.setDestStream(options);
110
+ const prettyPrint = options.prettyPrint ?? false;
111
+ const pinoStream = this.setPrettyPinoStream(prettyPrint, destStream);
112
+ const mergedOptions = {
113
+ level: import_shared2.Guards.isNumber(minLevel) ? this.mapLogLevelToString(minLevel) : minLevel,
114
+ ...options.pinoOptions,
115
+ redact: {
116
+ paths: combinedRedact,
117
+ censor: "[REDACTED]",
118
+ ...import_shared2.Guards.isObject(options.pinoOptions?.redact) ? options.pinoOptions.redact : {}
119
+ },
120
+ serializers: {
121
+ error: import_pino.default.stdSerializers.err,
122
+ err: import_pino.default.stdSerializers.err,
123
+ ...options.pinoOptions?.serializers ?? {}
124
+ }
125
+ };
126
+ return new PinoLogger((0, import_pino.default)(mergedOptions, pinoStream));
127
+ }
128
+ setPrettyPinoStream(prettyPrint, pinoStream) {
129
+ if (prettyPrint) {
130
+ return import_pino.default.transport({
131
+ target: "pino-pretty",
132
+ options: { translateTime: "SYS:standard" }
133
+ });
134
+ }
135
+ return pinoStream;
136
+ }
137
+ setDestStream(options) {
138
+ if (options.destination === "file") {
139
+ const logFilePath = options.filePath ?? path.join(process.cwd(), "logs", "app.log");
140
+ const logDir = path.dirname(logFilePath);
141
+ if (!fs.existsSync(logDir)) {
142
+ fs.mkdirSync(logDir, { recursive: true });
143
+ }
144
+ return import_pino.default.destination(logFilePath);
145
+ }
146
+ return import_pino.default.destination(1);
147
+ }
148
+ mapLogLevelToString(level) {
149
+ switch (level) {
150
+ case import_shared2.LOG_LEVEL.DEBUG:
151
+ return "debug";
152
+ case import_shared2.LOG_LEVEL.INFO:
153
+ return "info";
154
+ case import_shared2.LOG_LEVEL.WARN:
155
+ return "warn";
156
+ case import_shared2.LOG_LEVEL.ERROR:
157
+ return "error";
158
+ default:
159
+ return "info";
160
+ }
161
+ }
162
+ };
163
+
164
+ // src/infrastructure/pino.plugin.ts
165
+ var withPinoLogger = (setupAction) => {
166
+ return (0, import_core.definePlugin)("logger", (_builder, config, ctx) => {
167
+ if (!import_core.Guards.isDefined(ctx))
168
+ throw new Error("LoggerSetup is not defined.");
169
+ const options = {};
170
+ setupAction(options, config);
171
+ const isEnabled = options.isEnabled ?? true;
172
+ if (!isEnabled)
173
+ return;
174
+ ctx.addCustomLogger(() => new PinoLoggerFactory().create(options));
175
+ });
176
+ };
177
+ // Annotate the CommonJS export names for ESM import in node:
178
+ 0 && (module.exports = {
179
+ withPinoLogger
180
+ });
181
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/infrastructure/pino.plugin.ts","../src/infrastructure/factories/pino-logger.factory.ts","../src/infrastructure/service/pino.logger.ts"],"sourcesContent":["export { withPinoLogger } from './infrastructure/pino.plugin'\n","import type {\n IAppBuilder,\n IConfigurationService,\n ILoggerSetup,\n IXenoApplication,\n LoggerPlugin,\n SetupAction,\n XenoRegistry,\n} from '@xeno-js/core'\nimport { definePlugin, Guards } from '@xeno-js/core'\n\nimport { type ExtendedPinoOptions,PinoLoggerFactory } from './factories/pino-logger.factory'\n\n/**\n * @description Plugin for integrating Redis caching into an application. This plugin provides a convenient way to set up Redis caching with the specified configuration options. It leverages the RedisCacheFactory to create instances of RedisCache based on the provided configuration. The plugin also registers the RedisCacheFactory as a service in the application's dependency injection container.\n *\n * @author Xeno\n * @version 1.0.0\n * @since 2025-09-30\n * @link https://github.com/xeno-js/xeno-js\n */\nexport const withPinoLogger = <TRegistry extends XenoRegistry = XenoRegistry>(\n setupAction: SetupAction<ExtendedPinoOptions & { isEnabled?: boolean }, IConfigurationService>\n): LoggerPlugin<TRegistry> => {\n return definePlugin('logger', (_builder: IAppBuilder<TRegistry, IXenoApplication<TRegistry>>, config: IConfigurationService, ctx?: ILoggerSetup<TRegistry>) => {\n if (!Guards.isDefined(ctx))\n throw new Error('LoggerSetup is not defined.')\n\n const options: ExtendedPinoOptions & { isEnabled?: boolean } = { }\n setupAction(options, config)\n \n const isEnabled = options.isEnabled ?? true\n if(!isEnabled)\n return\n\n ctx.addCustomLogger(() => new PinoLoggerFactory().create(options))\n })\n}\n","import * as fs from 'node:fs'\r\nimport * as path from 'node:path'\r\n\r\nimport type { IFactory, ILoggerClient, LogLevel } from '@xeno-js/shared'\r\nimport { Guards, LOG_LEVEL } from '@xeno-js/shared'\r\nimport pino from 'pino'\r\nimport type SonicBoom from 'sonic-boom'\r\n\r\nimport { PinoLogger } from '../service/pino.logger'\r\n\r\nexport interface ExtendedPinoOptions {\r\n /**\r\n * @description Pino logger options for customizing the behavior of the Pino logger. This includes options like log level, redaction paths, and more. The options are passed to the Pino logger during initialization.\r\n * @type {pino.LoggerOptions}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n pinoOptions?: pino.LoggerOptions\r\n /**\r\n * @description Flag indicating whether to enable pretty printing for the Pino logger. When set to true, the logger will output log messages in a human-readable format, making it easier to read and debug. Pretty printing is useful during development and testing.\r\n * @type {boolean}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n prettyPrint?: boolean\r\n /**\r\n * @description log level string indicating the minimum log level to be captured by the Pino logger. The log level is defined in the LOG_LEVEL enum, which includes levels like 'debug', 'info', 'warn', 'error'. The logger will only capture log messages with a level equal to or higher than the specified minimum level. For example, if the logLevel is set to 'info', the logger will capture log messages with levels 'info', 'warn', and 'error', but not 'debug'.\r\n * @type {LogLevel}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n logLevel?: LogLevel\r\n /**\r\n * @description Array of redact paths for sensitive data. The redactPaths array contains strings representing the paths of sensitive data that should be redacted (masked) in the log messages. Redacting sensitive data helps protect sensitive information from being logged and potentially exposed. The redactPaths array allows specifying the paths of sensitive data that should be redacted. For example, if the redactPaths array contains ['password', 'creditCard'], any occurrences of 'password' and 'creditCard' in the log messages will be redacted.\r\n * @type {string[]}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n redactPaths?: string[]\r\n /**\r\n * @description Destination for log messages. The destination property specifies the destination for log messages. It can be either 'stdout' or 'file'. If set to 'stdout', log messages will be written to the standard output (console). If set to 'file', log messages will be written to a file specified by the filePath property. The destination property determines where the log messages will be written, providing flexibility in configuring the logging behavior.\r\n * @type {('stdout' | 'file')}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n destination?: 'stdout' | 'file'\r\n /**\r\n * @description File path for log messages. The filePath property specifies the file path where log messages will be written if the destination property is set to 'file'. It determines the location of the log file. The filePath property is only relevant when the destination property is set to 'file'.\r\n * @type {string} \r\n * @memberof ExtendedPinoOptions\r\n */\r\n filePath?: string\r\n}\r\n\r\n/**\r\n * @description Factory class responsible for creating instances of PinoLogger based on the provided configuration. It implements the IFactory interface, allowing for easy integration with dependency injection systems. The factory encapsulates the creation logic for the PinoLogger, including the initialization of the underlying Pino instance with the specified configuration options such as log level. This design promotes separation of concerns and allows for flexibility in managing PinoLogger instances across the application.\r\n * \r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js \r\n */\r\nexport class PinoLoggerFactory implements IFactory<\r\n ExtendedPinoOptions,\r\n ILoggerClient\r\n> {\r\n public create(options: ExtendedPinoOptions): ILoggerClient {\r\n const minLevel = options.logLevel ?? LOG_LEVEL.DEBUG\r\n\r\n const defaultRedactPaths = [\r\n 'password',\r\n 'token',\r\n 'authorization',\r\n 'accessToken',\r\n 'refreshToken',\r\n 'secret',\r\n 'cookie',\r\n 'creditCard',\r\n '*.password',\r\n '*.token',\r\n 'headers.authorization',\r\n 'headers.cookie'\r\n ]\r\n\r\n const userRedact = Guards.isDefined(options.pinoOptions?.redact)\r\n ? (Guards.isArray(options.pinoOptions.redact) ? options.pinoOptions.redact : options.pinoOptions.redact.paths)\r\n : []\r\n\r\n const combinedRedact = Array.from(new Set([\r\n ...defaultRedactPaths,\r\n ...(options.redactPaths ?? []),\r\n ...(userRedact)\r\n ]))\r\n\r\n const destStream = this.setDestStream(options)\r\n const prettyPrint = options.prettyPrint ?? false\r\n const pinoStream = this.setPrettyPinoStream(prettyPrint, destStream)\r\n\r\n const mergedOptions: pino.LoggerOptions = {\r\n level: Guards.isNumber(minLevel) ? this.mapLogLevelToString(minLevel) : minLevel,\r\n ...options.pinoOptions,\r\n redact: {\r\n paths: combinedRedact,\r\n censor: \"[REDACTED]\",\r\n ...(Guards.isObject(options.pinoOptions?.redact) ? options.pinoOptions.redact : {}),\r\n },\r\n serializers: {\r\n error: pino.stdSerializers.err,\r\n err: pino.stdSerializers.err,\r\n ...(options.pinoOptions?.serializers ?? {}),\r\n },\r\n }\r\n\r\n return new PinoLogger(pino(mergedOptions, pinoStream))\r\n }\r\n\r\n private setPrettyPinoStream(prettyPrint: boolean, pinoStream: SonicBoom) {\r\n if (prettyPrint) {\r\n return pino.transport({\r\n target: 'pino-pretty',\r\n options: { translateTime: 'SYS:standard' }\r\n })\r\n }\r\n return pinoStream\r\n }\r\n\r\n private setDestStream(options: ExtendedPinoOptions) {\r\n if (options.destination === 'file') {\r\n const logFilePath = options.filePath ?? path.join(process.cwd(), 'logs', 'app.log')\r\n const logDir = path.dirname(logFilePath)\r\n\r\n if (!fs.existsSync(logDir)) {\r\n fs.mkdirSync(logDir, { recursive: true })\r\n }\r\n return pino.destination(logFilePath)\r\n }\r\n return pino.destination(1)\r\n }\r\n\r\n private mapLogLevelToString(level: LogLevel): string {\r\n switch (level) {\r\n case LOG_LEVEL.DEBUG: return 'debug'\r\n case LOG_LEVEL.INFO: return 'info'\r\n case LOG_LEVEL.WARN: return 'warn'\r\n case LOG_LEVEL.ERROR: return 'error'\r\n default: return 'info'\r\n }\r\n }\r\n}\r\n\r\n","import type { ILoggerClient } from '@xeno-js/shared'\r\nimport type { LogLevel, Optional } from '@xeno-js/shared'\r\nimport { Guards, LOG_LEVEL } from '@xeno-js/shared'\r\nimport type { Logger } from 'pino'\r\n\r\n/**\r\n * @description Class that implements the ILoggerClient interface using the Pino logging library. This class serves as an adapter between the ILoggerClient interface and the Pino logging library, allowing the use of Pino as a logging provider within the application's architecture without directly coupling the code to the specific logging framework.\r\n * \r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js \r\n */\r\nexport class PinoLogger implements ILoggerClient {\r\n /**\r\n * Constructs a new instance of the PinoTransport class, which takes an optional minimum log level and an optional instance of the Pino logger. If no logger instance is provided, it initializes a new Pino logger with default settings. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.\r\n * @param _logger The Pino logger instance used for logging messages.\r\n * @param _minLevel The minimum log level for logging messages. Messages with a log level below this threshold will not be logged. Default is LOG_LEVEL.DEBUG.\r\n * \r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js \r\n */\r\n constructor(\r\n private readonly _logger: Logger,\r\n private readonly _minLevel: LogLevel = LOG_LEVEL.DEBUG,\r\n ) {}\r\n\r\n public track<T>(\r\n level: LogLevel,\r\n message: string,\r\n context: T,\r\n error: Optional<unknown> = undefined,\r\n ): void {\r\n if (level < this._minLevel) return\r\n\r\n const payload = Guards.isDefined(error) ? { ...context, error } : context\r\n\r\n switch (level) {\r\n case LOG_LEVEL.ERROR:\r\n this._logger.error(payload ?? {}, message)\r\n break\r\n case LOG_LEVEL.WARN:\r\n this._logger.warn(payload ?? {}, message)\r\n break\r\n case LOG_LEVEL.DEBUG:\r\n this._logger.debug(payload ?? {}, message)\r\n break\r\n default:\r\n this._logger.info(payload ?? {}, message)\r\n break\r\n }\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,kBAAqC;;;ACTrC,SAAoB;AACpB,WAAsB;AAGtB,IAAAA,iBAAkC;AAClC,kBAAiB;;;ACHjB,oBAAkC;AAW3B,IAAM,aAAN,MAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW/C,YACmB,SACA,YAAsB,wBAAU,OACjD;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA,EAGZ,MACL,OACA,SACA,SACA,Q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aAAO,0BAAa,UAAU,CAAC,UAA+D,QAA+B,QAAkC;AAC7J,QAAI,CAAC,mBAAO,UAAU,GAAG;AACvB,YAAM,IAAI,MAAM,6BAA6B;AAE/C,UAAM,UAAyD,CAAE;AACjE,gBAAY,SAAS,MAAM;AAE3B,UAAM,YAAY,QAAQ,aAAa;AACvC,QAAG,CAAC;AACF;AAEF,QAAI,gBAAgB,MAAM,IAAI,kBAAkB,EAAE,OAAO,OAAO,CAAC;AAAA,EACnE,CAAC;AACH;","names":["import_shared","pino"]}
@@ -0,0 +1,56 @@
1
+ import { XenoRegistry, SetupAction, IConfigurationService, LoggerPlugin } from '@xeno-js/core';
2
+ import { LogLevel } from '@xeno-js/shared';
3
+ import pino from 'pino';
4
+
5
+ interface ExtendedPinoOptions {
6
+ /**
7
+ * @description Pino logger options for customizing the behavior of the Pino logger. This includes options like log level, redaction paths, and more. The options are passed to the Pino logger during initialization.
8
+ * @type {pino.LoggerOptions}
9
+ * @memberof ExtendedPinoOptions
10
+ */
11
+ pinoOptions?: pino.LoggerOptions;
12
+ /**
13
+ * @description Flag indicating whether to enable pretty printing for the Pino logger. When set to true, the logger will output log messages in a human-readable format, making it easier to read and debug. Pretty printing is useful during development and testing.
14
+ * @type {boolean}
15
+ * @memberof ExtendedPinoOptions
16
+ */
17
+ prettyPrint?: boolean;
18
+ /**
19
+ * @description log level string indicating the minimum log level to be captured by the Pino logger. The log level is defined in the LOG_LEVEL enum, which includes levels like 'debug', 'info', 'warn', 'error'. The logger will only capture log messages with a level equal to or higher than the specified minimum level. For example, if the logLevel is set to 'info', the logger will capture log messages with levels 'info', 'warn', and 'error', but not 'debug'.
20
+ * @type {LogLevel}
21
+ * @memberof ExtendedPinoOptions
22
+ */
23
+ logLevel?: LogLevel;
24
+ /**
25
+ * @description Array of redact paths for sensitive data. The redactPaths array contains strings representing the paths of sensitive data that should be redacted (masked) in the log messages. Redacting sensitive data helps protect sensitive information from being logged and potentially exposed. The redactPaths array allows specifying the paths of sensitive data that should be redacted. For example, if the redactPaths array contains ['password', 'creditCard'], any occurrences of 'password' and 'creditCard' in the log messages will be redacted.
26
+ * @type {string[]}
27
+ * @memberof ExtendedPinoOptions
28
+ */
29
+ redactPaths?: string[];
30
+ /**
31
+ * @description Destination for log messages. The destination property specifies the destination for log messages. It can be either 'stdout' or 'file'. If set to 'stdout', log messages will be written to the standard output (console). If set to 'file', log messages will be written to a file specified by the filePath property. The destination property determines where the log messages will be written, providing flexibility in configuring the logging behavior.
32
+ * @type {('stdout' | 'file')}
33
+ * @memberof ExtendedPinoOptions
34
+ */
35
+ destination?: 'stdout' | 'file';
36
+ /**
37
+ * @description File path for log messages. The filePath property specifies the file path where log messages will be written if the destination property is set to 'file'. It determines the location of the log file. The filePath property is only relevant when the destination property is set to 'file'.
38
+ * @type {string}
39
+ * @memberof ExtendedPinoOptions
40
+ */
41
+ filePath?: string;
42
+ }
43
+
44
+ /**
45
+ * @description Plugin for integrating Redis caching into an application. This plugin provides a convenient way to set up Redis caching with the specified configuration options. It leverages the RedisCacheFactory to create instances of RedisCache based on the provided configuration. The plugin also registers the RedisCacheFactory as a service in the application's dependency injection container.
46
+ *
47
+ * @author Xeno
48
+ * @version 1.0.0
49
+ * @since 2025-09-30
50
+ * @link https://github.com/xeno-js/xeno-js
51
+ */
52
+ declare const withPinoLogger: <TRegistry extends XenoRegistry = XenoRegistry>(setupAction: SetupAction<ExtendedPinoOptions & {
53
+ isEnabled?: boolean;
54
+ }, IConfigurationService>) => LoggerPlugin<TRegistry>;
55
+
56
+ export { withPinoLogger };
@@ -0,0 +1,56 @@
1
+ import { XenoRegistry, SetupAction, IConfigurationService, LoggerPlugin } from '@xeno-js/core';
2
+ import { LogLevel } from '@xeno-js/shared';
3
+ import pino from 'pino';
4
+
5
+ interface ExtendedPinoOptions {
6
+ /**
7
+ * @description Pino logger options for customizing the behavior of the Pino logger. This includes options like log level, redaction paths, and more. The options are passed to the Pino logger during initialization.
8
+ * @type {pino.LoggerOptions}
9
+ * @memberof ExtendedPinoOptions
10
+ */
11
+ pinoOptions?: pino.LoggerOptions;
12
+ /**
13
+ * @description Flag indicating whether to enable pretty printing for the Pino logger. When set to true, the logger will output log messages in a human-readable format, making it easier to read and debug. Pretty printing is useful during development and testing.
14
+ * @type {boolean}
15
+ * @memberof ExtendedPinoOptions
16
+ */
17
+ prettyPrint?: boolean;
18
+ /**
19
+ * @description log level string indicating the minimum log level to be captured by the Pino logger. The log level is defined in the LOG_LEVEL enum, which includes levels like 'debug', 'info', 'warn', 'error'. The logger will only capture log messages with a level equal to or higher than the specified minimum level. For example, if the logLevel is set to 'info', the logger will capture log messages with levels 'info', 'warn', and 'error', but not 'debug'.
20
+ * @type {LogLevel}
21
+ * @memberof ExtendedPinoOptions
22
+ */
23
+ logLevel?: LogLevel;
24
+ /**
25
+ * @description Array of redact paths for sensitive data. The redactPaths array contains strings representing the paths of sensitive data that should be redacted (masked) in the log messages. Redacting sensitive data helps protect sensitive information from being logged and potentially exposed. The redactPaths array allows specifying the paths of sensitive data that should be redacted. For example, if the redactPaths array contains ['password', 'creditCard'], any occurrences of 'password' and 'creditCard' in the log messages will be redacted.
26
+ * @type {string[]}
27
+ * @memberof ExtendedPinoOptions
28
+ */
29
+ redactPaths?: string[];
30
+ /**
31
+ * @description Destination for log messages. The destination property specifies the destination for log messages. It can be either 'stdout' or 'file'. If set to 'stdout', log messages will be written to the standard output (console). If set to 'file', log messages will be written to a file specified by the filePath property. The destination property determines where the log messages will be written, providing flexibility in configuring the logging behavior.
32
+ * @type {('stdout' | 'file')}
33
+ * @memberof ExtendedPinoOptions
34
+ */
35
+ destination?: 'stdout' | 'file';
36
+ /**
37
+ * @description File path for log messages. The filePath property specifies the file path where log messages will be written if the destination property is set to 'file'. It determines the location of the log file. The filePath property is only relevant when the destination property is set to 'file'.
38
+ * @type {string}
39
+ * @memberof ExtendedPinoOptions
40
+ */
41
+ filePath?: string;
42
+ }
43
+
44
+ /**
45
+ * @description Plugin for integrating Redis caching into an application. This plugin provides a convenient way to set up Redis caching with the specified configuration options. It leverages the RedisCacheFactory to create instances of RedisCache based on the provided configuration. The plugin also registers the RedisCacheFactory as a service in the application's dependency injection container.
46
+ *
47
+ * @author Xeno
48
+ * @version 1.0.0
49
+ * @since 2025-09-30
50
+ * @link https://github.com/xeno-js/xeno-js
51
+ */
52
+ declare const withPinoLogger: <TRegistry extends XenoRegistry = XenoRegistry>(setupAction: SetupAction<ExtendedPinoOptions & {
53
+ isEnabled?: boolean;
54
+ }, IConfigurationService>) => LoggerPlugin<TRegistry>;
55
+
56
+ export { withPinoLogger };
package/dist/index.js ADDED
@@ -0,0 +1,144 @@
1
+ // src/infrastructure/pino.plugin.ts
2
+ import { definePlugin, Guards as Guards3 } from "@xeno-js/core";
3
+
4
+ // src/infrastructure/factories/pino-logger.factory.ts
5
+ import * as fs from "fs";
6
+ import * as path from "path";
7
+ import { Guards as Guards2, LOG_LEVEL as LOG_LEVEL2 } from "@xeno-js/shared";
8
+ import pino from "pino";
9
+
10
+ // src/infrastructure/service/pino.logger.ts
11
+ import { Guards, LOG_LEVEL } from "@xeno-js/shared";
12
+ var PinoLogger = class {
13
+ /**
14
+ * Constructs a new instance of the PinoTransport class, which takes an optional minimum log level and an optional instance of the Pino logger. If no logger instance is provided, it initializes a new Pino logger with default settings. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.
15
+ * @param _logger The Pino logger instance used for logging messages.
16
+ * @param _minLevel The minimum log level for logging messages. Messages with a log level below this threshold will not be logged. Default is LOG_LEVEL.DEBUG.
17
+ *
18
+ * @author Xeno
19
+ * @version 1.0.0
20
+ * @since 2025-09-30
21
+ * @link https://github.com/xeno-js/xeno-js
22
+ */
23
+ constructor(_logger, _minLevel = LOG_LEVEL.DEBUG) {
24
+ this._logger = _logger;
25
+ this._minLevel = _minLevel;
26
+ }
27
+ _logger;
28
+ _minLevel;
29
+ track(level, message, context, error = void 0) {
30
+ if (level < this._minLevel) return;
31
+ const payload = Guards.isDefined(error) ? { ...context, error } : context;
32
+ switch (level) {
33
+ case LOG_LEVEL.ERROR:
34
+ this._logger.error(payload ?? {}, message);
35
+ break;
36
+ case LOG_LEVEL.WARN:
37
+ this._logger.warn(payload ?? {}, message);
38
+ break;
39
+ case LOG_LEVEL.DEBUG:
40
+ this._logger.debug(payload ?? {}, message);
41
+ break;
42
+ default:
43
+ this._logger.info(payload ?? {}, message);
44
+ break;
45
+ }
46
+ }
47
+ };
48
+
49
+ // src/infrastructure/factories/pino-logger.factory.ts
50
+ var PinoLoggerFactory = class {
51
+ create(options) {
52
+ const minLevel = options.logLevel ?? LOG_LEVEL2.DEBUG;
53
+ const defaultRedactPaths = [
54
+ "password",
55
+ "token",
56
+ "authorization",
57
+ "accessToken",
58
+ "refreshToken",
59
+ "secret",
60
+ "cookie",
61
+ "creditCard",
62
+ "*.password",
63
+ "*.token",
64
+ "headers.authorization",
65
+ "headers.cookie"
66
+ ];
67
+ const userRedact = Guards2.isDefined(options.pinoOptions?.redact) ? Guards2.isArray(options.pinoOptions.redact) ? options.pinoOptions.redact : options.pinoOptions.redact.paths : [];
68
+ const combinedRedact = Array.from(/* @__PURE__ */ new Set([
69
+ ...defaultRedactPaths,
70
+ ...options.redactPaths ?? [],
71
+ ...userRedact
72
+ ]));
73
+ const destStream = this.setDestStream(options);
74
+ const prettyPrint = options.prettyPrint ?? false;
75
+ const pinoStream = this.setPrettyPinoStream(prettyPrint, destStream);
76
+ const mergedOptions = {
77
+ level: Guards2.isNumber(minLevel) ? this.mapLogLevelToString(minLevel) : minLevel,
78
+ ...options.pinoOptions,
79
+ redact: {
80
+ paths: combinedRedact,
81
+ censor: "[REDACTED]",
82
+ ...Guards2.isObject(options.pinoOptions?.redact) ? options.pinoOptions.redact : {}
83
+ },
84
+ serializers: {
85
+ error: pino.stdSerializers.err,
86
+ err: pino.stdSerializers.err,
87
+ ...options.pinoOptions?.serializers ?? {}
88
+ }
89
+ };
90
+ return new PinoLogger(pino(mergedOptions, pinoStream));
91
+ }
92
+ setPrettyPinoStream(prettyPrint, pinoStream) {
93
+ if (prettyPrint) {
94
+ return pino.transport({
95
+ target: "pino-pretty",
96
+ options: { translateTime: "SYS:standard" }
97
+ });
98
+ }
99
+ return pinoStream;
100
+ }
101
+ setDestStream(options) {
102
+ if (options.destination === "file") {
103
+ const logFilePath = options.filePath ?? path.join(process.cwd(), "logs", "app.log");
104
+ const logDir = path.dirname(logFilePath);
105
+ if (!fs.existsSync(logDir)) {
106
+ fs.mkdirSync(logDir, { recursive: true });
107
+ }
108
+ return pino.destination(logFilePath);
109
+ }
110
+ return pino.destination(1);
111
+ }
112
+ mapLogLevelToString(level) {
113
+ switch (level) {
114
+ case LOG_LEVEL2.DEBUG:
115
+ return "debug";
116
+ case LOG_LEVEL2.INFO:
117
+ return "info";
118
+ case LOG_LEVEL2.WARN:
119
+ return "warn";
120
+ case LOG_LEVEL2.ERROR:
121
+ return "error";
122
+ default:
123
+ return "info";
124
+ }
125
+ }
126
+ };
127
+
128
+ // src/infrastructure/pino.plugin.ts
129
+ var withPinoLogger = (setupAction) => {
130
+ return definePlugin("logger", (_builder, config, ctx) => {
131
+ if (!Guards3.isDefined(ctx))
132
+ throw new Error("LoggerSetup is not defined.");
133
+ const options = {};
134
+ setupAction(options, config);
135
+ const isEnabled = options.isEnabled ?? true;
136
+ if (!isEnabled)
137
+ return;
138
+ ctx.addCustomLogger(() => new PinoLoggerFactory().create(options));
139
+ });
140
+ };
141
+ export {
142
+ withPinoLogger
143
+ };
144
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/infrastructure/pino.plugin.ts","../src/infrastructure/factories/pino-logger.factory.ts","../src/infrastructure/service/pino.logger.ts"],"sourcesContent":["import type {\n IAppBuilder,\n IConfigurationService,\n ILoggerSetup,\n IXenoApplication,\n LoggerPlugin,\n SetupAction,\n XenoRegistry,\n} from '@xeno-js/core'\nimport { definePlugin, Guards } from '@xeno-js/core'\n\nimport { type ExtendedPinoOptions,PinoLoggerFactory } from './factories/pino-logger.factory'\n\n/**\n * @description Plugin for integrating Redis caching into an application. This plugin provides a convenient way to set up Redis caching with the specified configuration options. It leverages the RedisCacheFactory to create instances of RedisCache based on the provided configuration. The plugin also registers the RedisCacheFactory as a service in the application's dependency injection container.\n *\n * @author Xeno\n * @version 1.0.0\n * @since 2025-09-30\n * @link https://github.com/xeno-js/xeno-js\n */\nexport const withPinoLogger = <TRegistry extends XenoRegistry = XenoRegistry>(\n setupAction: SetupAction<ExtendedPinoOptions & { isEnabled?: boolean }, IConfigurationService>\n): LoggerPlugin<TRegistry> => {\n return definePlugin('logger', (_builder: IAppBuilder<TRegistry, IXenoApplication<TRegistry>>, config: IConfigurationService, ctx?: ILoggerSetup<TRegistry>) => {\n if (!Guards.isDefined(ctx))\n throw new Error('LoggerSetup is not defined.')\n\n const options: ExtendedPinoOptions & { isEnabled?: boolean } = { }\n setupAction(options, config)\n \n const isEnabled = options.isEnabled ?? true\n if(!isEnabled)\n return\n\n ctx.addCustomLogger(() => new PinoLoggerFactory().create(options))\n })\n}\n","import * as fs from 'node:fs'\r\nimport * as path from 'node:path'\r\n\r\nimport type { IFactory, ILoggerClient, LogLevel } from '@xeno-js/shared'\r\nimport { Guards, LOG_LEVEL } from '@xeno-js/shared'\r\nimport pino from 'pino'\r\nimport type SonicBoom from 'sonic-boom'\r\n\r\nimport { PinoLogger } from '../service/pino.logger'\r\n\r\nexport interface ExtendedPinoOptions {\r\n /**\r\n * @description Pino logger options for customizing the behavior of the Pino logger. This includes options like log level, redaction paths, and more. The options are passed to the Pino logger during initialization.\r\n * @type {pino.LoggerOptions}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n pinoOptions?: pino.LoggerOptions\r\n /**\r\n * @description Flag indicating whether to enable pretty printing for the Pino logger. When set to true, the logger will output log messages in a human-readable format, making it easier to read and debug. Pretty printing is useful during development and testing.\r\n * @type {boolean}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n prettyPrint?: boolean\r\n /**\r\n * @description log level string indicating the minimum log level to be captured by the Pino logger. The log level is defined in the LOG_LEVEL enum, which includes levels like 'debug', 'info', 'warn', 'error'. The logger will only capture log messages with a level equal to or higher than the specified minimum level. For example, if the logLevel is set to 'info', the logger will capture log messages with levels 'info', 'warn', and 'error', but not 'debug'.\r\n * @type {LogLevel}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n logLevel?: LogLevel\r\n /**\r\n * @description Array of redact paths for sensitive data. The redactPaths array contains strings representing the paths of sensitive data that should be redacted (masked) in the log messages. Redacting sensitive data helps protect sensitive information from being logged and potentially exposed. The redactPaths array allows specifying the paths of sensitive data that should be redacted. For example, if the redactPaths array contains ['password', 'creditCard'], any occurrences of 'password' and 'creditCard' in the log messages will be redacted.\r\n * @type {string[]}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n redactPaths?: string[]\r\n /**\r\n * @description Destination for log messages. The destination property specifies the destination for log messages. It can be either 'stdout' or 'file'. If set to 'stdout', log messages will be written to the standard output (console). If set to 'file', log messages will be written to a file specified by the filePath property. The destination property determines where the log messages will be written, providing flexibility in configuring the logging behavior.\r\n * @type {('stdout' | 'file')}\r\n * @memberof ExtendedPinoOptions\r\n */\r\n destination?: 'stdout' | 'file'\r\n /**\r\n * @description File path for log messages. The filePath property specifies the file path where log messages will be written if the destination property is set to 'file'. It determines the location of the log file. The filePath property is only relevant when the destination property is set to 'file'.\r\n * @type {string} \r\n * @memberof ExtendedPinoOptions\r\n */\r\n filePath?: string\r\n}\r\n\r\n/**\r\n * @description Factory class responsible for creating instances of PinoLogger based on the provided configuration. It implements the IFactory interface, allowing for easy integration with dependency injection systems. The factory encapsulates the creation logic for the PinoLogger, including the initialization of the underlying Pino instance with the specified configuration options such as log level. This design promotes separation of concerns and allows for flexibility in managing PinoLogger instances across the application.\r\n * \r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js \r\n */\r\nexport class PinoLoggerFactory implements IFactory<\r\n ExtendedPinoOptions,\r\n ILoggerClient\r\n> {\r\n public create(options: ExtendedPinoOptions): ILoggerClient {\r\n const minLevel = options.logLevel ?? LOG_LEVEL.DEBUG\r\n\r\n const defaultRedactPaths = [\r\n 'password',\r\n 'token',\r\n 'authorization',\r\n 'accessToken',\r\n 'refreshToken',\r\n 'secret',\r\n 'cookie',\r\n 'creditCard',\r\n '*.password',\r\n '*.token',\r\n 'headers.authorization',\r\n 'headers.cookie'\r\n ]\r\n\r\n const userRedact = Guards.isDefined(options.pinoOptions?.redact)\r\n ? (Guards.isArray(options.pinoOptions.redact) ? options.pinoOptions.redact : options.pinoOptions.redact.paths)\r\n : []\r\n\r\n const combinedRedact = Array.from(new Set([\r\n ...defaultRedactPaths,\r\n ...(options.redactPaths ?? []),\r\n ...(userRedact)\r\n ]))\r\n\r\n const destStream = this.setDestStream(options)\r\n const prettyPrint = options.prettyPrint ?? false\r\n const pinoStream = this.setPrettyPinoStream(prettyPrint, destStream)\r\n\r\n const mergedOptions: pino.LoggerOptions = {\r\n level: Guards.isNumber(minLevel) ? this.mapLogLevelToString(minLevel) : minLevel,\r\n ...options.pinoOptions,\r\n redact: {\r\n paths: combinedRedact,\r\n censor: \"[REDACTED]\",\r\n ...(Guards.isObject(options.pinoOptions?.redact) ? options.pinoOptions.redact : {}),\r\n },\r\n serializers: {\r\n error: pino.stdSerializers.err,\r\n err: pino.stdSerializers.err,\r\n ...(options.pinoOptions?.serializers ?? {}),\r\n },\r\n }\r\n\r\n return new PinoLogger(pino(mergedOptions, pinoStream))\r\n }\r\n\r\n private setPrettyPinoStream(prettyPrint: boolean, pinoStream: SonicBoom) {\r\n if (prettyPrint) {\r\n return pino.transport({\r\n target: 'pino-pretty',\r\n options: { translateTime: 'SYS:standard' }\r\n })\r\n }\r\n return pinoStream\r\n }\r\n\r\n private setDestStream(options: ExtendedPinoOptions) {\r\n if (options.destination === 'file') {\r\n const logFilePath = options.filePath ?? path.join(process.cwd(), 'logs', 'app.log')\r\n const logDir = path.dirname(logFilePath)\r\n\r\n if (!fs.existsSync(logDir)) {\r\n fs.mkdirSync(logDir, { recursive: true })\r\n }\r\n return pino.destination(logFilePath)\r\n }\r\n return pino.destination(1)\r\n }\r\n\r\n private mapLogLevelToString(level: LogLevel): string {\r\n switch (level) {\r\n case LOG_LEVEL.DEBUG: return 'debug'\r\n case LOG_LEVEL.INFO: return 'info'\r\n case LOG_LEVEL.WARN: return 'warn'\r\n case LOG_LEVEL.ERROR: return 'error'\r\n default: return 'info'\r\n }\r\n }\r\n}\r\n\r\n","import type { ILoggerClient } from '@xeno-js/shared'\r\nimport type { LogLevel, Optional } from '@xeno-js/shared'\r\nimport { Guards, LOG_LEVEL } from '@xeno-js/shared'\r\nimport type { Logger } from 'pino'\r\n\r\n/**\r\n * @description Class that implements the ILoggerClient interface using the Pino logging library. This class serves as an adapter between the ILoggerClient interface and the Pino logging library, allowing the use of Pino as a logging provider within the application's architecture without directly coupling the code to the specific logging framework.\r\n * \r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js \r\n */\r\nexport class PinoLogger implements ILoggerClient {\r\n /**\r\n * Constructs a new instance of the PinoTransport class, which takes an optional minimum log level and an optional instance of the Pino logger. If no logger instance is provided, it initializes a new Pino logger with default settings. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.\r\n * @param _logger The Pino logger instance used for logging messages.\r\n * @param _minLevel The minimum log level for logging messages. Messages with a log level below this threshold will not be logged. Default is LOG_LEVEL.DEBUG.\r\n * \r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js \r\n */\r\n constructor(\r\n private readonly _logger: Logger,\r\n private readonly _minLevel: LogLevel = LOG_LEVEL.DEBUG,\r\n ) {}\r\n\r\n public track<T>(\r\n level: LogLevel,\r\n message: string,\r\n context: T,\r\n error: Optional<unknown> = undefined,\r\n ): void {\r\n if (level < this._minLevel) return\r\n\r\n const payload = Guards.isDefined(error) ? { ...context, error } : context\r\n\r\n switch (level) {\r\n case LOG_LEVEL.ERROR:\r\n this._logger.error(payload ?? {}, message)\r\n break\r\n case LOG_LEVEL.WARN:\r\n this._logger.warn(payload ?? {}, message)\r\n break\r\n case LOG_LEVEL.DEBUG:\r\n this._logger.debug(payload ?? {}, message)\r\n break\r\n default:\r\n this._logger.info(payload ?? {}, message)\r\n break\r\n }\r\n }\r\n}\r\n"],"mappings":";AASA,SAAS,cAAc,UAAAA,eAAc;;;ACTrC,YAAY,QAAQ;AACpB,YAAY,UAAU;AAGtB,SAAS,UAAAC,SAAQ,aAAAC,kBAAiB;AAClC,OAAO,UAAU;;;ACHjB,SAAS,QAAQ,iBAAiB;AAW3B,IAAM,aAAN,MAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW/C,YACmB,SACA,YAAsB,UAAU,OACjD;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA,EAGZ,MACL,OACA,SACA,SACA,QAA2B,QACrB;AACN,QAAI,QAAQ,KAAK,UAAW;AAE5B,UAAM,UAAU,OAAO,UAAU,KAAK,IAAI,EAAE,GAAG,SAAS,MAAM,IAAI;AAElE,YAAQ,OAAO;AAAA,MACb,KAAK,UAAU;AACb,aAAK,QAAQ,MAAM,WAAW,CAAC,GAAG,OAAO;AACzC;AAAA,MACF,KAAK,UAAU;AACb,aAAK,QAAQ,KAAK,WAAW,CAAC,GAAG,OAAO;AACxC;AAAA,MACF,KAAK,UAAU;AACb,aAAK,QAAQ,MAAM,WAAW,CAAC,GAAG,OAAO;AACzC;AAAA,MACF;AACE,aAAK,QAAQ,KAAK,WAAW,CAAC,GAAG,OAAO;AACxC;AAAA,IACJ;AAAA,EACF;AACF;;;ADGO,IAAM,oBAAN,MAGL;AAAA,EACO,OAAO,SAA6C;AACzD,UAAM,WAAW,QAAQ,YAAYC,WAAU;AAE/C,UAAM,qBAAqB;AA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I,QAAQ,gBAAgB,QAAQ;AAClC,YAAM,cAAc,QAAQ,YAAiB,UAAK,QAAQ,IAAI,GAAG,QAAQ,SAAS;AAClF,YAAM,SAAc,aAAQ,WAAW;AAEvC,UAAI,CAAI,cAAW,MAAM,GAAG;AAC1B,QAAG,aAAU,QAAQ,EAAE,WAAW,KAAK,CAAC;AAAA,MAC1C;AACA,aAAO,KAAK,YAAY,WAAW;AAAA,IACrC;AACA,WAAO,KAAK,YAAY,CAAC;AAAA,EAC3B;AAAA,EAEQ,oBAAoB,OAAyB;AACnD,YAAQ,OAAO;AAAA,MACb,KAAKD,WAAU;AAAO,eAAO;AAAA,MAC7B,KAAKA,WAAU;AAAM,eAAO;AAAA,MAC5B,KAAKA,WAAU;AAAM,eAAO;AAAA,MAC5B,KAAKA,WAAU;AAAO,eAAO;AAAA,MAC7B;AAAS,eAAO;AAAA,IAClB;AAAA,EACF;AACF;;;AD1HO,IAAM,iBAAiB,CAC5B,gBAC4B;AAC5B,SAAO,aAAa,UAAU,CAAC,UAA+D,QAA+B,QAAkC;AAC7J,QAAI,CAACE,QAAO,UAAU,GAAG;AACvB,YAAM,IAAI,MAAM,6BAA6B;AAE/C,UAAM,UAAyD,CAAE;AACjE,gBAAY,SAAS,MAAM;AAE3B,UAAM,YAAY,QAAQ,aAAa;AACvC,QAAG,CAAC;AACF;AAEF,QAAI,gBAAgB,MAAM,IAAI,kBAAkB,EAAE,OAAO,OAAO,CAAC;AAAA,EACnE,CAAC;AACH;","names":["Guards","Guards","LOG_LEVEL","LOG_LEVEL","Guards","Guards"]}
package/package.json CHANGED
@@ -1,6 +1,105 @@
1
1
  {
2
2
  "name": "@xeno-js/pino",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "High-performance structured logging integration and Pino adapter for Xeno.js with automatic data redaction and TypeScript support.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/xeno-js/pino.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/xeno-js/pino/issues"
11
+ },
12
+ "homepage": "https://www.xeno-js.it",
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "registry": "https://registry.npmjs.org/"
30
+ },
31
+ "scripts": {
32
+ "build": "tsup",
33
+ "typecheck": "tsc -p tsconfig.json --noEmit",
34
+ "lint": "eslint --config eslint.config.mjs \"src/**/*.ts\" --max-warnings=0",
35
+ "lint:fix": "eslint --config eslint.config.mjs \"src/**/*.ts\" --fix --max-warnings=0",
36
+ "lint-staged": "lint-staged",
37
+ "commitlint": "commitlint",
38
+ "format": "prettier --write .",
39
+ "format:check": "prettier --check .",
40
+ "test": "vitest run",
41
+ "test:watch": "vitest",
42
+ "test:coverage": "vitest run --coverage",
43
+ "check": "npm run typecheck && npm run lint:fix && npm run test",
44
+ "verify:commit": "npm run lint-staged && npm run test",
45
+ "verify:push": "npm run check",
46
+ "prepare": "husky",
47
+ "changelog": "npx conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
48
+ "prepublishOnly": "npm run check && npm run build",
49
+ "release:patch": "npm version patch && npm run changelog && npm run prepublishOnly && npm publish",
50
+ "release:minor": "npm version minor && npm run changelog && npm run prepublishOnly && npm publish",
51
+ "release:major": "npm version major && npm run changelog && npm run prepublishOnly && npm publish"
52
+ },
53
+ "keywords": [
54
+ "xeno",
55
+ "xeno-js",
56
+ "xeno.js",
57
+ "pino",
58
+ "logger",
59
+ "logging",
60
+ "structured logging",
61
+ "json logger",
62
+ "redaction",
63
+ "typescript",
64
+ "typescript backend",
65
+ "nodejs",
66
+ "node.js",
67
+ "dependency injection",
68
+ "clean architecture",
69
+ "hexagonal architecture"
70
+ ],
71
+ "author": "Xeno",
72
+ "license": "MIT",
73
+ "engines": {
74
+ "node": ">=20.0.0"
75
+ },
76
+ "peerDependencies": {
77
+ "@xeno-js/core": "^4.0.0"
78
+ },
79
+ "devDependencies": {
80
+ "@commitlint/cli": "^21.2.3",
81
+ "@commitlint/config-conventional": "^21.2.3",
82
+ "@eslint/js": "^10.0.1",
83
+ "@types/pg": "^8.23.1",
84
+ "@vitest/coverage-v8": "^5.0.1",
85
+ "@xeno-js/core": "^4.0.0",
86
+ "conventional-changelog": "^8.1.3",
87
+ "conventional-changelog-angular": "^9.4.0",
88
+ "conventional-changelog-cli": "^5.0.0",
89
+ "conventional-changelog-writer": "^9.2.1",
90
+ "eslint": "^10.11.0",
91
+ "eslint-config-prettier": "^10.1.8",
92
+ "eslint-plugin-simple-import-sort": "^14.0.0",
93
+ "husky": "^9.1.7",
94
+ "lint-staged": "^17.5.1",
95
+ "prettier": "^3.9.9",
96
+ "tsc-alias": "^1.9.5",
97
+ "tsup": "^8.5.1",
98
+ "typescript": "^5.8.0",
99
+ "typescript-eslint": "^8.70.1",
100
+ "vitest": "^5.0.1"
101
+ },
102
+ "dependencies": {
103
+ "pino": "^10.4.0"
104
+ }
105
+ }