@infosel-sdk/logger 0.1.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.
Files changed (47) hide show
  1. package/README.md +233 -0
  2. package/package.json +51 -0
  3. package/src/data/datasources/console_logger_datasource.d.ts +31 -0
  4. package/src/data/datasources/console_logger_datasource.js +96 -0
  5. package/src/data/datasources/console_logger_datasource.js.map +1 -0
  6. package/src/data/datasources/pino_logger_datasource.d.ts +32 -0
  7. package/src/data/datasources/pino_logger_datasource.js +103 -0
  8. package/src/data/datasources/pino_logger_datasource.js.map +1 -0
  9. package/src/data/di/logger_component_impl.d.ts +13 -0
  10. package/src/data/di/logger_component_impl.js +103 -0
  11. package/src/data/di/logger_component_impl.js.map +1 -0
  12. package/src/data/repositories/logger_repository_impl.d.ts +34 -0
  13. package/src/data/repositories/logger_repository_impl.js +58 -0
  14. package/src/data/repositories/logger_repository_impl.js.map +1 -0
  15. package/src/domain/datasources/logger_datasource.d.ts +16 -0
  16. package/src/domain/datasources/logger_datasource.js +3 -0
  17. package/src/domain/datasources/logger_datasource.js.map +1 -0
  18. package/src/domain/di/logger_component.d.ts +127 -0
  19. package/src/domain/di/logger_component.js +3 -0
  20. package/src/domain/di/logger_component.js.map +1 -0
  21. package/src/domain/entities/error_types.d.ts +39 -0
  22. package/src/domain/entities/error_types.js +6 -0
  23. package/src/domain/entities/error_types.js.map +1 -0
  24. package/src/domain/entities/index.d.ts +3 -0
  25. package/src/domain/entities/index.js +7 -0
  26. package/src/domain/entities/index.js.map +1 -0
  27. package/src/domain/entities/log_entry.d.ts +13 -0
  28. package/src/domain/entities/log_entry.js +3 -0
  29. package/src/domain/entities/log_entry.js.map +1 -0
  30. package/src/domain/entities/log_level.d.ts +13 -0
  31. package/src/domain/entities/log_level.js +23 -0
  32. package/src/domain/entities/log_level.js.map +1 -0
  33. package/src/domain/entities/logger_config.d.ts +52 -0
  34. package/src/domain/entities/logger_config.js +18 -0
  35. package/src/domain/entities/logger_config.js.map +1 -0
  36. package/src/domain/repositories/logger_repository.d.ts +47 -0
  37. package/src/domain/repositories/logger_repository.js +3 -0
  38. package/src/domain/repositories/logger_repository.js.map +1 -0
  39. package/src/domain/use_cases/log_error.d.ts +57 -0
  40. package/src/domain/use_cases/log_error.js +143 -0
  41. package/src/domain/use_cases/log_error.js.map +1 -0
  42. package/src/domain/use_cases/log_message.d.ts +21 -0
  43. package/src/domain/use_cases/log_message.js +29 -0
  44. package/src/domain/use_cases/log_message.js.map +1 -0
  45. package/src/index.d.ts +13 -0
  46. package/src/index.js +21 -0
  47. package/src/index.js.map +1 -0
