@minimaltech/node-infra 0.3.9 → 0.3.10
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/dist/helpers/logger/application-logger.d.ts +10 -4
- package/dist/helpers/logger/application-logger.js +31 -17
- package/dist/helpers/logger/application-logger.js.map +1 -1
- package/dist/helpers/logger/default-logger.d.ts +12 -0
- package/dist/helpers/logger/default-logger.js +32 -22
- package/dist/helpers/logger/default-logger.js.map +1 -1
- package/dist/helpers/logger/factory.d.ts +2 -2
- package/dist/helpers/logger/factory.js +2 -2
- package/dist/helpers/logger/factory.js.map +1 -1
- package/package.json +1 -1
@@ -1,13 +1,19 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import winston from 'winston';
|
2
|
+
export declare class Logger {
|
3
3
|
readonly _environment: string | undefined;
|
4
|
-
|
4
|
+
private scopes;
|
5
|
+
private customLogger?;
|
6
|
+
constructor(opts?: {
|
7
|
+
customLogger?: winston.Logger;
|
8
|
+
});
|
9
|
+
private _getLogger;
|
5
10
|
withScope(scope: string): this;
|
6
11
|
private _enhanceMessage;
|
12
|
+
private _doLog;
|
7
13
|
debug(message: string, ...args: any[]): void;
|
8
14
|
info(message: string, ...args: any[]): void;
|
15
|
+
warn(message: string, ...args: any[]): void;
|
9
16
|
error(message: string, ...args: any[]): void;
|
10
17
|
}
|
11
18
|
export declare class ApplicationLogger extends Logger {
|
12
19
|
}
|
13
|
-
export {};
|
@@ -3,15 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.ApplicationLogger = void 0;
|
6
|
+
exports.ApplicationLogger = exports.Logger = void 0;
|
7
7
|
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
8
8
|
const default_logger_1 = require("./default-logger");
|
9
|
+
const utilities_1 = require("../../utilities");
|
9
10
|
const LOG_ENVIRONMENTS = new Set(['development', 'alpha', 'beta', 'staging']);
|
10
11
|
class Logger {
|
11
|
-
constructor() {
|
12
|
+
constructor(opts) {
|
12
13
|
this.scopes = [];
|
13
14
|
this._environment = process.env.NODE_ENV;
|
15
|
+
this.customLogger = opts === null || opts === void 0 ? void 0 : opts.customLogger;
|
14
16
|
}
|
17
|
+
// ---------------------------------------------------------------------
|
18
|
+
_getLogger() {
|
19
|
+
var _a;
|
20
|
+
return (_a = this.customLogger) !== null && _a !== void 0 ? _a : default_logger_1.applicationLogger;
|
21
|
+
}
|
22
|
+
// ---------------------------------------------------------------------
|
15
23
|
withScope(scope) {
|
16
24
|
if (this.scopes.length < 2) {
|
17
25
|
this.scopes.push(scope);
|
@@ -23,6 +31,7 @@ class Logger {
|
|
23
31
|
this.scopes[1] = scope;
|
24
32
|
return this;
|
25
33
|
}
|
34
|
+
// ---------------------------------------------------------------------
|
26
35
|
_enhanceMessage(parts, message) {
|
27
36
|
const enhanced = parts === null || parts === void 0 ? void 0 : parts.reduce((prevState = '', current) => {
|
28
37
|
if ((0, isEmpty_1.default)(prevState)) {
|
@@ -32,34 +41,39 @@ class Logger {
|
|
32
41
|
}, '');
|
33
42
|
return `[${enhanced}]${message}`;
|
34
43
|
}
|
44
|
+
// ---------------------------------------------------------------------
|
45
|
+
_doLog(level, message, ...args) {
|
46
|
+
const logger = this._getLogger();
|
47
|
+
if (!logger) {
|
48
|
+
throw (0, utilities_1.getError)({ message: `[doLog] Level: ${level} | Invalid logger instance!` });
|
49
|
+
}
|
50
|
+
const enhanced = this._enhanceMessage(this.scopes, message);
|
51
|
+
logger.log(level, enhanced, ...args);
|
52
|
+
}
|
53
|
+
// ---------------------------------------------------------------------
|
35
54
|
debug(message, ...args) {
|
36
55
|
if (this._environment && !LOG_ENVIRONMENTS.has(this._environment)) {
|
37
56
|
return;
|
38
57
|
}
|
39
|
-
if (!default_logger_1.applicationLogger) {
|
40
|
-
throw new Error('Invalid logger instance!');
|
41
|
-
}
|
42
58
|
if (!process.env.DEBUG) {
|
43
59
|
return;
|
44
60
|
}
|
45
|
-
|
46
|
-
default_logger_1.applicationLogger.log('debug', enhanced, ...args);
|
61
|
+
this._doLog('debug', message, ...args);
|
47
62
|
}
|
63
|
+
// ---------------------------------------------------------------------
|
48
64
|
info(message, ...args) {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
65
|
+
this._doLog('info', message, ...args);
|
66
|
+
}
|
67
|
+
// ---------------------------------------------------------------------
|
68
|
+
warn(message, ...args) {
|
69
|
+
this._doLog('warn', message, ...args);
|
54
70
|
}
|
71
|
+
// ---------------------------------------------------------------------
|
55
72
|
error(message, ...args) {
|
56
|
-
|
57
|
-
throw new Error('Invalid logger instance!');
|
58
|
-
}
|
59
|
-
const enhanced = this._enhanceMessage(this.scopes, message);
|
60
|
-
default_logger_1.applicationLogger.log('error', enhanced, ...args);
|
73
|
+
this._doLog('error', message, ...args);
|
61
74
|
}
|
62
75
|
}
|
76
|
+
exports.Logger = Logger;
|
63
77
|
class ApplicationLogger extends Logger {
|
64
78
|
}
|
65
79
|
exports.ApplicationLogger = ApplicationLogger;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"application-logger.js","sourceRoot":"","sources":["../../../src/helpers/logger/application-logger.ts"],"names":[],"mappings":";;;;;;AAAA,6DAAqC;AACrC,qDAAqD;
|
1
|
+
{"version":3,"file":"application-logger.js","sourceRoot":"","sources":["../../../src/helpers/logger/application-logger.ts"],"names":[],"mappings":";;;;;;AAAA,6DAAqC;AACrC,qDAAqD;AACrD,2CAAuC;AAGvC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAE9E,MAAa,MAAM;IAMjB,YAAY,IAAwC;QAH5C,WAAM,GAAa,EAAE,CAAC;QAI5B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC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ter: ReturnType<typeof format.combine>;
|
4
|
+
export declare const defineCustomLogger: (opts: {
|
5
|
+
transports: {
|
6
|
+
info: {
|
7
|
+
folder: string;
|
8
|
+
prefix: string;
|
9
|
+
};
|
10
|
+
error: {
|
11
|
+
folder: string;
|
12
|
+
prefix: string;
|
13
|
+
};
|
14
|
+
};
|
15
|
+
}) => import("winston").Logger;
|
4
16
|
export declare const applicationLogger: import("winston").Logger;
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
var _a;
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
-
exports.applicationLogger = exports.applicationLogFormatter = void 0;
|
7
|
+
exports.applicationLogger = exports.defineCustomLogger = exports.applicationLogFormatter = void 0;
|
8
8
|
const path_1 = __importDefault(require("path"));
|
9
9
|
const winston_1 = require("winston");
|
10
10
|
require("winston-daily-rotate-file");
|
@@ -14,27 +14,37 @@ const LOGGER_PREFIX = common_1.App.APPLICATION_NAME;
|
|
14
14
|
const consoleLogTransport = new winston_1.transports.Console({
|
15
15
|
level: 'debug',
|
16
16
|
});
|
17
|
-
const infoLogTransport = new winston_1.transports.DailyRotateFile({
|
18
|
-
frequency: '1h',
|
19
|
-
maxSize: '100m',
|
20
|
-
maxFiles: '5d',
|
21
|
-
datePattern: 'YYYYMMDD_HH',
|
22
|
-
filename: path_1.default.join(LOGGER_FOLDER_PATH, `/${LOGGER_PREFIX}-info-%DATE%.log`),
|
23
|
-
level: 'info',
|
24
|
-
});
|
25
|
-
const errorLogTransport = new winston_1.transports.DailyRotateFile({
|
26
|
-
frequency: '1h',
|
27
|
-
maxSize: '100m',
|
28
|
-
maxFiles: '5d',
|
29
|
-
datePattern: 'YYYYMMDD_HH',
|
30
|
-
filename: path_1.default.join(LOGGER_FOLDER_PATH, `/${LOGGER_PREFIX}-error-%DATE%.log`),
|
31
|
-
level: 'error',
|
32
|
-
});
|
33
17
|
exports.applicationLogFormatter = winston_1.format.combine(winston_1.format.label({ label: LOGGER_PREFIX }), winston_1.format.splat(), winston_1.format.align(), winston_1.format.timestamp(), winston_1.format.simple(), winston_1.format.colorize(), winston_1.format.printf(({ level, message, label, timestamp }) => `${timestamp} [${label}] ${level}: ${message}`), winston_1.format.errors({ stack: true }));
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
18
|
+
const defineCustomLogger = (opts) => {
|
19
|
+
const { transports: { info, error }, } = opts;
|
20
|
+
const infoTransport = new winston_1.transports.DailyRotateFile({
|
21
|
+
frequency: '1h',
|
22
|
+
maxSize: '100m',
|
23
|
+
maxFiles: '5d',
|
24
|
+
datePattern: 'YYYYMMDD_HH',
|
25
|
+
filename: path_1.default.join(info.folder, `/${info.prefix}-info-%DATE%.log`),
|
26
|
+
level: 'info',
|
27
|
+
});
|
28
|
+
const errorTransport = new winston_1.transports.DailyRotateFile({
|
29
|
+
frequency: '1h',
|
30
|
+
maxSize: '100m',
|
31
|
+
maxFiles: '5d',
|
32
|
+
datePattern: 'YYYYMMDD_HH',
|
33
|
+
filename: path_1.default.join(error.folder, `/${error.prefix}-error-%DATE%.log`),
|
34
|
+
level: 'error',
|
35
|
+
});
|
36
|
+
return (0, winston_1.createLogger)({
|
37
|
+
format: exports.applicationLogFormatter,
|
38
|
+
exitOnError: false,
|
39
|
+
transports: [consoleLogTransport, infoTransport, errorTransport],
|
40
|
+
exceptionHandlers: [consoleLogTransport, errorTransport],
|
41
|
+
});
|
42
|
+
};
|
43
|
+
exports.defineCustomLogger = defineCustomLogger;
|
44
|
+
exports.applicationLogger = (0, exports.defineCustomLogger)({
|
45
|
+
transports: {
|
46
|
+
info: { folder: LOGGER_FOLDER_PATH, prefix: LOGGER_PREFIX },
|
47
|
+
error: { folder: LOGGER_FOLDER_PATH, prefix: LOGGER_PREFIX },
|
48
|
+
},
|
39
49
|
});
|
40
50
|
//# sourceMappingURL=default-logger.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"default-logger.js","sourceRoot":"","sources":["../../../src/helpers/logger/default-logger.ts"],"names":[],"mappings":";;;;;;;AAAA,gDAAwB;AACxB,qCAA2D;AAC3D,qCAAmC;AACnC,qCAA+B;AAE/B,MAAM,kBAAkB,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,0BAA0B,mCAAI,IAAI,CAAC;AAC1E,MAAM,aAAa,GAAG,YAAG,CAAC,gBAAgB,CAAC;AAE3C,MAAM,mBAAmB,GAAG,IAAI,oBAAU,CAAC,OAAO,CAAC;IACjD,KAAK,EAAE,OAAO;CACf,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"default-logger.js","sourceRoot":"","sources":["../../../src/helpers/logger/default-logger.ts"],"names":[],"mappings":";;;;;;;AAAA,gDAAwB;AACxB,qCAA2D;AAC3D,qCAAmC;AACnC,qCAA+B;AAE/B,MAAM,kBAAkB,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,0BAA0B,mCAAI,IAAI,CAAC;AAC1E,MAAM,aAAa,GAAG,YAAG,CAAC,gBAAgB,CAAC;AAE3C,MAAM,mBAAmB,GAAG,IAAI,oBAAU,CAAC,OAAO,CAAC;IACjD,KAAK,EAAE,OAAO;CACf,CAAC,CAAC;AAEU,QAAA,uBAAuB,GAAsC,gBAAM,CAAC,OAAO,CACtF,gBAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,EACtC,gBAAM,CAAC,KAAK,EAAE,EACd,gBAAM,CAAC,KAAK,EAAE,EACd,gBAAM,CAAC,SAAS,EAAE,EAClB,gBAAM,CAAC,MAAM,EAAE,EACf,gBAAM,CAAC,QAAQ,EAAE,EACjB,gBAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,GAAG,SAAS,KAAK,KAAK,KAAK,KAAK,KAAK,OAAO,EAAE,CAAC,EACvG,gBAAM,CAAC,MAAM,CAAC,EAAE,KAAK,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,aAAa,EAAE;KAC7D;CACF,CAAC,CAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Logger } from './application-logger';
|
2
2
|
export declare class LoggerFactory {
|
3
|
-
static getLogger(scopes: string[]):
|
3
|
+
static getLogger(scopes: string[], customLogger?: Logger): Logger;
|
4
4
|
}
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LoggerFactory = void 0;
|
4
4
|
const application_logger_1 = require("./application-logger");
|
5
5
|
class LoggerFactory {
|
6
|
-
static getLogger(scopes) {
|
7
|
-
const logger = new application_logger_1.ApplicationLogger();
|
6
|
+
static getLogger(scopes, customLogger) {
|
7
|
+
const logger = customLogger !== null && customLogger !== void 0 ? customLogger : new application_logger_1.ApplicationLogger();
|
8
8
|
logger.withScope(scopes.join('-'));
|
9
9
|
return logger;
|
10
10
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/helpers/logger/factory.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/helpers/logger/factory.ts"],"names":[],"mappings":";;;AAAA,6DAAiE;AAEjE,MAAa,aAAa;IACxB,MAAM,CAAC,SAAS,CAAC,MAAgB,EAAE,YAAqB;QACtD,MAAM,MAAM,GAAG,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,IAAI,sCAAiB,EAAE,CAAC;QACvD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAND,sCAMC"}
|