@heavybit/logger-ts 1.0.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/README.md +458 -0
- package/dist/config/index.d.ts +34 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +204 -0
- package/dist/config/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/aopLogger.d.ts +44 -0
- package/dist/lib/aopLogger.d.ts.map +1 -0
- package/dist/lib/aopLogger.js +269 -0
- package/dist/lib/aopLogger.js.map +1 -0
- package/dist/lib/aopLoggerUtils.d.ts +54 -0
- package/dist/lib/aopLoggerUtils.d.ts.map +1 -0
- package/dist/lib/aopLoggerUtils.js +195 -0
- package/dist/lib/aopLoggerUtils.js.map +1 -0
- package/dist/lib/logger.d.ts +22 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +253 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/middleware/loggingMiddleware.d.ts +27 -0
- package/dist/middleware/loggingMiddleware.d.ts.map +1 -0
- package/dist/middleware/loggingMiddleware.js +225 -0
- package/dist/middleware/loggingMiddleware.js.map +1 -0
- package/dist/types/index.d.ts +208 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/sanitize.d.ts +26 -0
- package/dist/utils/sanitize.d.ts.map +1 -0
- package/dist/utils/sanitize.js +132 -0
- package/dist/utils/sanitize.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logMethodsWithAOP = logMethodsWithAOP;
|
|
4
|
+
exports.LogMethod = LogMethod;
|
|
5
|
+
exports.LogClass = LogClass;
|
|
6
|
+
exports.wrapRoutesWithLogging = wrapRoutesWithLogging;
|
|
7
|
+
exports.withLogging = withLogging;
|
|
8
|
+
const aopLogger_1 = require("./aopLogger");
|
|
9
|
+
/**
|
|
10
|
+
* Utility to log all method calls dynamically on a class except excluded methods.
|
|
11
|
+
* Handles error-specific methods (such as getAll) and logs errors accordingly.
|
|
12
|
+
*
|
|
13
|
+
* @param classPrototype - The prototype of the class whose methods are to be logged.
|
|
14
|
+
* @param excludedMethods - Array of method names to be excluded from logging.
|
|
15
|
+
* @param logErrorsOnly - Array of methods to log only errors (e.g., getAll).
|
|
16
|
+
* @param className - The name of the class for logging context.
|
|
17
|
+
* @param classType - The type of the class (optional).
|
|
18
|
+
* @param adviceType - The type of advice (optional, defaults to "around").
|
|
19
|
+
*/
|
|
20
|
+
function logMethodsWithAOP(classPrototype, excludedMethods = [], logErrorsOnly = [], className, classType, adviceType = 'around') {
|
|
21
|
+
// Retrieve all method names from the class prototype, excluding the constructor
|
|
22
|
+
const methodNames = Object.getOwnPropertyNames(classPrototype).filter((method) => method !== 'constructor' &&
|
|
23
|
+
!excludedMethods.includes(method) &&
|
|
24
|
+
typeof classPrototype[method] === 'function');
|
|
25
|
+
// Loop through all methods to log them
|
|
26
|
+
methodNames.forEach((methodName) => {
|
|
27
|
+
// If the method is in the logErrorsOnly array, we log errors only for it
|
|
28
|
+
const methodType = logErrorsOnly.includes(methodName) ? 'getAll' : '';
|
|
29
|
+
aopLogger_1.AOPLogger.logMethodCall(classPrototype, methodName, className, methodType, adviceType, classType);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Decorator for logging method calls (for use with TypeScript decorators)
|
|
34
|
+
*
|
|
35
|
+
* @param className - The class name for logging context
|
|
36
|
+
* @param methodType - The method type (optional)
|
|
37
|
+
* @param adviceType - The advice type (default: 'around')
|
|
38
|
+
* @param classType - The class type for log level determination
|
|
39
|
+
*/
|
|
40
|
+
function LogMethod(className, methodType = '', adviceType = 'around', classType) {
|
|
41
|
+
return function (_target, propertyKey, descriptor) {
|
|
42
|
+
const originalMethod = descriptor.value;
|
|
43
|
+
descriptor.value = async function (req, res, next) {
|
|
44
|
+
const methodNameStr = typeof propertyKey === 'symbol' ? propertyKey.description || 'symbol' : propertyKey;
|
|
45
|
+
const context = {
|
|
46
|
+
methodName: methodNameStr,
|
|
47
|
+
methodType,
|
|
48
|
+
classType: classType || aopLogger_1.AOPLogger.getClassType(this),
|
|
49
|
+
className: className || this.constructor.name,
|
|
50
|
+
startTime: Date.now(),
|
|
51
|
+
url: req?.originalUrl,
|
|
52
|
+
method: req?.method,
|
|
53
|
+
body: req?.body,
|
|
54
|
+
};
|
|
55
|
+
// Log before
|
|
56
|
+
if (adviceType === 'before' || adviceType === 'around') {
|
|
57
|
+
if (methodType !== 'getAll' && methodType !== 'getSingle') {
|
|
58
|
+
aopLogger_1.AOPLogger.logRequestDetails(context, 'before');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const result = await originalMethod.call(this, req, res, next);
|
|
63
|
+
// Log after
|
|
64
|
+
if (adviceType === 'after' || adviceType === 'around') {
|
|
65
|
+
context.endTime = Date.now();
|
|
66
|
+
context.executionTime = context.endTime - context.startTime;
|
|
67
|
+
context.result = result;
|
|
68
|
+
context.statusCode = res.statusCode;
|
|
69
|
+
context.logType = 'info';
|
|
70
|
+
aopLogger_1.AOPLogger.logRequestDetails(context, 'after');
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
context.error = error;
|
|
76
|
+
context.statusCode = error.statusCode || 500;
|
|
77
|
+
context.message = error?.message;
|
|
78
|
+
context.logType = 'error';
|
|
79
|
+
aopLogger_1.AOPLogger.logRequestDetails(context, 'error');
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return descriptor;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Decorator for logging all methods in a class
|
|
88
|
+
*
|
|
89
|
+
* @param excludedMethods - Methods to exclude from logging
|
|
90
|
+
* @param logErrorsOnly - Methods that only log errors
|
|
91
|
+
* @param classType - The class type for log level determination
|
|
92
|
+
*/
|
|
93
|
+
function LogClass(excludedMethods = [], logErrorsOnly = [], classType) {
|
|
94
|
+
return function (constructor) {
|
|
95
|
+
const className = constructor.name;
|
|
96
|
+
const prototype = constructor.prototype;
|
|
97
|
+
logMethodsWithAOP(prototype, excludedMethods, logErrorsOnly, className, classType, 'around');
|
|
98
|
+
return constructor;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Wraps all route handlers in a router with AOP logging.
|
|
103
|
+
*
|
|
104
|
+
* @param router - The Express router object.
|
|
105
|
+
* @param className - The class name or context name for logging.
|
|
106
|
+
* @param classType - The type of the class (e.g., "routes", "controller").
|
|
107
|
+
* @param logErrorsOnly - Methods that should only log on errors.
|
|
108
|
+
*/
|
|
109
|
+
function wrapRoutesWithLogging(router, className, classType = 'routes', logErrorsOnly = []) {
|
|
110
|
+
const stack = router.stack;
|
|
111
|
+
stack.forEach((routeLayer) => {
|
|
112
|
+
if (routeLayer.route && routeLayer.route.stack) {
|
|
113
|
+
routeLayer.route.stack.forEach((layer) => {
|
|
114
|
+
if (typeof layer.handle === 'function') {
|
|
115
|
+
const originalHandler = layer.handle;
|
|
116
|
+
const methods = Object.keys(routeLayer.route.methods)
|
|
117
|
+
.filter((m) => routeLayer.route.methods[m])
|
|
118
|
+
.join(',')
|
|
119
|
+
.toUpperCase();
|
|
120
|
+
const methodName = `${routeLayer.route.path} [${methods}]`;
|
|
121
|
+
const methodType = logErrorsOnly.includes(methodName) ? 'getAll' : '';
|
|
122
|
+
// Wrap the original handler
|
|
123
|
+
layer.handle = async function (req, res, next) {
|
|
124
|
+
const context = {
|
|
125
|
+
methodName,
|
|
126
|
+
methodType,
|
|
127
|
+
classType,
|
|
128
|
+
className,
|
|
129
|
+
startTime: Date.now(),
|
|
130
|
+
url: req.originalUrl,
|
|
131
|
+
method: req.method,
|
|
132
|
+
body: req.body,
|
|
133
|
+
};
|
|
134
|
+
// Log before
|
|
135
|
+
if (methodType !== 'getAll') {
|
|
136
|
+
aopLogger_1.AOPLogger.logRequestDetails(context, 'before');
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
await originalHandler(req, res, next);
|
|
140
|
+
context.endTime = Date.now();
|
|
141
|
+
context.executionTime = context.endTime - context.startTime;
|
|
142
|
+
context.statusCode = res.statusCode;
|
|
143
|
+
context.logType = 'info';
|
|
144
|
+
aopLogger_1.AOPLogger.logRequestDetails(context, 'after');
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
context.error = error;
|
|
148
|
+
context.statusCode = error.statusCode || 500;
|
|
149
|
+
context.message = error?.message;
|
|
150
|
+
context.logType = 'error';
|
|
151
|
+
aopLogger_1.AOPLogger.logRequestDetails(context, 'error');
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Create a wrapped handler with logging
|
|
162
|
+
*/
|
|
163
|
+
function withLogging(handler, methodName, className = 'Handler', classType = 'controllers') {
|
|
164
|
+
return async function (req, res, next) {
|
|
165
|
+
const context = {
|
|
166
|
+
methodName,
|
|
167
|
+
methodType: '',
|
|
168
|
+
classType,
|
|
169
|
+
className,
|
|
170
|
+
startTime: Date.now(),
|
|
171
|
+
url: req.originalUrl,
|
|
172
|
+
method: req.method,
|
|
173
|
+
body: req.body,
|
|
174
|
+
};
|
|
175
|
+
// Log before
|
|
176
|
+
aopLogger_1.AOPLogger.logRequestDetails(context, 'before');
|
|
177
|
+
try {
|
|
178
|
+
await handler(req, res, next);
|
|
179
|
+
context.endTime = Date.now();
|
|
180
|
+
context.executionTime = context.endTime - context.startTime;
|
|
181
|
+
context.statusCode = res.statusCode;
|
|
182
|
+
context.logType = 'info';
|
|
183
|
+
aopLogger_1.AOPLogger.logRequestDetails(context, 'after');
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
context.error = error;
|
|
187
|
+
context.statusCode = error.statusCode || 500;
|
|
188
|
+
context.message = error?.message;
|
|
189
|
+
context.logType = 'error';
|
|
190
|
+
aopLogger_1.AOPLogger.logRequestDetails(context, 'error');
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=aopLoggerUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aopLoggerUtils.js","sourceRoot":"","sources":["../../src/lib/aopLoggerUtils.ts"],"names":[],"mappings":";;AA0BA,8CA6BC;AAUD,8BAgEC;AASD,4BAoBC;AAuBD,sDAgEC;AAKD,kCA2CC;AApSD,2CAAwC;AAcxC;;;;;;;;;;GAUG;AACH,SAAgB,iBAAiB,CAC/B,cAA8B,EAC9B,kBAA4B,EAAE,EAC9B,gBAA0B,EAAE,EAC5B,SAAiB,EACjB,SAAqB,EACrB,aAAyB,QAAQ;IAEjC,gFAAgF;IAChF,MAAM,WAAW,GAAG,MAAM,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,MAAM,CACnE,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,KAAK,aAAa;QACxB,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC;QACjC,OAAO,cAAc,CAAC,MAAM,CAAC,KAAK,UAAU,CAC/C,CAAC;IAEF,uCAAuC;IACvC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACjC,yEAAyE;QACzE,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,qBAAS,CAAC,aAAa,CACrB,cAAgD,EAChD,UAAU,EACV,SAAS,EAC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AU,EAAE,EAAE;YACd,SAAS;YACT,SAAS;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,GAAG,EAAE,GAAG,CAAC,WAAW;YACpB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,IAAI,EAAE,GAAG,CAAC,IAA+B;SAC1C,CAAC;QAEF,aAAa;QACb,qBAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAE/C,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAE9B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC7B,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;YAC5D,OAAO,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;YACpC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;YAEzB,qBAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,GAAG,KAAc,CAAC;YAC/B,OAAO,CAAC,UAAU,GAAI,KAAiC,CAAC,UAAU,IAAI,GAAG,CAAC;YAC1E,OAAO,CAAC,OAAO,GAAI,KAAe,EAAE,OAAO,CAAC;YAC5C,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;YAC1B,qBAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { LoggerConfig, RequestLogEntry, ExtendedLogger } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Initialize the logger (call once at app startup)
|
|
4
|
+
*
|
|
5
|
+
* @param config - Optional custom configuration
|
|
6
|
+
* @param setupGlobalHandlers - Whether to set up global error handlers (default: true)
|
|
7
|
+
*/
|
|
8
|
+
export declare const initLogger: (config?: Partial<LoggerConfig>, setupGlobalHandlers?: boolean) => ExtendedLogger;
|
|
9
|
+
/**
|
|
10
|
+
* Get the logger instance (creates default if not initialized)
|
|
11
|
+
*/
|
|
12
|
+
export declare const getLogger: () => ExtendedLogger;
|
|
13
|
+
/**
|
|
14
|
+
* Create a new logger instance with custom config (does not replace singleton)
|
|
15
|
+
*/
|
|
16
|
+
export declare const createLogger: (config?: Partial<LoggerConfig>) => ExtendedLogger;
|
|
17
|
+
/**
|
|
18
|
+
* Format a log entry for consistent structure
|
|
19
|
+
*/
|
|
20
|
+
export declare const formatLogEntry: (entry: Partial<RequestLogEntry>) => RequestLogEntry;
|
|
21
|
+
export default getLogger;
|
|
22
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,YAAY,EAEZ,eAAe,EACf,cAAc,EACf,MAAM,UAAU,CAAC;AAkPlB;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GACrB,SAAS,OAAO,CAAC,YAAY,CAAC,EAC9B,sBAAqB,OAAc,KAClC,cAYF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,QAAO,cAK5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,OAAO,CAAC,YAAY,CAAC,KAAG,cAE7D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,CAAC,eAAe,CAAC,KAAG,eAW/D,CAAC;AAGH,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,253 @@
|
|
|
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.formatLogEntry = exports.createLogger = exports.getLogger = exports.initLogger = void 0;
|
|
7
|
+
const winston_1 = __importDefault(require("winston"));
|
|
8
|
+
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const util_1 = __importDefault(require("util"));
|
|
12
|
+
const config_1 = require("../config");
|
|
13
|
+
const sanitize_1 = require("../utils/sanitize");
|
|
14
|
+
/**
|
|
15
|
+
* Create a structured log format function
|
|
16
|
+
*/
|
|
17
|
+
const createStructuredLogFormat = (config) => {
|
|
18
|
+
return (info) => {
|
|
19
|
+
const sanitizedPayload = (0, sanitize_1.sanitizeData)(info.body || {});
|
|
20
|
+
// Convert message to string if it's an object
|
|
21
|
+
const message = typeof info.message === 'object'
|
|
22
|
+
? util_1.default.inspect(info.message, { depth: null })
|
|
23
|
+
: info.message;
|
|
24
|
+
let logMessage = `${info.timestamp}`;
|
|
25
|
+
// Add app name if configured
|
|
26
|
+
if (config.appName) {
|
|
27
|
+
logMessage += ` | app=${config.appName}`;
|
|
28
|
+
}
|
|
29
|
+
logMessage += ` | className=${info.className || ''}`;
|
|
30
|
+
logMessage += ` | OperationName=${info.methodName || ''}`;
|
|
31
|
+
logMessage += ` | Method=${info.method || ''}`;
|
|
32
|
+
logMessage += ` | Endpoint=${info.url || ''}`;
|
|
33
|
+
logMessage += ` | LogLevel=${info.level || ''}`;
|
|
34
|
+
logMessage += ` | Payload=${util_1.default.inspect(sanitizedPayload, { depth: null })}`;
|
|
35
|
+
logMessage += ` | Message=${message || ''}`;
|
|
36
|
+
if (info.requestId) {
|
|
37
|
+
logMessage += ` | RequestId=${info.requestId}`;
|
|
38
|
+
}
|
|
39
|
+
if (info.responseTime) {
|
|
40
|
+
logMessage += ` | ResponseTime=${info.responseTime}`;
|
|
41
|
+
}
|
|
42
|
+
if (info.statusCode !== undefined) {
|
|
43
|
+
logMessage += ` | StatusCode=${info.statusCode}`;
|
|
44
|
+
}
|
|
45
|
+
if (info.error) {
|
|
46
|
+
const errorStr = info.error instanceof Error
|
|
47
|
+
? `${info.error.message}\n${info.error.stack}`
|
|
48
|
+
: String(info.error);
|
|
49
|
+
logMessage += ` | Error=${errorStr}`;
|
|
50
|
+
}
|
|
51
|
+
return logMessage;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Create JSON log format for structured logging (useful for log aggregation systems)
|
|
56
|
+
*/
|
|
57
|
+
const createJsonLogFormat = (config) => {
|
|
58
|
+
return winston_1.default.format.printf((info) => {
|
|
59
|
+
const sanitizedPayload = (0, sanitize_1.sanitizeData)(info.body || {});
|
|
60
|
+
const logObject = {
|
|
61
|
+
timestamp: info.timestamp,
|
|
62
|
+
level: info.level,
|
|
63
|
+
app: config.appName,
|
|
64
|
+
environment: config.environment,
|
|
65
|
+
className: info.className || undefined,
|
|
66
|
+
methodName: info.methodName || undefined,
|
|
67
|
+
method: info.method || undefined,
|
|
68
|
+
url: info.url || undefined,
|
|
69
|
+
requestId: info.requestId || undefined,
|
|
70
|
+
statusCode: info.statusCode || undefined,
|
|
71
|
+
responseTime: info.responseTime || undefined,
|
|
72
|
+
message: typeof info.message === 'object'
|
|
73
|
+
? util_1.default.inspect(info.message, { depth: null })
|
|
74
|
+
: info.message,
|
|
75
|
+
payload: Object.keys(sanitizedPayload).length > 0 ? sanitizedPayload : undefined,
|
|
76
|
+
error: info.error instanceof Error
|
|
77
|
+
? { message: info.error.message, stack: info.error.stack }
|
|
78
|
+
: info.error || undefined,
|
|
79
|
+
};
|
|
80
|
+
// Remove undefined values
|
|
81
|
+
const cleanObject = Object.fromEntries(Object.entries(logObject).filter(([, v]) => v !== undefined));
|
|
82
|
+
return JSON.stringify(cleanObject);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Create the log format based on configuration
|
|
87
|
+
*/
|
|
88
|
+
const createLogFormat = (config, useJson = false) => {
|
|
89
|
+
const formatFunc = useJson
|
|
90
|
+
? createJsonLogFormat(config)
|
|
91
|
+
: winston_1.default.format.printf(createStructuredLogFormat(config));
|
|
92
|
+
return winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }), formatFunc);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Create Winston transports based on configuration
|
|
96
|
+
*/
|
|
97
|
+
const createTransports = (config) => {
|
|
98
|
+
const transports = [];
|
|
99
|
+
// File transport
|
|
100
|
+
if (config.target === 'file' || config.target === 'both') {
|
|
101
|
+
// Ensure the logs directory exists
|
|
102
|
+
const logDir = config.file.directory;
|
|
103
|
+
if (!fs_1.default.existsSync(logDir)) {
|
|
104
|
+
fs_1.default.mkdirSync(logDir, { recursive: true });
|
|
105
|
+
}
|
|
106
|
+
const fileTransport = new winston_daily_rotate_file_1.default({
|
|
107
|
+
level: config.file.level,
|
|
108
|
+
format: createLogFormat(config, true), // Use JSON for file logs
|
|
109
|
+
filename: path_1.default.join(logDir, '%DATE%.log'),
|
|
110
|
+
datePattern: config.file.datePattern,
|
|
111
|
+
maxFiles: config.file.maxFiles,
|
|
112
|
+
zippedArchive: config.file.zippedArchive,
|
|
113
|
+
maxSize: config.file.maxSize,
|
|
114
|
+
});
|
|
115
|
+
// Error file transport (separate file for errors)
|
|
116
|
+
const errorFileTransport = new winston_daily_rotate_file_1.default({
|
|
117
|
+
level: 'error',
|
|
118
|
+
format: createLogFormat(config, true),
|
|
119
|
+
filename: path_1.default.join(logDir, '%DATE%-error.log'),
|
|
120
|
+
datePattern: config.file.datePattern,
|
|
121
|
+
maxFiles: config.file.maxFiles,
|
|
122
|
+
zippedArchive: config.file.zippedArchive,
|
|
123
|
+
maxSize: config.file.maxSize,
|
|
124
|
+
});
|
|
125
|
+
transports.push(fileTransport, errorFileTransport);
|
|
126
|
+
}
|
|
127
|
+
// Console/stdout transport
|
|
128
|
+
if (config.target === 'stdout' || config.target === 'both') {
|
|
129
|
+
const consoleFormat = config.console.colorize
|
|
130
|
+
? winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }), winston_1.default.format.printf(createStructuredLogFormat(config)))
|
|
131
|
+
: createLogFormat(config);
|
|
132
|
+
transports.push(new winston_1.default.transports.Console({
|
|
133
|
+
level: config.console.level,
|
|
134
|
+
format: consoleFormat,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
return transports;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Create the logger instance
|
|
141
|
+
*/
|
|
142
|
+
const createLoggerInstance = (config) => {
|
|
143
|
+
const finalConfig = config ? (0, config_1.mergeConfig)(config) : (0, config_1.getConfig)();
|
|
144
|
+
const winstonLogger = winston_1.default.createLogger({
|
|
145
|
+
level: finalConfig.defaultLevel,
|
|
146
|
+
format: createLogFormat(finalConfig),
|
|
147
|
+
transports: createTransports(finalConfig),
|
|
148
|
+
exitOnError: false,
|
|
149
|
+
});
|
|
150
|
+
// Listen for errors in transports
|
|
151
|
+
winstonLogger.on('error', (err) => {
|
|
152
|
+
console.error('Logging error:', err);
|
|
153
|
+
});
|
|
154
|
+
// Extend logger with custom methods
|
|
155
|
+
const extendedLogger = winstonLogger;
|
|
156
|
+
/**
|
|
157
|
+
* Log with request context
|
|
158
|
+
*/
|
|
159
|
+
extendedLogger.logRequest = function (entry) {
|
|
160
|
+
const level = entry.level || 'info';
|
|
161
|
+
this.log(level, entry.message, {
|
|
162
|
+
requestId: entry.requestId,
|
|
163
|
+
method: entry.method,
|
|
164
|
+
url: entry.url,
|
|
165
|
+
statusCode: entry.statusCode,
|
|
166
|
+
responseTime: entry.responseTime,
|
|
167
|
+
body: entry.body,
|
|
168
|
+
error: entry.error,
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Log with custom metadata
|
|
173
|
+
*/
|
|
174
|
+
extendedLogger.logWithMeta = function (level, message, meta) {
|
|
175
|
+
this.log(level, message, meta);
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Get current configuration
|
|
179
|
+
*/
|
|
180
|
+
extendedLogger.getConfig = function () {
|
|
181
|
+
return finalConfig;
|
|
182
|
+
};
|
|
183
|
+
return extendedLogger;
|
|
184
|
+
};
|
|
185
|
+
// Global handlers for uncaught exceptions and rejections
|
|
186
|
+
const setupGlobalErrorHandlers = (logger) => {
|
|
187
|
+
process.on('uncaughtException', (err) => {
|
|
188
|
+
logger.error('Uncaught Exception:', { error: err.message, stack: err.stack });
|
|
189
|
+
console.error('Uncaught Exception:', err);
|
|
190
|
+
});
|
|
191
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
192
|
+
logger.error('Unhandled Rejection:', {
|
|
193
|
+
reason: reason instanceof Error ? reason.message : String(reason),
|
|
194
|
+
promise: String(promise),
|
|
195
|
+
});
|
|
196
|
+
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
// Singleton logger instance
|
|
200
|
+
let loggerInstance = null;
|
|
201
|
+
/**
|
|
202
|
+
* Initialize the logger (call once at app startup)
|
|
203
|
+
*
|
|
204
|
+
* @param config - Optional custom configuration
|
|
205
|
+
* @param setupGlobalHandlers - Whether to set up global error handlers (default: true)
|
|
206
|
+
*/
|
|
207
|
+
const initLogger = (config, setupGlobalHandlers = true) => {
|
|
208
|
+
if (config) {
|
|
209
|
+
(0, config_1.initConfig)(config);
|
|
210
|
+
}
|
|
211
|
+
loggerInstance = createLoggerInstance(config);
|
|
212
|
+
if (setupGlobalHandlers) {
|
|
213
|
+
setupGlobalErrorHandlers(loggerInstance);
|
|
214
|
+
}
|
|
215
|
+
return loggerInstance;
|
|
216
|
+
};
|
|
217
|
+
exports.initLogger = initLogger;
|
|
218
|
+
/**
|
|
219
|
+
* Get the logger instance (creates default if not initialized)
|
|
220
|
+
*/
|
|
221
|
+
const getLogger = () => {
|
|
222
|
+
if (!loggerInstance) {
|
|
223
|
+
loggerInstance = createLoggerInstance();
|
|
224
|
+
}
|
|
225
|
+
return loggerInstance;
|
|
226
|
+
};
|
|
227
|
+
exports.getLogger = getLogger;
|
|
228
|
+
/**
|
|
229
|
+
* Create a new logger instance with custom config (does not replace singleton)
|
|
230
|
+
*/
|
|
231
|
+
const createLogger = (config) => {
|
|
232
|
+
return createLoggerInstance(config);
|
|
233
|
+
};
|
|
234
|
+
exports.createLogger = createLogger;
|
|
235
|
+
/**
|
|
236
|
+
* Format a log entry for consistent structure
|
|
237
|
+
*/
|
|
238
|
+
const formatLogEntry = (entry) => ({
|
|
239
|
+
level: entry.level || 'info',
|
|
240
|
+
message: entry.message || '',
|
|
241
|
+
requestId: entry.requestId || '',
|
|
242
|
+
method: entry.method || '',
|
|
243
|
+
url: entry.url || '',
|
|
244
|
+
statusCode: entry.statusCode,
|
|
245
|
+
responseTime: entry.responseTime || '',
|
|
246
|
+
timestamp: entry.timestamp || new Date().toISOString(),
|
|
247
|
+
body: entry.body || {},
|
|
248
|
+
error: entry.error || '',
|
|
249
|
+
});
|
|
250
|
+
exports.formatLogEntry = formatLogEntry;
|
|
251
|
+
// Default export - the singleton logger
|
|
252
|
+
exports.default = exports.getLogger;
|
|
253
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,0FAAwD;AACxD,4CAAoB;AACpB,gDAAwB;AACxB,gDAAwB;AAOxB,sCAA+D;AAC/D,gDAAiD;AAEjD;;GAEG;AACH,MAAM,yBAAyB,GAAG,CAAC,MAAoB,EAAE,EAAE;IACzD,OAAO,CAAC,IAAuC,EAAU,EAAE;QACzD,MAAM,gBAAgB,GAA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AY,GAAG,CAAC,MAA8B,EAAkB,EAAE;IAC7E,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB;AAEF;;GAEG;AACI,MAAM,cAAc,GAAG,CAAC,KAA+B,EAAmB,EAAE,CAAC,CAAC;IACnF,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,MAAM;IAC5B,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE;IAC5B,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,EAAE;IAChC,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,EAAE;IAC1B,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,EAAE;IACpB,UAAU,EAAE,KAAK,CAAC,UAAU;IAC5B,YAAY,EAAE,KAAK,CAAC,YAAY,IAAI,EAAE;IACtC,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;IACtD,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE;IACtB,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE;CACzB,CAAC,CAAC;AAXU,QAAA,cAAc,kBAWxB;AAEH,wCAAwC;AACxC,kBAAe,iBAAS,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Response, NextFunction } from 'express';
|
|
2
|
+
import { LoggingRequest, MiddlewareOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Create the Express logging middleware with configuration options
|
|
5
|
+
*
|
|
6
|
+
* @param options - Middleware configuration options
|
|
7
|
+
* @returns Express middleware function
|
|
8
|
+
*/
|
|
9
|
+
export declare const createLoggingMiddleware: (options?: MiddlewareOptions) => (req: LoggingRequest, res: Response, next: NextFunction) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Default logging middleware (uses default configuration)
|
|
12
|
+
*/
|
|
13
|
+
export declare const loggingMiddleware: (req: LoggingRequest, res: Response, next: NextFunction) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Error logging middleware for Express error handling
|
|
16
|
+
*/
|
|
17
|
+
export declare const errorLoggingMiddleware: (err: Error & {
|
|
18
|
+
statusCode?: number;
|
|
19
|
+
status?: number;
|
|
20
|
+
}, req: LoggingRequest, _res: Response, next: NextFunction) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Morgan-style request logging format
|
|
23
|
+
* Returns a middleware that logs in a standardized format
|
|
24
|
+
*/
|
|
25
|
+
export declare const morganStyleMiddleware: (format?: "combined" | "common" | "dev" | "short" | "tiny") => (req: LoggingRequest, res: Response, next: NextFunction) => void;
|
|
26
|
+
export default loggingMiddleware;
|
|
27
|
+
//# sourceMappingURL=loggingMiddleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loggingMiddleware.d.ts","sourceRoot":"","sources":["../../src/middleware/loggingMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAmB,MAAM,UAAU,CAAC;AAqB9E;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAAI,UAAS,iBAAsB,MAS7D,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,KAAG,IAoJlE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,QAzJf,cAAc,OAAO,QAAQ,QAAQ,YAAY,KAAG,IAyJT,CAAC;AAE3D;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,KAAK,KAAK,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EACrD,KAAK,cAAc,EACnB,MAAM,QAAQ,EACd,MAAM,YAAY,KACjB,IAsBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAQ,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,MAAc,MAC5F,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,KAAG,IAwClE,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|