@expressots/core 1.9.1 → 2.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/lib/CHANGELOG.md +45 -17
- package/lib/cjs/middleware/middleware-resolver.js +0 -3
- package/lib/cjs/types/middleware/middleware-resolver.d.ts.map +1 -1
- package/lib/esm/middleware/middleware-resolver.js +0 -3
- package/lib/esm/types/middleware/middleware-resolver.d.ts.map +1 -1
- package/lib/package.json +2 -7
- package/package.json +2 -7
- package/lib/cjs/provider/logger/winston-logger.js +0 -131
- package/lib/cjs/types/provider/logger/winston-logger.d.ts +0 -46
- package/lib/cjs/types/provider/logger/winston-logger.d.ts.map +0 -1
- package/lib/esm/provider/logger/winston-logger.js +0 -132
- package/lib/esm/types/provider/logger/winston-logger.d.ts +0 -46
- package/lib/esm/types/provider/logger/winston-logger.d.ts.map +0 -1
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,39 +1,67 @@
|
|
|
1
|
+
## [2.0.0](https://github.com/expressots/expressots/compare/1.9.1...2.0.0) (2023-09-14)
|
|
1
2
|
|
|
3
|
+
### Features
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
- add middleware resolver ([23b8d9f](https://github.com/expressots/expressots/commit/23b8d9ff8f0c8b4bb893f4fd0d7f39afcb7dd1cd))
|
|
6
|
+
- add app factory
|
|
7
|
+
- add services layer
|
|
8
|
+
- add middleware interfaces for cors, compression, bodyparser and generic middleware
|
|
9
|
+
- add configurable error handler
|
|
10
|
+
- separate expressjs from core library in its own library called adapter-express
|
|
11
|
+
- created provider mechanism to share resources between multiple adapters
|
|
12
|
+
- eliminate chalk, inversify utils dependencies
|
|
13
|
+
- create a logger system using stdout
|
|
5
14
|
|
|
6
|
-
###
|
|
15
|
+
### Code Refactoring
|
|
7
16
|
|
|
8
|
-
|
|
9
|
-
|
|
17
|
+
- refactor error handling
|
|
18
|
+
- remove winston lib for loggin ([5868bc9](https://github.com/expressots/expressots/commit/5868bc949f2242f0a9bfe5483642bb3878cc0156))
|
|
19
|
+
- removing unnecessary dependencies ([fdd43e0](https://github.com/expressots/expressots/commit/fdd43e0f280024b8e4b53f392ea56842a091898e))
|
|
10
20
|
|
|
21
|
+
## [1.9.1](https://github.com/expressots/expressots/compare/1.9.0...1.9.1) (2023-09-14)
|
|
11
22
|
|
|
12
23
|
### Bug Fixes
|
|
13
24
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* use new report utility in usecases ([#91](https://github.com/expressots/expressots/issues/91)) ([d1477b2](https://github.com/expressots/expressots/commit/d1477b24f932e354fb55373e8e73fe9155289486))
|
|
20
|
-
|
|
25
|
+
- add peer dependency @expressots/adapter-express ([874db40](https://github.com/expressots/expressots/commit/874db402af7bac8d5ac638fc206f3daf9f707fc3))
|
|
26
|
+
- change esm config to modeule interop ([32f04b5](https://github.com/expressots/expressots/commit/32f04b5bc7da6c515df70b0156f2f5cadd5526ac))
|
|
27
|
+
- change esm config to modeule interop ([978b168](https://github.com/expressots/expressots/commit/978b1685aa18c0573313ee96049159a1c95c4d87))
|
|
28
|
+
- opinionated template app provider services ([bcb55ca](https://github.com/expressots/expressots/commit/bcb55caf1e5a0ff053b5aaf89a79ef4537b38161))
|
|
29
|
+
- using adapter-express dependency ([84b0348](https://github.com/expressots/expressots/commit/84b03486193632b84e46e670bd44c6f8a01ebaa4))
|
|
21
30
|
|
|
22
31
|
### Code Refactoring
|
|
23
32
|
|
|
24
|
-
|
|
33
|
+
- create express adapter platform ([784beaa](https://github.com/expressots/expressots/commit/784beaaea9247e304abada8ebd33c673199e35f9))
|
|
34
|
+
- expose app base class for adapter ([36d8dec](https://github.com/expressots/expressots/commit/36d8dec0435a2456d1b9e1d5dca5bfb8956cfdea))
|
|
25
35
|
|
|
26
|
-
## [1.
|
|
36
|
+
## [1.9.0](https://github.com/expressots/expressots/compare/1.8.1...1.9.0) (2023-09-12)
|
|
37
|
+
|
|
38
|
+
### Features
|
|
27
39
|
|
|
40
|
+
- add pck resolver & remove chalk dependency ([6bbd415](https://github.com/expressots/expressots/commit/6bbd415937159e419116b6ade8f9852c3251fbf4))
|
|
41
|
+
- bump vitest from 0.34.3 to 0.34.4 ([#92](https://github.com/expressots/expressots/issues/92)) ([89dc682](https://github.com/expressots/expressots/commit/89dc682c7047897f01fd7770591b6ffea689d137))
|
|
28
42
|
|
|
29
43
|
### Bug Fixes
|
|
30
44
|
|
|
31
|
-
|
|
45
|
+
- disable console.spec to be refactored ([22a54bd](https://github.com/expressots/expressots/commit/22a54bdb7f0c2032d3b0e0f935ce48d73e665e84))
|
|
46
|
+
- dto validator json structure per property ([a8fbe40](https://github.com/expressots/expressots/commit/a8fbe409647140e867f930a882fd395df45d6de7))
|
|
47
|
+
- export console for testing ([d3f2c07](https://github.com/expressots/expressots/commit/d3f2c07ca2df0176fabed04172ce4ff684c91c9c))
|
|
48
|
+
- opinionated template logger.error function ([073f4e1](https://github.com/expressots/expressots/commit/073f4e154732fa3fed9492ec772c36894bc3cf48))
|
|
49
|
+
- replace dto interface for class opinionated template ([3e99d7c](https://github.com/expressots/expressots/commit/3e99d7c5492ff64701e754ec845a0410da442296))
|
|
50
|
+
- use new report utility in usecases ([#91](https://github.com/expressots/expressots/issues/91)) ([d1477b2](https://github.com/expressots/expressots/commit/d1477b24f932e354fb55373e8e73fe9155289486))
|
|
51
|
+
|
|
52
|
+
### Code Refactoring
|
|
32
53
|
|
|
54
|
+
- update type from any to number ([#90](https://github.com/expressots/expressots/issues/90)) ([5e34a44](https://github.com/expressots/expressots/commit/5e34a44d8bd353b8d3834f198f36bf73aa521845))
|
|
55
|
+
|
|
56
|
+
## [1.8.1](https://github.com/expressots/expressots/compare/1.8.0...1.8.1) (2023-09-10)
|
|
57
|
+
|
|
58
|
+
### Bug Fixes
|
|
59
|
+
|
|
60
|
+
- add generic in memory db and virtual table analysis ([#86](https://github.com/expressots/expressots/issues/86)) ([29541f9](https://github.com/expressots/expressots/commit/29541f997e47c8ac5f8cafbb0195c34c904454f4))
|
|
33
61
|
|
|
34
62
|
### Continuous Integrations
|
|
35
63
|
|
|
36
|
-
|
|
64
|
+
- config test workflow and setup vitest ([#88](https://github.com/expressots/expressots/issues/88)) ([67316ce](https://github.com/expressots/expressots/commit/67316cece977f04f9750a5a5af6cd88dfc695e0d))
|
|
37
65
|
|
|
38
66
|
## [1.8.0](https://github.com/expressots/expressots/compare/1.7.0...1.8.0) (2023-09-05)
|
|
39
67
|
|
|
@@ -270,4 +298,4 @@
|
|
|
270
298
|
|
|
271
299
|
### Bug Fixes
|
|
272
300
|
|
|
273
|
-
- fix pipeline for tag name ([b9ec52d](https://github.com/expressots/expressots/commit/b9ec52dc065763185f69364d8f083b1a95fa37e0))
|
|
301
|
+
- fix pipeline for tag name ([b9ec52d](https://github.com/expressots/expressots/commit/b9ec52dc065763185f69364d8f083b1a95fa37e0))
|
|
@@ -46,9 +46,6 @@ class MiddlewareResolver {
|
|
|
46
46
|
const middleware = require(hasMiddleware);
|
|
47
47
|
return middleware(...options) || middleware.default(...options);
|
|
48
48
|
}
|
|
49
|
-
else {
|
|
50
|
-
this.logger.warn(`Middleware [${middlewareName}] not installed. Please install it using your package manager.`, "middleware-resolver");
|
|
51
|
-
}
|
|
52
49
|
return null;
|
|
53
50
|
}
|
|
54
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware-resolver.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-resolver.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware-resolver.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-resolver.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAgE9B;;;;;;;GAOG;AACH,iBAAS,kBAAkB,CACzB,UAAU,EAAE,MAAM,EAClB,GAAG,OAAO,EAAE,GAAG,GACd,OAAO,CAAC,cAAc,GAAG,IAAI,CAG/B;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -47,9 +47,6 @@ class MiddlewareResolver {
|
|
|
47
47
|
const middleware = require(hasMiddleware);
|
|
48
48
|
return middleware(...options) || middleware.default(...options);
|
|
49
49
|
}
|
|
50
|
-
else {
|
|
51
|
-
this.logger.warn(`Middleware [${middlewareName}] not installed. Please install it using your package manager.`, "middleware-resolver");
|
|
52
|
-
}
|
|
53
50
|
return null;
|
|
54
51
|
}
|
|
55
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware-resolver.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-resolver.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware-resolver.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-resolver.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAgE9B;;;;;;;GAOG;AACH,iBAAS,kBAAkB,CACzB,UAAU,EAAE,MAAM,EAClB,GAAG,OAAO,EAAE,GAAG,GACd,OAAO,CAAC,cAAc,GAAG,IAAI,CAG/B;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -68,14 +68,9 @@
|
|
|
68
68
|
"lint:fix": "eslint \"packages/**/*.ts\" --fix"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"dotenv": "^16.0.3",
|
|
72
|
-
"express": "^4.18.2",
|
|
73
71
|
"inversify": "^6.0.1",
|
|
74
72
|
"inversify-binding-decorators": "^4.0.0",
|
|
75
|
-
"
|
|
76
|
-
"reflect-metadata": "^0.1.13",
|
|
77
|
-
"winston": "^3.8.2",
|
|
78
|
-
"winston-daily-rotate-file": "^4.7.1"
|
|
73
|
+
"reflect-metadata": "^0.1.13"
|
|
79
74
|
},
|
|
80
75
|
"devDependencies": {
|
|
81
76
|
"@commitlint/cli": "^17.7.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -68,14 +68,9 @@
|
|
|
68
68
|
"lint:fix": "eslint \"packages/**/*.ts\" --fix"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"dotenv": "^16.0.3",
|
|
72
|
-
"express": "^4.18.2",
|
|
73
71
|
"inversify": "^6.0.1",
|
|
74
72
|
"inversify-binding-decorators": "^4.0.0",
|
|
75
|
-
"
|
|
76
|
-
"reflect-metadata": "^0.1.13",
|
|
77
|
-
"winston": "^3.8.2",
|
|
78
|
-
"winston-daily-rotate-file": "^4.7.1"
|
|
73
|
+
"reflect-metadata": "^0.1.13"
|
|
79
74
|
},
|
|
80
75
|
"devDependencies": {
|
|
81
76
|
"@commitlint/cli": "^17.7.1",
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
var GeneralLogger_1;
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.log = exports.GeneralLogger = exports.LogLevel = void 0;
|
|
17
|
-
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
18
|
-
const winston_1 = require("winston");
|
|
19
|
-
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
20
|
-
/**
|
|
21
|
-
* LogLevel enumeration defines the available log levels.
|
|
22
|
-
*/
|
|
23
|
-
var LogLevel;
|
|
24
|
-
(function (LogLevel) {
|
|
25
|
-
LogLevel[LogLevel["Debug"] = 0] = "Debug";
|
|
26
|
-
LogLevel[LogLevel["Error"] = 1] = "Error";
|
|
27
|
-
LogLevel[LogLevel["Info"] = 2] = "Info";
|
|
28
|
-
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
29
|
-
/**
|
|
30
|
-
* GeneralLogger class is a utility class to manage logging within the application.
|
|
31
|
-
*/
|
|
32
|
-
let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
|
|
33
|
-
constructor() {
|
|
34
|
-
this.logger = (0, winston_1.createLogger)(this.createLoggerOptions());
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Creates a console transport for logging.
|
|
38
|
-
* @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
|
|
39
|
-
*/
|
|
40
|
-
createConsoleTransport() {
|
|
41
|
-
const consoleTransport = new winston_1.transports.Console({
|
|
42
|
-
level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
|
|
43
|
-
handleExceptions: false,
|
|
44
|
-
handleRejections: true,
|
|
45
|
-
});
|
|
46
|
-
return consoleTransport;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Creates a rotational file transport for logging.
|
|
50
|
-
* @returns {DailyRotateFile} A Winston daily rotate file transport instance.
|
|
51
|
-
*/
|
|
52
|
-
createRotationalFileTransport() {
|
|
53
|
-
const rotationalFileTransport = new winston_daily_rotate_file_1.default({
|
|
54
|
-
level: "error",
|
|
55
|
-
filename: "logs/general-%DATE%.log",
|
|
56
|
-
datePattern: "YYYY-MM-DD",
|
|
57
|
-
zippedArchive: true,
|
|
58
|
-
maxSize: "20m",
|
|
59
|
-
maxFiles: "7d",
|
|
60
|
-
silent: false,
|
|
61
|
-
});
|
|
62
|
-
return rotationalFileTransport;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Creates a logger options object for Winston.
|
|
66
|
-
* @returns {LoggerOptions} A Winston logger options object.
|
|
67
|
-
*/
|
|
68
|
-
createLoggerOptions() {
|
|
69
|
-
const loggerOptions = {
|
|
70
|
-
transports: [
|
|
71
|
-
this.createConsoleTransport(),
|
|
72
|
-
this.createRotationalFileTransport(),
|
|
73
|
-
],
|
|
74
|
-
defaultMeta: { service: "service-unknown" },
|
|
75
|
-
format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.label({ label: "core-api" }), winston_1.format.printf(({ timestamp, level, message, service, label }) => {
|
|
76
|
-
return `[${timestamp}] [${label}] [${service}] ${level}: ${message}`;
|
|
77
|
-
})),
|
|
78
|
-
};
|
|
79
|
-
return loggerOptions;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Retrieves the path and line number of the error.
|
|
83
|
-
* @param error - An Error object containing error details.
|
|
84
|
-
* @returns {string} A string containing the path and line number of the error.
|
|
85
|
-
*/
|
|
86
|
-
getPathAndLine(error) {
|
|
87
|
-
let pathLine = "";
|
|
88
|
-
if (error.stack) {
|
|
89
|
-
const callerLine = error.stack.split("\n")[1];
|
|
90
|
-
const index = callerLine.indexOf("at ");
|
|
91
|
-
pathLine = callerLine.substring(index + +2, callerLine.length);
|
|
92
|
-
}
|
|
93
|
-
return pathLine;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Logs a message or error with the specified log level and service.
|
|
97
|
-
* @param logLevel - The log level to use (Debug, Error, or Info).
|
|
98
|
-
* @param content - The message or Error object to log.
|
|
99
|
-
* @param service - The service name (optional) associated with the log.
|
|
100
|
-
*/
|
|
101
|
-
log(logLevel, content, service) {
|
|
102
|
-
let pathLine = "";
|
|
103
|
-
let logMessageFormat = "";
|
|
104
|
-
if (typeof content === "object") {
|
|
105
|
-
pathLine = this.getPathAndLine(content);
|
|
106
|
-
logMessageFormat = `${content.message} - (${content.name}) [file: %s]`;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
logMessageFormat = content;
|
|
110
|
-
}
|
|
111
|
-
switch (logLevel) {
|
|
112
|
-
case LogLevel.Debug:
|
|
113
|
-
console.log(logMessageFormat, pathLine, { service });
|
|
114
|
-
break;
|
|
115
|
-
case LogLevel.Error:
|
|
116
|
-
this.logger.error(logMessageFormat, pathLine, { service });
|
|
117
|
-
break;
|
|
118
|
-
case LogLevel.Info:
|
|
119
|
-
this.logger.info(content, { service });
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
exports.GeneralLogger = GeneralLogger;
|
|
125
|
-
exports.GeneralLogger = GeneralLogger = GeneralLogger_1 = __decorate([
|
|
126
|
-
(0, inversify_binding_decorators_1.provide)(GeneralLogger_1),
|
|
127
|
-
__metadata("design:paramtypes", [])
|
|
128
|
-
], GeneralLogger);
|
|
129
|
-
const Log = new GeneralLogger();
|
|
130
|
-
const log = Log.log.bind(Log);
|
|
131
|
-
exports.log = log;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LogLevel enumeration defines the available log levels.
|
|
3
|
-
*/
|
|
4
|
-
declare enum LogLevel {
|
|
5
|
-
Debug = 0,
|
|
6
|
-
Error = 1,
|
|
7
|
-
Info = 2
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* GeneralLogger class is a utility class to manage logging within the application.
|
|
11
|
-
*/
|
|
12
|
-
declare class GeneralLogger {
|
|
13
|
-
private logger;
|
|
14
|
-
constructor();
|
|
15
|
-
/**
|
|
16
|
-
* Creates a console transport for logging.
|
|
17
|
-
* @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
|
|
18
|
-
*/
|
|
19
|
-
private createConsoleTransport;
|
|
20
|
-
/**
|
|
21
|
-
* Creates a rotational file transport for logging.
|
|
22
|
-
* @returns {DailyRotateFile} A Winston daily rotate file transport instance.
|
|
23
|
-
*/
|
|
24
|
-
private createRotationalFileTransport;
|
|
25
|
-
/**
|
|
26
|
-
* Creates a logger options object for Winston.
|
|
27
|
-
* @returns {LoggerOptions} A Winston logger options object.
|
|
28
|
-
*/
|
|
29
|
-
private createLoggerOptions;
|
|
30
|
-
/**
|
|
31
|
-
* Retrieves the path and line number of the error.
|
|
32
|
-
* @param error - An Error object containing error details.
|
|
33
|
-
* @returns {string} A string containing the path and line number of the error.
|
|
34
|
-
*/
|
|
35
|
-
private getPathAndLine;
|
|
36
|
-
/**
|
|
37
|
-
* Logs a message or error with the specified log level and service.
|
|
38
|
-
* @param logLevel - The log level to use (Debug, Error, or Info).
|
|
39
|
-
* @param content - The message or Error object to log.
|
|
40
|
-
* @param service - The service name (optional) associated with the log.
|
|
41
|
-
*/
|
|
42
|
-
log(logLevel: LogLevel, content: Error | string, service?: string): void;
|
|
43
|
-
}
|
|
44
|
-
declare const log: (logLevel: LogLevel, content: Error | string, service?: string) => void;
|
|
45
|
-
export { LogLevel, GeneralLogger, log };
|
|
46
|
-
//# sourceMappingURL=winston-logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/provider/logger/winston-logger.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,aAAK,QAAQ;IACX,KAAK,IAAA;IACL,KAAK,IAAA;IACL,IAAI,IAAA;CACL;AAED;;GAEG;AACH,cACM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAS;;IAMvB;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;;OAGG;IACH,OAAO,CAAC,6BAA6B;IAcrC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAYtB;;;;;OAKG;IACI,GAAG,CACR,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GAAG,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM,GACf,IAAI;CAyBR;AAGD,QAAA,MAAM,GAAG,aA/BK,QAAQ,WACT,KAAK,GAAG,MAAM,YACb,MAAM,KACf,IA4BwB,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
var GeneralLogger_1;
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.log = exports.GeneralLogger = exports.LogLevel = void 0;
|
|
17
|
-
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
18
|
-
const winston_1 = require("winston");
|
|
19
|
-
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
20
|
-
/**
|
|
21
|
-
* LogLevel enumeration defines the available log levels.
|
|
22
|
-
*/
|
|
23
|
-
var LogLevel;
|
|
24
|
-
(function (LogLevel) {
|
|
25
|
-
LogLevel[LogLevel["Debug"] = 0] = "Debug";
|
|
26
|
-
LogLevel[LogLevel["Error"] = 1] = "Error";
|
|
27
|
-
LogLevel[LogLevel["Info"] = 2] = "Info";
|
|
28
|
-
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
29
|
-
/**
|
|
30
|
-
* GeneralLogger class is a utility class to manage logging within the application.
|
|
31
|
-
*/
|
|
32
|
-
let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
|
|
33
|
-
logger;
|
|
34
|
-
constructor() {
|
|
35
|
-
this.logger = (0, winston_1.createLogger)(this.createLoggerOptions());
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Creates a console transport for logging.
|
|
39
|
-
* @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
|
|
40
|
-
*/
|
|
41
|
-
createConsoleTransport() {
|
|
42
|
-
const consoleTransport = new winston_1.transports.Console({
|
|
43
|
-
level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
|
|
44
|
-
handleExceptions: false,
|
|
45
|
-
handleRejections: true,
|
|
46
|
-
});
|
|
47
|
-
return consoleTransport;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Creates a rotational file transport for logging.
|
|
51
|
-
* @returns {DailyRotateFile} A Winston daily rotate file transport instance.
|
|
52
|
-
*/
|
|
53
|
-
createRotationalFileTransport() {
|
|
54
|
-
const rotationalFileTransport = new winston_daily_rotate_file_1.default({
|
|
55
|
-
level: "error",
|
|
56
|
-
filename: "logs/general-%DATE%.log",
|
|
57
|
-
datePattern: "YYYY-MM-DD",
|
|
58
|
-
zippedArchive: true,
|
|
59
|
-
maxSize: "20m",
|
|
60
|
-
maxFiles: "7d",
|
|
61
|
-
silent: false,
|
|
62
|
-
});
|
|
63
|
-
return rotationalFileTransport;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Creates a logger options object for Winston.
|
|
67
|
-
* @returns {LoggerOptions} A Winston logger options object.
|
|
68
|
-
*/
|
|
69
|
-
createLoggerOptions() {
|
|
70
|
-
const loggerOptions = {
|
|
71
|
-
transports: [
|
|
72
|
-
this.createConsoleTransport(),
|
|
73
|
-
this.createRotationalFileTransport(),
|
|
74
|
-
],
|
|
75
|
-
defaultMeta: { service: "service-unknown" },
|
|
76
|
-
format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.label({ label: "core-api" }), winston_1.format.printf(({ timestamp, level, message, service, label }) => {
|
|
77
|
-
return `[${timestamp}] [${label}] [${service}] ${level}: ${message}`;
|
|
78
|
-
})),
|
|
79
|
-
};
|
|
80
|
-
return loggerOptions;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Retrieves the path and line number of the error.
|
|
84
|
-
* @param error - An Error object containing error details.
|
|
85
|
-
* @returns {string} A string containing the path and line number of the error.
|
|
86
|
-
*/
|
|
87
|
-
getPathAndLine(error) {
|
|
88
|
-
let pathLine = "";
|
|
89
|
-
if (error.stack) {
|
|
90
|
-
const callerLine = error.stack.split("\n")[1];
|
|
91
|
-
const index = callerLine.indexOf("at ");
|
|
92
|
-
pathLine = callerLine.substring(index + +2, callerLine.length);
|
|
93
|
-
}
|
|
94
|
-
return pathLine;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Logs a message or error with the specified log level and service.
|
|
98
|
-
* @param logLevel - The log level to use (Debug, Error, or Info).
|
|
99
|
-
* @param content - The message or Error object to log.
|
|
100
|
-
* @param service - The service name (optional) associated with the log.
|
|
101
|
-
*/
|
|
102
|
-
log(logLevel, content, service) {
|
|
103
|
-
let pathLine = "";
|
|
104
|
-
let logMessageFormat = "";
|
|
105
|
-
if (typeof content === "object") {
|
|
106
|
-
pathLine = this.getPathAndLine(content);
|
|
107
|
-
logMessageFormat = `${content.message} - (${content.name}) [file: %s]`;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
logMessageFormat = content;
|
|
111
|
-
}
|
|
112
|
-
switch (logLevel) {
|
|
113
|
-
case LogLevel.Debug:
|
|
114
|
-
console.log(logMessageFormat, pathLine, { service });
|
|
115
|
-
break;
|
|
116
|
-
case LogLevel.Error:
|
|
117
|
-
this.logger.error(logMessageFormat, pathLine, { service });
|
|
118
|
-
break;
|
|
119
|
-
case LogLevel.Info:
|
|
120
|
-
this.logger.info(content, { service });
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
exports.GeneralLogger = GeneralLogger;
|
|
126
|
-
exports.GeneralLogger = GeneralLogger = GeneralLogger_1 = __decorate([
|
|
127
|
-
(0, inversify_binding_decorators_1.provide)(GeneralLogger_1),
|
|
128
|
-
__metadata("design:paramtypes", [])
|
|
129
|
-
], GeneralLogger);
|
|
130
|
-
const Log = new GeneralLogger();
|
|
131
|
-
const log = Log.log.bind(Log);
|
|
132
|
-
exports.log = log;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LogLevel enumeration defines the available log levels.
|
|
3
|
-
*/
|
|
4
|
-
declare enum LogLevel {
|
|
5
|
-
Debug = 0,
|
|
6
|
-
Error = 1,
|
|
7
|
-
Info = 2
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* GeneralLogger class is a utility class to manage logging within the application.
|
|
11
|
-
*/
|
|
12
|
-
declare class GeneralLogger {
|
|
13
|
-
private logger;
|
|
14
|
-
constructor();
|
|
15
|
-
/**
|
|
16
|
-
* Creates a console transport for logging.
|
|
17
|
-
* @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
|
|
18
|
-
*/
|
|
19
|
-
private createConsoleTransport;
|
|
20
|
-
/**
|
|
21
|
-
* Creates a rotational file transport for logging.
|
|
22
|
-
* @returns {DailyRotateFile} A Winston daily rotate file transport instance.
|
|
23
|
-
*/
|
|
24
|
-
private createRotationalFileTransport;
|
|
25
|
-
/**
|
|
26
|
-
* Creates a logger options object for Winston.
|
|
27
|
-
* @returns {LoggerOptions} A Winston logger options object.
|
|
28
|
-
*/
|
|
29
|
-
private createLoggerOptions;
|
|
30
|
-
/**
|
|
31
|
-
* Retrieves the path and line number of the error.
|
|
32
|
-
* @param error - An Error object containing error details.
|
|
33
|
-
* @returns {string} A string containing the path and line number of the error.
|
|
34
|
-
*/
|
|
35
|
-
private getPathAndLine;
|
|
36
|
-
/**
|
|
37
|
-
* Logs a message or error with the specified log level and service.
|
|
38
|
-
* @param logLevel - The log level to use (Debug, Error, or Info).
|
|
39
|
-
* @param content - The message or Error object to log.
|
|
40
|
-
* @param service - The service name (optional) associated with the log.
|
|
41
|
-
*/
|
|
42
|
-
log(logLevel: LogLevel, content: Error | string, service?: string): void;
|
|
43
|
-
}
|
|
44
|
-
declare const log: (logLevel: LogLevel, content: Error | string, service?: string) => void;
|
|
45
|
-
export { LogLevel, GeneralLogger, log };
|
|
46
|
-
//# sourceMappingURL=winston-logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/provider/logger/winston-logger.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,aAAK,QAAQ;IACX,KAAK,IAAA;IACL,KAAK,IAAA;IACL,IAAI,IAAA;CACL;AAED;;GAEG;AACH,cACM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAS;;IAMvB;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;;OAGG;IACH,OAAO,CAAC,6BAA6B;IAcrC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAYtB;;;;;OAKG;IACI,GAAG,CACR,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GAAG,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM,GACf,IAAI;CAyBR;AAGD,QAAA,MAAM,GAAG,aA/BK,QAAQ,WACT,KAAK,GAAG,MAAM,YACb,MAAM,KACf,IA4BwB,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC"}
|