package/README.md ADDED
@@ -0,0 +1,233 @@
1
+ # @infosel-sdk/logger
2
+
3
+ Logger SDK for Infosel financial services platform. Provides structured logging functionality powered by Pino for production-grade logging with Grafana integration.
4
+
5
+ ## Features
6
+
7
+ - **Multiple Log Levels**: debug, info, warn, error
8
+ - **Structured Logging**: Service, context, and metadata support
9
+ - **Pino Integration**: High-performance JSON logging
10
+ - **Grafana Ready**: Optimized for Loki/Grafana visualization
11
+ - **Context Tracking**: Track events like login, reconnection, retransmission
12
+ - **TypeScript Support**: Full type definitions included
13
+ - **Dual Output**: Pretty print for development, JSON for production
14
+ - **Production Ready**: Battle-tested logging for production environments
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @infosel-sdk/logger
20
+ ```
21
+
22
+ Or install from a local .tgz file:
23
+
24
+ ```bash
25
+ npm install ./infosel-sdk-logger-0.0.1.tgz
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ### Production Usage (with Pino - For Grafana)
31
+
32
+ ```typescript
33
+ import InfoselLogger from '@infosel-sdk/logger';
34
+ import { LogLevel } from '@infosel-sdk/logger';
35
+
36
+ // Initialize logger with Pino for production
37
+ const logger = InfoselLogger.createLogger({
38
+ usePino: true,
39
+ prettyPrint: false, // JSON output for Grafana/Loki
40
+ minLevel: LogLevel.INFO,
41
+ service: 'my-nextjs-app',
42
+ });
43
+
44
+ // Log with structured data
45
+ logger.log(LogLevel.INFO, 'User successfully logged in', {
46
+ service: 'auth-service',
47
+ context: 'login',
48
+ metadata: {
49
+ userId: '123',
50
+ method: 'oauth',
51
+ ip: '192.168.1.1'
52
+ }
53
+ });
54
+
55
+ // Output (JSON for Grafana):
56
+ // {
57
+ // "level": "INFO",
58
+ // "time": "2024-11-27T10:30:45.123Z",
59
+ // "service": "auth-service",
60
+ // "context": "login",
61
+ // "userId": "123",
62
+ // "method": "oauth",
63
+ // "ip": "192.168.1.1",
64
+ // "msg": "User successfully logged in"
65
+ // }
66
+ ```
67
+
68
+ ### Métodos Convenientes por Nivel
69
+
70
+ Cada nivel tiene su propio método para facilitar el uso:
71
+
72
+ ```typescript
73
+ const logger = InfoselLogger.createLogger({
74
+ usePino: true,
75
+ prettyPrint: true, // Pretty print para desarrollo
76
+ minLevel: LogLevel.DEBUG,
77
+ service: 'my-app',
78
+ });
79
+
80
+ // ✅ logger.info() - Información general (más usado)
81
+ logger.info('User logged in', {
82
+ service: 'auth-service',
83
+ context: 'login',
84
+ metadata: {
85
+ userId: '123',
86
+ email: 'user@example.com',
87
+ method: 'oauth'
88
+ }
89
+ });
90
+
91
+ // ✅ logger.warn() - Advertencias (reconexiones, retransmisiones)
92
+ logger.warn('WebSocket reconnecting', {
93
+ service: 'websocket-service',
94
+ context: 'reconnection',
95
+ metadata: {
96
+ attempt: 1,
97
+ maxAttempts: 5,
98
+ reason: 'network_timeout'
99
+ }
100
+ });
101
+
102
+ // ✅ logger.error() - Errores críticos
103
+ logger.error('Database connection failed', {
104
+ service: 'database-service',
105
+ context: 'connection',
106
+ metadata: {
107
+ errorMessage: 'Connection timeout',
108
+ errorStack: error.stack,
109
+ host: 'db.prod.com',
110
+ retries: 3
111
+ }
112
+ });
113
+
114
+ // ✅ logger.debug() - Debugging detallado (solo desarrollo)
115
+ logger.debug('Cache lookup performed', {
116
+ service: 'cache-service',
117
+ context: 'cache-lookup',
118
+ metadata: {
119
+ key: 'user:123',
120
+ hit: true,
121
+ ttl: 3600
122
+ }
123
+ });
124
+ ```
125
+
126
+ ### Configuration Options
127
+
128
+ ```typescript
129
+ interface LoggerConfig {
130
+ minLevel?: LogLevel; // Minimum log level: 'debug' | 'info' | 'warn' | 'error'
131
+ enableTimestamps?: boolean; // Include timestamps in logs
132
+ enableColors?: boolean; // Enable colored console output
133
+ prefix?: string; // Custom prefix for all log messages
134
+ service?: string; // Service or module name (e.g., 'auth-service')
135
+ usePino?: boolean; // Use Pino for logging (recommended for production)
136
+ prettyPrint?: boolean; // Pretty print output (for development)
137
+ outputFn?: (msg: string) => void; // Custom output function
138
+ }
139
+
140
+ interface LogOptions {
141
+ service?: string; // Override service name
142
+ context?: string; // Event context (login, reconnection, etc.)
143
+ metadata?: Record<string, unknown>; // Additional structured data
144
+ }
145
+ ```
146
+
147
+ ### Log Levels
148
+
149
+ - **DEBUG**: Detailed information for debugging
150
+ - **INFO**: General informational messages
151
+ - **WARN**: Warning messages for potentially harmful situations
152
+ - **ERROR**: Error messages for serious problems
153
+
154
+ ### Log Structure
155
+
156
+ Each log includes:
157
+ - **Timestamp**: ISO 8601 format
158
+ - **Level**: Log level (INFO, WARN, ERROR, DEBUG)
159
+ - **Service**: Service or module name
160
+ - **Context**: Event context (login, reconnection, retransmission, etc.)
161
+ - **Message**: Clear, descriptive message
162
+ - **Metadata**: Additional structured data
163
+
164
+ ### Common Contexts
165
+
166
+ - **login**: User authentication events
167
+ - **logout**: User logout events
168
+ - **reconnection**: WebSocket/connection reconnection attempts
169
+ - **retransmission**: Message queue retransmission events
170
+ - **http-request**: API request/response
171
+ - **connection**: Database/service connections
172
+ - **data-fetch**: Data fetching operations
173
+
174
+ ## Examples
175
+
176
+ ### Next.js Integration
177
+
178
+ See [examples/nextjs-integration.ts](./examples/nextjs-integration.ts) for complete Next.js examples including:
179
+ - API Routes logging
180
+ - WebSocket reconnection tracking
181
+ - Message queue retransmission
182
+ - Error boundary logging
183
+
184
+ ### Log Output Examples
185
+
186
+ See [examples/LOG_OUTPUT_EXAMPLES.md](./examples/LOG_OUTPUT_EXAMPLES.md) for:
187
+ - JSON output examples (for Grafana)
188
+ - Pretty print examples (for development)
189
+ - Real-world use cases
190
+
191
+ ### Grafana Integration
192
+
193
+ See [examples/GRAFANA_INTEGRATION.md](./examples/GRAFANA_INTEGRATION.md) for:
194
+ - Docker Compose configuration
195
+ - Loki setup
196
+ - Grafana dashboards
197
+ - LogQL queries
198
+ - Alerts configuration
199
+
200
+ ## Building
201
+
202
+ Run `nx build logger` to build the library.
203
+
204
+ ## Running unit tests
205
+
206
+ Run `nx test logger` to execute the unit tests via [Jest](https://jestjs.io).
207
+
208
+ ## Creating a Package
209
+
210
+ To create a .tgz file for distribution:
211
+
212
+ ```bash
213
+ nx build logger
214
+ cd dist/packages/logger
215
+ npm pack
216
+ ```
217
+
218
+ This will create `infosel-sdk-logger-0.0.1.tgz` that you can install in other projects.
219
+
220
+ ## Documentation
221
+
222
+ - **[README.md](./README.md)** - This file
223
+ - **[LOG_OUTPUT_EXAMPLES.md](./examples/LOG_OUTPUT_EXAMPLES.md)** - Log output examples
224
+ - **[nextjs-integration.ts](./examples/nextjs-integration.ts)** - Next.js integration examples
225
+ - **[GRAFANA_INTEGRATION.md](./examples/GRAFANA_INTEGRATION.md)** - Grafana setup guide
226
+ - **[INSTALLATION.md](./INSTALLATION.md)** - Installation and deployment guide
227
+ - **[CHANGELOG.md](./CHANGELOG.md)** - Version history
228
+
229
+ ## License
230
+
231
+ MIT
232
+
233
+
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@infosel-sdk/logger",
3
+ "version": "0.1.0",
4
+ "description": "Logger SDK for Infosel financial services platform. Provides structured logging with Pino integration, optimized for Grafana/Loki visualization with service, context, and metadata support.",
5
+ "keywords": [
6
+ "infosel",
7
+ "sdk",
8
+ "logger",
9
+ "logging",
10
+ "pino",
11
+ "grafana",
12
+ "loki",
13
+ "structured-logging",
14
+ "observability",
15
+ "monitoring",
16
+ "debug",
17
+ "typescript"
18
+ ],
19
+ "author": "Infosel Team",
20
+ "license": "MIT",
21
+ "scripts": {
22
+ "test": "jest",
23
+ "test:coverage": "jest --coverage"
24
+ },
25
+ "dependencies": {
26
+ "pino": "^9.5.0",
27
+ "pino-pretty": "^11.3.0",
28
+ "tslib": "^2.8.1"
29
+ },
30
+ "peerDependencies": {
31
+ "@infosel-sdk/core": "^0.0.5"
32
+ },
33
+ "devDependencies": {
34
+ "@types/jest": "^29.4.0",
35
+ "jest": "^29.4.1",
36
+ "ts-jest": "^29.1.0"
37
+ },
38
+ "type": "commonjs",
39
+ "main": "./src/index.js",
40
+ "types": "./src/index.d.ts",
41
+ "files": [
42
+ "src/**/*",
43
+ "README.md"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "engines": {
49
+ "node": ">=16.0.0"
50
+ }
51
+ }
@@ -0,0 +1,31 @@
1
+ import { LoggerDataSource } from '../../domain/datasources/logger_datasource';
2
+ import { LogEntry } from '../../domain/entities/log_entry';
3
+ import { LoggerConfig } from '../../domain/entities/logger_config';
4
+ /**
5
+ * Console implementation of logger data source
6
+ */
7
+ export declare class ConsoleLoggerDataSource implements LoggerDataSource {
8
+ private config;
9
+ private readonly colors;
10
+ constructor(config?: LoggerConfig);
11
+ /**
12
+ * Log an entry to console
13
+ */
14
+ log(entry: LogEntry): void;
15
+ /**
16
+ * Check if a log level is enabled
17
+ */
18
+ isLevelEnabled(level: string): boolean;
19
+ /**
20
+ * Update logger configuration
21
+ */
22
+ updateConfig(config: Partial<LoggerConfig>): void;
23
+ /**
24
+ * Format log message
25
+ */
26
+ private formatMessage;
27
+ /**
28
+ * Format timestamp
29
+ */
30
+ private formatTimestamp;
31
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleLoggerDataSource = void 0;
4
+ const log_level_1 = require("../../domain/entities/log_level");
5
+ const logger_config_1 = require("../../domain/entities/logger_config");
6
+ /**
7
+ * Console implementation of logger data source
8
+ */
9
+ class ConsoleLoggerDataSource {
10
+ constructor(config) {
11
+ // ANSI color codes
12
+ this.colors = {
13
+ reset: '\x1b[0m',
14
+ debug: '\x1b[36m',
15
+ info: '\x1b[32m',
16
+ warn: '\x1b[33m',
17
+ error: '\x1b[31m',
18
+ timestamp: '\x1b[90m',
19
+ metadata: '\x1b[35m', // Magenta
20
+ };
21
+ this.config = Object.assign(Object.assign({}, logger_config_1.DEFAULT_LOGGER_CONFIG), config);
22
+ }
23
+ /**
24
+ * Log an entry to console
25
+ */
26
+ log(entry) {
27
+ if (!this.isLevelEnabled(entry.level)) {
28
+ return;
29
+ }
30
+ const message = this.formatMessage(entry);
31
+ const outputFn = this.config.outputFn || console.log;
32
+ outputFn(message);
33
+ }
34
+ /**
35
+ * Check if a log level is enabled
36
+ */
37
+ isLevelEnabled(level) {
38
+ const currentLevel = log_level_1.LOG_LEVEL_PRIORITY[this.config.minLevel];
39
+ const checkLevel = log_level_1.LOG_LEVEL_PRIORITY[level];
40
+ return checkLevel >= currentLevel;
41
+ }
42
+ /**
43
+ * Update logger configuration
44
+ */
45
+ updateConfig(config) {
46
+ this.config = Object.assign(Object.assign({}, this.config), config);
47
+ }
48
+ /**
49
+ * Format log message
50
+ */
51
+ formatMessage(entry) {
52
+ const parts = [];
53
+ // Add timestamp
54
+ if (this.config.enableTimestamps) {
55
+ const timestamp = this.formatTimestamp(entry.timestamp);
56
+ parts.push(this.config.enableColors
57
+ ? `${this.colors.timestamp}${timestamp}${this.colors.reset}`
58
+ : timestamp);
59
+ }
60
+ // Add log level
61
+ const levelStr = `[${entry.level.toUpperCase()}]`;
62
+ if (this.config.enableColors) {
63
+ const color = this.colors[entry.level] || this.colors.reset;
64
+ parts.push(`${color}${levelStr}${this.colors.reset}`);
65
+ }
66
+ else {
67
+ parts.push(levelStr);
68
+ }
69
+ // Add prefix
70
+ if (entry.prefix || this.config.prefix) {
71
+ const prefix = entry.prefix || this.config.prefix;
72
+ parts.push(`[${prefix}]`);
73
+ }
74
+ // Add message
75
+ parts.push(entry.message);
76
+ // Add metadata
77
+ if (entry.metadata && Object.keys(entry.metadata).length > 0) {
78
+ const metadataStr = JSON.stringify(entry.metadata, null, 2);
79
+ if (this.config.enableColors) {
80
+ parts.push(`${this.colors.metadata}${metadataStr}${this.colors.reset}`);
81
+ }
82
+ else {
83
+ parts.push(metadataStr);
84
+ }
85
+ }
86
+ return parts.join(' ');
87
+ }
88
+ /**
89
+ * Format timestamp
90
+ */
91
+ formatTimestamp(date) {
92
+ return date.toISOString();
93
+ }
94
+ }
95
+ exports.ConsoleLoggerDataSource = ConsoleLoggerDataSource;
96
+ //# sourceMappingURL=console_logger_datasource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console_logger_datasource.js","sourceRoot":"","sources":["../../../../../../packages/logger/src/data/datasources/console_logger_datasource.ts"],"names":[],"mappings":";;;AAEA,+DAA+E;AAC/E,uEAG6C;AAE7C;;GAEG;AACH,MAAa,uBAAuB;IAgBlC,YAAY,MAAqB;QAXjC,mBAAmB;QACF,WAAM,GAAG;YACxB,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,UAAU;YACjB,SAAS,EAAE,UAAU;YACrB,QAAQ,EAAE,UAAU,EAAE,UAAU;SACjC,CAAC;QAGA,IAAI,CAAC,MAAM,mCACN,qCAAqB,GACrB,MAAM,CACV,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,KAAe;QACjB,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACrC,OAAO;SACR;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC;QAC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AAC,CAAC;SACtB;QAED,aAAa;QACb,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YACtC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YAClD,KAAK,CAAC,IAAI,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;SAC3B;QAED,cAAc;QACd,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE1B,eAAe;QACf,IAAI,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5D,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC5D,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;gBAC5B,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;aACzE;iBAAM;gBACL,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aACzB;SACF;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACK,eAAe,CAAC,IAAU;QAChC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;CACF;AA5GD,0DA4GC"}
@@ -0,0 +1,32 @@
1
+ import pino from 'pino';
2
+ import { LoggerDataSource } from '../../domain/datasources/logger_datasource';
3
+ import { LogEntry } from '../../domain/entities/log_entry';
4
+ import { LoggerConfig } from '../../domain/entities/logger_config';
5
+ /**
6
+ * Pino implementation of logger data source
7
+ */
8
+ export declare class PinoLoggerDataSource implements LoggerDataSource {
9
+ private config;
10
+ private pinoLogger;
11
+ constructor(config?: LoggerConfig);
12
+ /**
13
+ * Log an entry using Pino
14
+ */
15
+ log(entry: LogEntry): void;
16
+ /**
17
+ * Check if a log level is enabled
18
+ */
19
+ isLevelEnabled(level: string): boolean;
20
+ /**
21
+ * Update logger configuration
22
+ */
23
+ updateConfig(config: Partial<LoggerConfig>): void;
24
+ /**
25
+ * Get the Pino logger instance
26
+ */
27
+ getPinoInstance(): pino.Logger;
28
+ /**
29
+ * Map our log levels to Pino levels
30
+ */
31
+ private mapLogLevel;
32
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PinoLoggerDataSource = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pino_1 = tslib_1.__importDefault(require("pino"));
6
+ const log_level_1 = require("../../domain/entities/log_level");
7
+ const logger_config_1 = require("../../domain/entities/logger_config");
8
+ /**
9
+ * Pino implementation of logger data source
10
+ */
11
+ class PinoLoggerDataSource {
12
+ constructor(config) {
13
+ this.config = Object.assign(Object.assign({}, logger_config_1.DEFAULT_LOGGER_CONFIG), config);
14
+ // Configurar Pino
15
+ const pinoConfig = {
16
+ level: this.mapLogLevel(this.config.minLevel),
17
+ timestamp: this.config.enableTimestamps
18
+ ? pino_1.default.stdTimeFunctions.isoTime
19
+ : false,
20
+ formatters: {
21
+ level: label => {
22
+ return { level: label.toUpperCase() };
23
+ },
24
+ log: object => {
25
+ // Estructura personalizada para los logs
26
+ const { service, context } = object, rest = tslib_1.__rest(object, ["service", "context"]);
27
+ return Object.assign({ service: service || this.config.service || undefined, context: context || undefined }, rest);
28
+ },
29
+ },
30
+ };
31
+ // Agregar pretty print si está habilitado
32
+ if (this.config.prettyPrint) {
33
+ this.pinoLogger = (0, pino_1.default)(Object.assign(Object.assign({}, pinoConfig), { transport: {
34
+ target: 'pino-pretty',
35
+ options: {
36
+ colorize: this.config.enableColors,
37
+ translateTime: 'SYS:standard',
38
+ ignore: 'pid,hostname',
39
+ },
40
+ } }));
41
+ }
42
+ else {
43
+ this.pinoLogger = (0, pino_1.default)(pinoConfig);
44
+ }
45
+ }
46
+ /**
47
+ * Log an entry using Pino
48
+ */
49
+ log(entry) {
50
+ if (!this.isLevelEnabled(entry.level)) {
51
+ return;
52
+ }
53
+ const pinoLevel = this.mapLogLevel(entry.level);
54
+ // Construir el objeto de log con la estructura requerida
55
+ const logObject = Object.assign({ service: entry.service || this.config.service || undefined, context: entry.context || undefined }, (entry.metadata || {}));
56
+ // Remover campos undefined
57
+ Object.keys(logObject).forEach(key => {
58
+ if (logObject[key] === undefined) {
59
+ delete logObject[key];
60
+ }
61
+ });
62
+ // Log usando Pino
63
+ this.pinoLogger[pinoLevel](logObject, entry.message);
64
+ }
65
+ /**
66
+ * Check if a log level is enabled
67
+ */
68
+ isLevelEnabled(level) {
69
+ const currentLevel = log_level_1.LOG_LEVEL_PRIORITY[this.config.minLevel];
70
+ const checkLevel = log_level_1.LOG_LEVEL_PRIORITY[level];
71
+ return checkLevel >= currentLevel;
72
+ }
73
+ /**
74
+ * Update logger configuration
75
+ */
76
+ updateConfig(config) {
77
+ this.config = Object.assign(Object.assign({}, this.config), config);
78
+ // Actualizar nivel de Pino si cambió
79
+ if (config.minLevel) {
80
+ this.pinoLogger.level = this.mapLogLevel(config.minLevel);
81
+ }
82
+ }
83
+ /**
84
+ * Get the Pino logger instance
85
+ */
86
+ getPinoInstance() {
87
+ return this.pinoLogger;
88
+ }
89
+ /**
90
+ * Map our log levels to Pino levels
91
+ */
92
+ mapLogLevel(level) {
93
+ const levelMap = {
94
+ [log_level_1.LogLevel.DEBUG]: 'debug',
95
+ [log_level_1.LogLevel.INFO]: 'info',
96
+ [log_level_1.LogLevel.WARN]: 'warn',
97
+ [log_level_1.LogLevel.ERROR]: 'error',
98
+ };
99
+ return levelMap[level];
100
+ }
101
+ }
102
+ exports.PinoLoggerDataSource = PinoLoggerDataSource;
103
+ //# sourceMappingURL=pino_logger_datasource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pino_logger_datasource.js","sourceRoot":"","sources":["../../../../../../packages/logger/src/data/datasources/pino_logger_datasource.ts"],"names":[],"mappings":";;;;AAAA,wDAAwB;AAGxB,+DAA+E;AAC/E,uEAG6C;AAE7C;;GAEG;AACH,MAAa,oBAAoB;IAM/B,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,mCACN,qCAAqB,GACrB,MAAM,CACV,CAAC;QAEF,kBAAkB;QAClB,MAAM,UAAU,GAAuB;YACrC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YAC7C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAgB;gBACrC,CAAC,CAAC,cAAI,CAAC,gBAAgB,CAAC,OAAO;gBAC/B,CAAC,CAAC,KAAK;YACT,UAAU,EAAE;gBACV,KAAK,EAAE,KAAK,CAAC,EAAE;oBACb,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxC,CAAC;gBACD,GAAG,EAAE,MAAM,CAAC,EAAE;oBACZ,yCAAyC;oBACzC,MAAM,EAAE,OAAO,EAAE,OAAO,KAAc,MAAM,EAAf,IAAI,kBAAK,MAAM,EAAtC,sBAA6B,CAAS,CAAC;oBAC7C,uBACE,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,SAAS,EACpD,OAAO,EAAE,OAAO,IAAI,SAAS,IAC1B,IAAI,EACP;gBACJ,CAAC;aACF;SACF,CAAC;QAEF,0CAA0C;QAC1C,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;YAC3B,IAAI,CAAC,UAAU,GAAG,IAAA,cAAI,kCACjB,UAAU,KACb,SAAS,EAAE;oBACT,MAAM,EAAE,aAAa;oBACrB,OAAO,EAAE;wBACP,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;wBAClC,aAAa,EAAE,cAAc;wBAC7B,MAAM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EF,qCAAqC;QACrC,IAAI,MAAM,CAAC,QAAQ,EAAE;YACnB,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;SAC3D;IACH,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,KAAe;QACjC,MAAM,QAAQ,GAAiC;YAC7C,CAAC,oBAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;YACzB,CAAC,oBAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;YACvB,CAAC,oBAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;YACvB,CAAC,oBAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;SAC1B,CAAC;QACF,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;CACF;AA3HD,oDA2HC"}
@@ -0,0 +1,13 @@
1
+ import { LoggerComponent } from '../../domain/di/logger_component';
2
+ import { LoggerConfig } from '../../domain/entities/logger_config';
3
+ /**
4
+ * Factory to create a logger instance
5
+ */
6
+ declare const InfoselLogger: {
7
+ /**
8
+ * Create a new logger instance
9
+ * @param config Logger configuration
10
+ */
11
+ createLogger(config?: LoggerConfig): LoggerComponent;
12
+ };
13
+ export default InfoselLogger;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const log_message_1 = require("../../domain/use_cases/log_message");
4
+ const log_error_1 = require("../../domain/use_cases/log_error");
5
+ const console_logger_datasource_1 = require("../datasources/console_logger_datasource");
6
+ const pino_logger_datasource_1 = require("../datasources/pino_logger_datasource");
7
+ const logger_repository_impl_1 = require("../repositories/logger_repository_impl");
8
+ /**
9
+ * Implementation of logger component for dependency injection
10
+ */
11
+ class LoggerComponentImpl {
12
+ constructor(config) {
13
+ // Initialize data source based on configuration
14
+ const dataSource = (config === null || config === void 0 ? void 0 : config.usePino)
15
+ ? new pino_logger_datasource_1.PinoLoggerDataSource(config)
16
+ : new console_logger_datasource_1.ConsoleLoggerDataSource(config);
17
+ // Initialize repository
18
+ this.repository = new logger_repository_impl_1.LoggerRepositoryImpl(dataSource);
19
+ // Initialize use cases
20
+ this.logMessageUseCase = new log_message_1.LogMessage(this.repository);
21
+ this.logErrorUseCase = new log_error_1.LogError(this.repository);
22
+ }
23
+ /**
24
+ * Log a debug message
25
+ */
26
+ debug(message, options) {
27
+ this.repository.debug(message, options);
28
+ }
29
+ /**
30
+ * Log an info message
31
+ */
32
+ info(message, options) {
33
+ this.repository.info(message, options);
34
+ }
35
+ /**
36
+ * Log a warning message
37
+ */
38
+ warn(message, options) {
39
+ this.repository.warn(message, options);
40
+ }
41
+ /**
42
+ * Log an error message
43
+ */
44
+ error(message, options) {
45
+ this.repository.error(message, options);
46
+ }
47
+ /**
48
+ * Log a message with a specific level, service, and context
49
+ * This method uses Pino to generate structured logs with:
50
+ * - Timestamp (ISO 8601)
51
+ * - Log level (INFO, WARN, ERROR, DEBUG)
52
+ * - Service / Module name
53
+ * - Context of the event
54
+ * - Clear message
55
+ */
56
+ log(level, message, options) {
57
+ this.logMessageUseCase.execute(level, message, options);
58
+ }
59
+ /**
60
+ * Check if a log level is enabled
61
+ */
62
+ isLevelEnabled(level) {
63
+ return this.logMessageUseCase.isLevelEnabled(level);
64
+ }
65
+ /**
66
+ * Get the logger repository
67
+ */
68
+ getRepository() {
69
+ return this.repository;
70
+ }
71
+ /**
72
+ * Get the log message use case
73
+ */
74
+ getLogMessageUseCase() {
75
+ return this.logMessageUseCase;
76
+ }
77
+ /**
78
+ * Log an error with automatic type detection
79
+ */
80
+ logError(message, error, options) {
81
+ this.logErrorUseCase.execute(message, error, options);
82
+ }
83
+ /**
84
+ * Get the log error use case
85
+ */
86
+ getLogErrorUseCase() {
87
+ return this.logErrorUseCase;
88
+ }
89
+ }
90
+ /**
91
+ * Factory to create a logger instance
92
+ */
93
+ const InfoselLogger = {
94
+ /**
95
+ * Create a new logger instance
96
+ * @param config Logger configuration
97
+ */
98
+ createLogger(config) {
99
+ return new LoggerComponentImpl(config);
100
+ },
101
+ };
102
+ exports.default = InfoselLogger;
103
+ //# sourceMappingURL=logger_component_impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger_component_impl.js","sourceRoot":"","sources":["../../../../../../packages/logger/src/data/di/logger_component_impl.ts"],"names":[],"mappings":";;AAKA,oEAAgE;AAChE,gEAA4D;AAC5D,wFAAmF;AACnF,kFAA6E;AAC7E,mFAA8E;AAK9E;;GAEG;AACH,MAAM,mBAAmB;IAKvB,YAAY,MAAqB;QAC/B,gDAAgD;QAChD,MAAM,UAAU,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO;YAChC,CAAC,CAAC,IAAI,6CAAoB,CAAC,MAAM,CAAC;YAClC,CAAC,CAAC,IAAI,mDAAuB,CAAC,MAAM,CAAC,CAAC;QAExC,wBAAwB;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,6CAAoB,CAAC,UAAU,CAAC,CAAC;QAEvD,uBAAuB;QACvB,IAAI,CAAC,iBAAiB,GAAG,IAAI,wBAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,eAAe,GAAG,IAAI,oBAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAe,EAAE,OAAoB;QACzC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,OAAe,EAAE,OAAoB;QACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,OAAe,EAAE,OAAoB;QACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,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