ismx-nexo-node-app 0.4.163 → 0.4.166
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.
|
@@ -1,9 +1,72 @@
|
|
|
1
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 __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const fs = __importStar(require("fs"));
|
|
27
|
+
const path = __importStar(require("path"));
|
|
3
28
|
class BusinessLogger {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.logStream = null;
|
|
31
|
+
this.currentLogFile = null;
|
|
32
|
+
}
|
|
33
|
+
file() {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
writeToFile(message) {
|
|
37
|
+
const file = this.file();
|
|
38
|
+
if (!file)
|
|
39
|
+
return;
|
|
40
|
+
if (this.currentLogFile !== file) {
|
|
41
|
+
if (this.logStream) {
|
|
42
|
+
this.logStream.end();
|
|
43
|
+
this.logStream = null;
|
|
44
|
+
}
|
|
45
|
+
const dir = path.dirname(file);
|
|
46
|
+
if (!fs.existsSync(dir))
|
|
47
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
48
|
+
this.logStream = fs.createWriteStream(file, { flags: 'a', encoding: 'utf8' });
|
|
49
|
+
this.currentLogFile = file;
|
|
50
|
+
}
|
|
51
|
+
if (this.logStream)
|
|
52
|
+
this.logStream.write(message + '\n');
|
|
53
|
+
}
|
|
54
|
+
log(level, message, writeToFile = false) {
|
|
55
|
+
const logMessage = `[${level}] ${new Date().toISOString()} -- ${message}`;
|
|
56
|
+
console.log(logMessage);
|
|
57
|
+
this.writeToFile(logMessage);
|
|
58
|
+
}
|
|
4
59
|
i(message) {
|
|
5
|
-
|
|
60
|
+
this.log("INFO", message);
|
|
61
|
+
}
|
|
62
|
+
w(message) {
|
|
63
|
+
this.log("WARN", message);
|
|
64
|
+
}
|
|
65
|
+
e(message) {
|
|
66
|
+
this.log("ERROR", message);
|
|
67
|
+
}
|
|
68
|
+
d(message) {
|
|
69
|
+
this.log("DEBUG", message);
|
|
6
70
|
}
|
|
7
|
-
;
|
|
8
71
|
}
|
|
9
72
|
exports.default = BusinessLogger;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
export default class BusinessLogger {
|
|
2
|
+
private logStream;
|
|
3
|
+
private currentLogFile;
|
|
4
|
+
constructor();
|
|
5
|
+
protected file(): string | null;
|
|
6
|
+
private writeToFile;
|
|
7
|
+
private log;
|
|
2
8
|
i(message: string): void;
|
|
9
|
+
w(message: string): void;
|
|
10
|
+
e(message: string): void;
|
|
11
|
+
d(message: string): void;
|
|
3
12
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
1
4
|
export default class BusinessLogger
|
|
2
5
|
{
|
|
6
|
+
private logStream: fs.WriteStream | null = null;
|
|
7
|
+
private currentLogFile: string | null = null;
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
protected file(): string | null {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private writeToFile(message: string) {
|
|
18
|
+
const file = this.file();
|
|
19
|
+
if (!file) return;
|
|
20
|
+
|
|
21
|
+
if (this.currentLogFile !== file) {
|
|
22
|
+
if (this.logStream) {
|
|
23
|
+
this.logStream.end();
|
|
24
|
+
this.logStream = null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const dir = path.dirname(file);
|
|
28
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
29
|
+
this.logStream = fs.createWriteStream(file, { flags: 'a', encoding: 'utf8' });
|
|
30
|
+
this.currentLogFile = file;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (this.logStream) this.logStream.write(message + '\n');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private log(level: string, message: string, writeToFile: boolean = false) {
|
|
37
|
+
const logMessage = `[${level}] ${new Date().toISOString()} -- ${message}`;
|
|
38
|
+
console.log(logMessage); this.writeToFile(logMessage);
|
|
39
|
+
}
|
|
40
|
+
|
|
3
41
|
i(message: string) {
|
|
4
|
-
|
|
5
|
-
}
|
|
42
|
+
this.log("INFO", message);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
w(message: string) {
|
|
46
|
+
this.log("WARN", message);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
e(message: string) {
|
|
50
|
+
this.log("ERROR", message);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
d(message: string) {
|
|
54
|
+
this.log("DEBUG", message);
|
|
55
|
+
}
|
|
6
56
|
}
|