@eqxjs/nest-logger 3.1.0-beta.9 → 3.1.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +57 -1
- package/MIGRATION.md +234 -0
- package/PERFORMANCE_IMPROVEMENTS.md +158 -0
- package/README.md +2008 -16
- package/RESTRUCTURING_SUMMARY.md +272 -0
- package/STRUCTURE.md +110 -0
- package/dist/constants/action-message.constant.d.ts +187 -0
- package/dist/constants/action-message.constant.js +220 -0
- package/dist/constants/action-message.constant.js.map +1 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +9 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/logger.constants.d.ts +17 -0
- package/dist/constants/logger.constants.js +20 -0
- package/dist/constants/logger.constants.js.map +1 -0
- package/dist/core/formatters/index.d.ts +1 -0
- package/dist/core/formatters/index.js +6 -0
- package/dist/core/formatters/index.js.map +1 -0
- package/dist/core/formatters/logger.formatter.d.ts +141 -0
- package/dist/core/formatters/logger.formatter.js +268 -0
- package/dist/core/formatters/logger.formatter.js.map +1 -0
- package/dist/core/loggers/app.logger.d.ts +46 -0
- package/dist/core/loggers/app.logger.js +92 -0
- package/dist/core/loggers/app.logger.js.map +1 -0
- package/dist/core/loggers/base-app.logger.d.ts +299 -0
- package/dist/core/loggers/base-app.logger.js +517 -0
- package/dist/core/loggers/base-app.logger.js.map +1 -0
- package/dist/core/loggers/custom.logger.d.ts +127 -0
- package/dist/core/loggers/custom.logger.js +260 -0
- package/dist/core/loggers/custom.logger.js.map +1 -0
- package/dist/core/loggers/index.d.ts +3 -0
- package/dist/core/loggers/index.js +10 -0
- package/dist/core/loggers/index.js.map +1 -0
- package/dist/helpers/datetime.helper.d.ts +24 -0
- package/dist/helpers/datetime.helper.js +36 -0
- package/dist/helpers/datetime.helper.js.map +1 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +17 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/log.helper.d.ts +84 -0
- package/dist/helpers/log.helper.js +109 -0
- package/dist/helpers/log.helper.js.map +1 -0
- package/dist/helpers/logger-builder.helper.d.ts +242 -0
- package/dist/helpers/logger-builder.helper.js +345 -0
- package/dist/helpers/logger-builder.helper.js.map +1 -0
- package/dist/helpers/message-formatter.helper.d.ts +88 -0
- package/dist/helpers/message-formatter.helper.js +159 -0
- package/dist/helpers/message-formatter.helper.js.map +1 -0
- package/dist/helpers/time-performance.helper.d.ts +68 -0
- package/dist/helpers/time-performance.helper.js +82 -0
- package/dist/helpers/time-performance.helper.js.map +1 -0
- package/dist/index.d.ts +13 -5
- package/dist/index.js +24 -9
- package/dist/index.js.map +1 -1
- package/dist/interfaces/data-header.interface.d.ts +21 -0
- package/dist/{dto/m2.dto.js → interfaces/data-header.interface.js} +1 -1
- package/dist/interfaces/data-header.interface.js.map +1 -0
- package/dist/interfaces/data-protocol.interface.d.ts +14 -0
- package/dist/interfaces/data-protocol.interface.js +3 -0
- package/dist/interfaces/data-protocol.interface.js.map +1 -0
- package/dist/interfaces/data-service.interface.d.ts +21 -0
- package/dist/{dto/m3.dto.js → interfaces/data-service.interface.js} +1 -1
- package/dist/interfaces/data-service.interface.js.map +1 -0
- package/dist/{types.d.ts → interfaces/data.interface.d.ts} +4 -4
- package/dist/{dto/m1.dto.js → interfaces/data.interface.js} +1 -1
- package/dist/interfaces/data.interface.js.map +1 -0
- package/dist/interfaces/index.d.ts +5 -0
- package/dist/{types.js → interfaces/index.js} +1 -1
- package/dist/interfaces/index.js.map +1 -0
- package/dist/{dto/header.dto.js → interfaces/logger-opt.interface.js} +1 -1
- package/dist/interfaces/logger-opt.interface.js.map +1 -0
- package/dist/logger.module.js +4 -4
- package/dist/logger.module.js.map +1 -1
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +6 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/logger.dto.d.ts +71 -0
- package/dist/models/logger.dto.js +76 -0
- package/dist/models/logger.dto.js.map +1 -0
- package/package.json +30 -33
- package/dist/dto/header.dto.d.ts +0 -21
- package/dist/dto/header.dto.js.map +0 -1
- package/dist/dto/logger.dto.d.ts +0 -28
- package/dist/dto/logger.dto.js +0 -33
- package/dist/dto/logger.dto.js.map +0 -1
- package/dist/dto/m1.dto.d.ts +0 -7
- package/dist/dto/m1.dto.js.map +0 -1
- package/dist/dto/m2.dto.d.ts +0 -5
- package/dist/dto/m2.dto.js.map +0 -1
- package/dist/dto/m3.dto.d.ts +0 -5
- package/dist/dto/m3.dto.js.map +0 -1
- package/dist/dto/protocol.dto.d.ts +0 -14
- package/dist/dto/protocol.dto.js +0 -3
- package/dist/dto/protocol.dto.js.map +0 -1
- package/dist/dto/service.dto.d.ts +0 -25
- package/dist/dto/service.dto.js +0 -3
- package/dist/dto/service.dto.js.map +0 -1
- package/dist/logger.app.d.ts +0 -62
- package/dist/logger.app.js +0 -504
- package/dist/logger.app.js.map +0 -1
- package/dist/logger.service.d.ts +0 -15
- package/dist/logger.service.js +0 -158
- package/dist/logger.service.js.map +0 -1
- package/dist/logger.util.d.ts +0 -3
- package/dist/logger.util.js +0 -28
- package/dist/logger.util.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/action.common.d.ts +0 -14
- package/dist/utils/action.common.js +0 -43
- package/dist/utils/action.common.js.map +0 -1
- package/dist/utils/datetime.util.d.ts +0 -1
- package/dist/utils/datetime.util.js +0 -13
- package/dist/utils/datetime.util.js.map +0 -1
- package/dist/utils/logger.opt.js +0 -3
- package/dist/utils/logger.opt.js.map +0 -1
- package/dist/utils/m1.utils.d.ts +0 -3
- package/dist/utils/m1.utils.js +0 -79
- package/dist/utils/m1.utils.js.map +0 -1
- package/dist/utils/time.performance.d.ts +0 -6
- package/dist/utils/time.performance.js +0 -18
- package/dist/utils/time.performance.js.map +0 -1
- /package/dist/{utils/logger.opt.d.ts → interfaces/logger-opt.interface.d.ts} +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { LoggerService } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* CustomLogger - Basic logger implementation with standard log levels.
|
|
4
|
+
*
|
|
5
|
+
* Implements NestJS LoggerService interface and uses Winston for actual logging.
|
|
6
|
+
* Provides simple logging methods (log, error, warn, debug, verbose) for basic use cases.
|
|
7
|
+
*
|
|
8
|
+
* For advanced structured logging with OpenTelemetry integration, use BaseAppLogger or AppLogger.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const logger = new CustomLogger('MyService');
|
|
13
|
+
* logger.log('Application started');
|
|
14
|
+
* logger.error('An error occurred', 'Error stack trace');
|
|
15
|
+
* logger.warn('Warning message');
|
|
16
|
+
* logger.debug('Debug information');
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @implements {LoggerService}
|
|
20
|
+
*/
|
|
21
|
+
export declare class CustomLogger implements LoggerService {
|
|
22
|
+
protected appName: string;
|
|
23
|
+
private logger;
|
|
24
|
+
protected readonly cachedHostname: string;
|
|
25
|
+
constructor();
|
|
26
|
+
constructor(appName?: string);
|
|
27
|
+
/**
|
|
28
|
+
* Formats a Date object to ISO 8601 string with UTC+7 timezone offset.
|
|
29
|
+
*
|
|
30
|
+
* @param date - The date to format
|
|
31
|
+
* @returns ISO 8601 formatted string (e.g., "2026-01-12T10:00:00.000Z")
|
|
32
|
+
* @protected
|
|
33
|
+
*/
|
|
34
|
+
protected dateFormat(date: Date): string;
|
|
35
|
+
/**
|
|
36
|
+
* Initializes a LoggerDto with basic log information.
|
|
37
|
+
*
|
|
38
|
+
* Creates a structured log entry from the provided message and parameters.
|
|
39
|
+
* Handles message formatting, truncation, and sets default values for required fields.
|
|
40
|
+
*
|
|
41
|
+
* @param level - Log level
|
|
42
|
+
* @param message - Log message (any type)
|
|
43
|
+
* @param optionalParams - Additional parameters (last parameter becomes componentName)
|
|
44
|
+
* @returns Initialized LoggerDto object
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
private initializeLogger;
|
|
48
|
+
/**
|
|
49
|
+
* Logs an informational message.
|
|
50
|
+
* Alias for standard console.log behavior in NestJS applications.
|
|
51
|
+
*
|
|
52
|
+
* @param message - Message to log (any type)
|
|
53
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* logger.log('User created successfully');
|
|
58
|
+
* logger.log('Request processed', 'UserController');
|
|
59
|
+
* logger.log({ userId: 123, action: 'create' });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
log(message: any, ...optionalParams: any[]): void;
|
|
63
|
+
/**
|
|
64
|
+
* Logs an error message.
|
|
65
|
+
* Use for logging error conditions and failures.
|
|
66
|
+
*
|
|
67
|
+
* @param message - Error message (any type)
|
|
68
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* logger.error('Database connection failed');
|
|
73
|
+
* logger.error('Query error', 'DatabaseService');
|
|
74
|
+
* logger.error(new Error('Something went wrong'));
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
error(message: any, ...optionalParams: any[]): void;
|
|
78
|
+
/**
|
|
79
|
+
* Logs a warning message.
|
|
80
|
+
* Use for potentially harmful situations or deprecated functionality.
|
|
81
|
+
*
|
|
82
|
+
* @param message - Warning message (any type)
|
|
83
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* logger.warn('API rate limit approaching');
|
|
88
|
+
* logger.warn('Using deprecated method', 'PaymentService');
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
warn(message: any, ...optionalParams: any[]): void;
|
|
92
|
+
/**
|
|
93
|
+
* Logs a debug message.
|
|
94
|
+
* Use for detailed diagnostic information during development.
|
|
95
|
+
*
|
|
96
|
+
* @param message - Debug message (any type)
|
|
97
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* logger.debug('Processing request payload');
|
|
102
|
+
* logger.debug({ requestId: '123', payload: data }, 'RequestHandler');
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
debug(message: any, ...optionalParams: any[]): void;
|
|
106
|
+
/**
|
|
107
|
+
* Logs a verbose message.
|
|
108
|
+
* Use for the most detailed information, typically only needed for deep debugging.
|
|
109
|
+
*
|
|
110
|
+
* @param message - Verbose message (any type)
|
|
111
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* logger.verbose('Internal state dump');
|
|
116
|
+
* logger.verbose({ state: internalState }, 'StateMachine');
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
verbose(message: any, ...optionalParams: any[]): void;
|
|
120
|
+
/**
|
|
121
|
+
* Flushes the log message to Winston logger.
|
|
122
|
+
*
|
|
123
|
+
* @param message - Message to be logged
|
|
124
|
+
* @protected
|
|
125
|
+
*/
|
|
126
|
+
protected flushLog(message: any): void;
|
|
127
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
+
};
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.CustomLogger = void 0;
|
|
52
|
+
const common_1 = require("@nestjs/common");
|
|
53
|
+
const moment_1 = __importDefault(require("moment"));
|
|
54
|
+
const os = __importStar(require("os"));
|
|
55
|
+
const winston = __importStar(require("winston"));
|
|
56
|
+
const logger_dto_1 = require("../../models/logger.dto");
|
|
57
|
+
const logger_constants_1 = require("../../constants/logger.constants");
|
|
58
|
+
const message_formatter_helper_1 = require("../../helpers/message-formatter.helper");
|
|
59
|
+
const logUtil = __importStar(require("../../helpers/log.helper"));
|
|
60
|
+
/**
|
|
61
|
+
* CustomLogger - Basic logger implementation with standard log levels.
|
|
62
|
+
*
|
|
63
|
+
* Implements NestJS LoggerService interface and uses Winston for actual logging.
|
|
64
|
+
* Provides simple logging methods (log, error, warn, debug, verbose) for basic use cases.
|
|
65
|
+
*
|
|
66
|
+
* For advanced structured logging with OpenTelemetry integration, use BaseAppLogger or AppLogger.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const logger = new CustomLogger('MyService');
|
|
71
|
+
* logger.log('Application started');
|
|
72
|
+
* logger.error('An error occurred', 'Error stack trace');
|
|
73
|
+
* logger.warn('Warning message');
|
|
74
|
+
* logger.debug('Debug information');
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @implements {LoggerService}
|
|
78
|
+
*/
|
|
79
|
+
let CustomLogger = class CustomLogger {
|
|
80
|
+
appName;
|
|
81
|
+
logger;
|
|
82
|
+
cachedHostname;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new CustomLogger instance.
|
|
85
|
+
*
|
|
86
|
+
* Initializes Winston logger with console transport and caches the hostname
|
|
87
|
+
* for performance optimization.
|
|
88
|
+
*
|
|
89
|
+
* @param appName - Name of the application (default: 'EQXJS')
|
|
90
|
+
*/
|
|
91
|
+
constructor(appName = logger_constants_1.DEFAULT_VALUES.DEFAULT_APP_NAME) {
|
|
92
|
+
this.appName = appName;
|
|
93
|
+
this.logger = winston.createLogger({
|
|
94
|
+
level: 'silly',
|
|
95
|
+
transports: [new winston.transports.Console()],
|
|
96
|
+
});
|
|
97
|
+
this.cachedHostname = os.hostname();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Formats a Date object to ISO 8601 string with UTC+7 timezone offset.
|
|
101
|
+
*
|
|
102
|
+
* @param date - The date to format
|
|
103
|
+
* @returns ISO 8601 formatted string (e.g., "2026-01-12T10:00:00.000Z")
|
|
104
|
+
* @protected
|
|
105
|
+
*/
|
|
106
|
+
dateFormat(date) {
|
|
107
|
+
return (0, moment_1.default)(date).utcOffset('+0700').format('YYYY-MM-DDTHH:mm:ss.SSS\\Z');
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Initializes a LoggerDto with basic log information.
|
|
111
|
+
*
|
|
112
|
+
* Creates a structured log entry from the provided message and parameters.
|
|
113
|
+
* Handles message formatting, truncation, and sets default values for required fields.
|
|
114
|
+
*
|
|
115
|
+
* @param level - Log level
|
|
116
|
+
* @param message - Log message (any type)
|
|
117
|
+
* @param optionalParams - Additional parameters (last parameter becomes componentName)
|
|
118
|
+
* @returns Initialized LoggerDto object
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
initializeLogger(level, message, ...optionalParams) {
|
|
122
|
+
const componentName = optionalParams.length > 0 ? optionalParams.pop() : undefined;
|
|
123
|
+
const formattedMessage = (0, message_formatter_helper_1.formatMessage)(message);
|
|
124
|
+
const truncatedMessage = (0, message_formatter_helper_1.truncateMessage)(formattedMessage);
|
|
125
|
+
// Direct object creation for better performance
|
|
126
|
+
const dto = new logger_dto_1.LoggerDto();
|
|
127
|
+
dto.level = level;
|
|
128
|
+
dto.timestamp = this.dateFormat(new Date());
|
|
129
|
+
dto.appName = this.appName;
|
|
130
|
+
dto.componentName = componentName || logger_constants_1.DEFAULT_VALUES.NONE;
|
|
131
|
+
dto.action = '[SYSTEM]';
|
|
132
|
+
dto.message = truncatedMessage;
|
|
133
|
+
dto.instance = this.cachedHostname;
|
|
134
|
+
dto.originateServiceName = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
135
|
+
dto.recordName = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
136
|
+
dto.recordType = logger_constants_1.DEFAULT_VALUES.RECORD_TYPE_DETAIL;
|
|
137
|
+
dto.sessionId = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
138
|
+
dto.transactionId = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
139
|
+
dto.channel = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
140
|
+
dto.componentVersion = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
141
|
+
dto.useCase = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
142
|
+
dto.useCaseStep = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
143
|
+
dto.user = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
144
|
+
dto.device = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
145
|
+
dto.public = logger_constants_1.DEFAULT_VALUES.NONE;
|
|
146
|
+
return dto;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Logs an informational message.
|
|
150
|
+
* Alias for standard console.log behavior in NestJS applications.
|
|
151
|
+
*
|
|
152
|
+
* @param message - Message to log (any type)
|
|
153
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* logger.log('User created successfully');
|
|
158
|
+
* logger.log('Request processed', 'UserController');
|
|
159
|
+
* logger.log({ userId: 123, action: 'create' });
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
log(message, ...optionalParams) {
|
|
163
|
+
if (!logUtil.isLevelEnable(logger_constants_1.LOG_LEVELS.LOG))
|
|
164
|
+
return;
|
|
165
|
+
const loggerDto = this.initializeLogger(logger_constants_1.LOG_LEVELS.INFO, message, ...optionalParams);
|
|
166
|
+
this.logger.log(loggerDto);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Logs an error message.
|
|
170
|
+
* Use for logging error conditions and failures.
|
|
171
|
+
*
|
|
172
|
+
* @param message - Error message (any type)
|
|
173
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* logger.error('Database connection failed');
|
|
178
|
+
* logger.error('Query error', 'DatabaseService');
|
|
179
|
+
* logger.error(new Error('Something went wrong'));
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
error(message, ...optionalParams) {
|
|
183
|
+
if (!logUtil.isLevelEnable(logger_constants_1.LOG_LEVELS.ERROR))
|
|
184
|
+
return;
|
|
185
|
+
const loggerDto = this.initializeLogger(logger_constants_1.LOG_LEVELS.ERROR, message, ...optionalParams);
|
|
186
|
+
this.logger.log(loggerDto);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Logs a warning message.
|
|
190
|
+
* Use for potentially harmful situations or deprecated functionality.
|
|
191
|
+
*
|
|
192
|
+
* @param message - Warning message (any type)
|
|
193
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* logger.warn('API rate limit approaching');
|
|
198
|
+
* logger.warn('Using deprecated method', 'PaymentService');
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
warn(message, ...optionalParams) {
|
|
202
|
+
if (!logUtil.isLevelEnable(logger_constants_1.LOG_LEVELS.WARN))
|
|
203
|
+
return;
|
|
204
|
+
const loggerDto = this.initializeLogger(logger_constants_1.LOG_LEVELS.WARN, message, ...optionalParams);
|
|
205
|
+
this.logger.log(loggerDto);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Logs a debug message.
|
|
209
|
+
* Use for detailed diagnostic information during development.
|
|
210
|
+
*
|
|
211
|
+
* @param message - Debug message (any type)
|
|
212
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* logger.debug('Processing request payload');
|
|
217
|
+
* logger.debug({ requestId: '123', payload: data }, 'RequestHandler');
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
debug(message, ...optionalParams) {
|
|
221
|
+
if (!logUtil.isLevelEnable(logger_constants_1.LOG_LEVELS.DEBUG))
|
|
222
|
+
return;
|
|
223
|
+
const loggerDto = this.initializeLogger(logger_constants_1.LOG_LEVELS.DEBUG, message, ...optionalParams);
|
|
224
|
+
this.logger.log(loggerDto);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Logs a verbose message.
|
|
228
|
+
* Use for the most detailed information, typically only needed for deep debugging.
|
|
229
|
+
*
|
|
230
|
+
* @param message - Verbose message (any type)
|
|
231
|
+
* @param optionalParams - Additional parameters (last one becomes component name)
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* logger.verbose('Internal state dump');
|
|
236
|
+
* logger.verbose({ state: internalState }, 'StateMachine');
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
verbose(message, ...optionalParams) {
|
|
240
|
+
if (!logUtil.isLevelEnable(logger_constants_1.LOG_LEVELS.VERBOSE))
|
|
241
|
+
return;
|
|
242
|
+
const loggerDto = this.initializeLogger(logger_constants_1.LOG_LEVELS.VERBOSE, message, ...optionalParams);
|
|
243
|
+
this.logger.log(loggerDto);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Flushes the log message to Winston logger.
|
|
247
|
+
*
|
|
248
|
+
* @param message - Message to be logged
|
|
249
|
+
* @protected
|
|
250
|
+
*/
|
|
251
|
+
flushLog(message) {
|
|
252
|
+
this.logger.log(message);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
exports.CustomLogger = CustomLogger;
|
|
256
|
+
exports.CustomLogger = CustomLogger = __decorate([
|
|
257
|
+
__param(0, (0, common_1.Optional)()),
|
|
258
|
+
__metadata("design:paramtypes", [String])
|
|
259
|
+
], CustomLogger);
|
|
260
|
+
//# sourceMappingURL=custom.logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.logger.js","sourceRoot":"","sources":["../../../src/core/loggers/custom.logger.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppLogger = exports.BaseAppLogger = exports.CustomLogger = void 0;
|
|
4
|
+
var custom_logger_1 = require("./custom.logger");
|
|
5
|
+
Object.defineProperty(exports, "CustomLogger", { enumerable: true, get: function () { return custom_logger_1.CustomLogger; } });
|
|
6
|
+
var base_app_logger_1 = require("./base-app.logger");
|
|
7
|
+
Object.defineProperty(exports, "BaseAppLogger", { enumerable: true, get: function () { return base_app_logger_1.BaseAppLogger; } });
|
|
8
|
+
var app_logger_1 = require("./app.logger");
|
|
9
|
+
Object.defineProperty(exports, "AppLogger", { enumerable: true, get: function () { return app_logger_1.AppLogger; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/loggers/index.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AACrB,qDAAkD;AAAzC,gHAAA,aAAa,OAAA;AACtB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats the current date and time to ISO 8601 format with UTC+7 timezone offset.
|
|
3
|
+
*
|
|
4
|
+
* Returns a string representation of the current timestamp in the format:
|
|
5
|
+
* `YYYY-MM-DDTHH:mm:ss.SSSZ` (e.g., "2026-01-12T15:30:45.123Z")
|
|
6
|
+
*
|
|
7
|
+
* The timestamp is adjusted to UTC+7 timezone (Bangkok/Jakarta timezone).
|
|
8
|
+
*
|
|
9
|
+
* @returns ISO 8601 formatted timestamp string with UTC+7 offset
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const timestamp = dateFormat();
|
|
14
|
+
* console.log(timestamp); // "2026-01-12T15:30:45.123Z"
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Use in logging
|
|
20
|
+
* const dto = new LoggerDto();
|
|
21
|
+
* dto.timestamp = dateFormat();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function dateFormat(): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.dateFormat = dateFormat;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
/**
|
|
9
|
+
* Formats the current date and time to ISO 8601 format with UTC+7 timezone offset.
|
|
10
|
+
*
|
|
11
|
+
* Returns a string representation of the current timestamp in the format:
|
|
12
|
+
* `YYYY-MM-DDTHH:mm:ss.SSSZ` (e.g., "2026-01-12T15:30:45.123Z")
|
|
13
|
+
*
|
|
14
|
+
* The timestamp is adjusted to UTC+7 timezone (Bangkok/Jakarta timezone).
|
|
15
|
+
*
|
|
16
|
+
* @returns ISO 8601 formatted timestamp string with UTC+7 offset
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const timestamp = dateFormat();
|
|
21
|
+
* console.log(timestamp); // "2026-01-12T15:30:45.123Z"
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Use in logging
|
|
27
|
+
* const dto = new LoggerDto();
|
|
28
|
+
* dto.timestamp = dateFormat();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function dateFormat() {
|
|
32
|
+
return (0, moment_1.default)(new Date())
|
|
33
|
+
.utcOffset('+0700')
|
|
34
|
+
.format('YYYY-MM-DDTHH:mm:ss.SSS\\Z');
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=datetime.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datetime.helper.js","sourceRoot":"","sources":["../../src/helpers/datetime.helper.ts"],"names":[],"mappings":";;;;;AAyBA,gCAIC;AA7BD,oDAA4B;AAE5B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,UAAU;IACxB,OAAO,IAAA,gBAAM,EAAC,IAAI,IAAI,EAAE,CAAC;SACtB,SAAS,CAAC,OAAO,CAAC;SAClB,MAAM,CAAC,4BAA4B,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { isLevelEnable, logStringify, maskMessageReplacer } from './log.helper';
|
|
2
|
+
export { TimeDiff } from './time-performance.helper';
|
|
3
|
+
export { dateFormat } from './datetime.helper';
|
|
4
|
+
export { LoggerDtoBuilder } from './logger-builder.helper';
|
|
5
|
+
export { formatMessage, setValueOrDefault } from './message-formatter.helper';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setValueOrDefault = exports.formatMessage = exports.LoggerDtoBuilder = exports.dateFormat = exports.TimeDiff = exports.maskMessageReplacer = exports.logStringify = exports.isLevelEnable = void 0;
|
|
4
|
+
var log_helper_1 = require("./log.helper");
|
|
5
|
+
Object.defineProperty(exports, "isLevelEnable", { enumerable: true, get: function () { return log_helper_1.isLevelEnable; } });
|
|
6
|
+
Object.defineProperty(exports, "logStringify", { enumerable: true, get: function () { return log_helper_1.logStringify; } });
|
|
7
|
+
Object.defineProperty(exports, "maskMessageReplacer", { enumerable: true, get: function () { return log_helper_1.maskMessageReplacer; } });
|
|
8
|
+
var time_performance_helper_1 = require("./time-performance.helper");
|
|
9
|
+
Object.defineProperty(exports, "TimeDiff", { enumerable: true, get: function () { return time_performance_helper_1.TimeDiff; } });
|
|
10
|
+
var datetime_helper_1 = require("./datetime.helper");
|
|
11
|
+
Object.defineProperty(exports, "dateFormat", { enumerable: true, get: function () { return datetime_helper_1.dateFormat; } });
|
|
12
|
+
var logger_builder_helper_1 = require("./logger-builder.helper");
|
|
13
|
+
Object.defineProperty(exports, "LoggerDtoBuilder", { enumerable: true, get: function () { return logger_builder_helper_1.LoggerDtoBuilder; } });
|
|
14
|
+
var message_formatter_helper_1 = require("./message-formatter.helper");
|
|
15
|
+
Object.defineProperty(exports, "formatMessage", { enumerable: true, get: function () { return message_formatter_helper_1.formatMessage; } });
|
|
16
|
+
Object.defineProperty(exports, "setValueOrDefault", { enumerable: true, get: function () { return message_formatter_helper_1.setValueOrDefault; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;AAAA,2CAAgF;AAAvE,2GAAA,aAAa,OAAA;AAAE,0GAAA,YAAY,OAAA;AAAE,iHAAA,mBAAmB,OAAA;AACzD,qEAAqD;AAA5C,mHAAA,QAAQ,OAAA;AACjB,qDAA+C;AAAtC,6GAAA,UAAU,OAAA;AACnB,iEAA2D;AAAlD,yHAAA,gBAAgB,OAAA;AACzB,uEAA8E;AAArE,yHAAA,aAAa,OAAA;AAAE,6HAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a specific log level is enabled based on the LOG_LEVEL environment variable.
|
|
3
|
+
*
|
|
4
|
+
* The LOG_LEVEL environment variable should contain a comma-separated list of enabled levels.
|
|
5
|
+
* Common log levels: 'debug', 'info', 'log', 'warn', 'error', 'verbose'
|
|
6
|
+
*
|
|
7
|
+
* @param level - The log level to check (e.g., 'info', 'debug', 'error')
|
|
8
|
+
* @returns True if the level is enabled, false otherwise
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* process.env.LOG_LEVEL = 'info,error,warn';
|
|
13
|
+
*
|
|
14
|
+
* if (isLevelEnable('debug')) {
|
|
15
|
+
* // Won't execute - debug is not enabled
|
|
16
|
+
* console.log('Debug info');
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* if (isLevelEnable('info')) {
|
|
20
|
+
* // Will execute - info is enabled
|
|
21
|
+
* console.log('Info message');
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function isLevelEnable(level: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* JSON replacer function that masks sensitive field values.
|
|
28
|
+
*
|
|
29
|
+
* Used with JSON.stringify to automatically replace sensitive field values with '*****'.
|
|
30
|
+
* Sensitive fields are configured via the LOG_MASK_KEYS environment variable.
|
|
31
|
+
*
|
|
32
|
+
* @param key - The property key being stringified
|
|
33
|
+
* @param value - The property value being stringified
|
|
34
|
+
* @returns The original value if not sensitive, or '*****' if the key is in the mask list
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* process.env.LOG_MASK_KEYS = 'password,apiKey,secret';
|
|
39
|
+
*
|
|
40
|
+
* const data = {
|
|
41
|
+
* username: 'john',
|
|
42
|
+
* password: 'secret123',
|
|
43
|
+
* apiKey: 'abc-def-ghi'
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* const masked = JSON.stringify(data, maskMessageReplacer);
|
|
47
|
+
* // {"username":"john","password":"*****","apiKey":"*****"}
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @see logStringify
|
|
51
|
+
*/
|
|
52
|
+
export declare function maskMessageReplacer(key: string, value: any): any;
|
|
53
|
+
/**
|
|
54
|
+
* Converts any value to a string with automatic masking of sensitive fields.
|
|
55
|
+
*
|
|
56
|
+
* Handles various input types:
|
|
57
|
+
* - Strings: returned as-is
|
|
58
|
+
* - Objects: JSON stringified with automatic masking via maskMessageReplacer
|
|
59
|
+
* - Others: converted using String()
|
|
60
|
+
*
|
|
61
|
+
* Sensitive fields are masked based on the LOG_MASK_KEYS environment variable.
|
|
62
|
+
*
|
|
63
|
+
* @param message - The value to stringify (can be any type)
|
|
64
|
+
* @returns String representation of the message with sensitive fields masked
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* process.env.LOG_MASK_KEYS = 'password,token';
|
|
69
|
+
*
|
|
70
|
+
* // String input
|
|
71
|
+
* logStringify('Hello'); // "Hello"
|
|
72
|
+
*
|
|
73
|
+
* // Object with sensitive data
|
|
74
|
+
* const user = { name: 'John', password: 'secret' };
|
|
75
|
+
* logStringify(user); // '{"name":"John","password":"*****"}'
|
|
76
|
+
*
|
|
77
|
+
* // Nested objects
|
|
78
|
+
* const data = { user: { token: 'abc123' }, message: 'test' };
|
|
79
|
+
* logStringify(data); // '{"user":{"token":"*****"},"message":"test"}'
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @see maskMessageReplacer
|
|
83
|
+
*/
|
|
84
|
+
export declare function logStringify(message: any): string;
|