badmfck-api-server 1.3.7 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -43,7 +43,7 @@ async function Initializer(services) {
|
|
43
43
|
exports.Initializer = Initializer;
|
44
44
|
class APIService extends BaseService_1.BaseService {
|
45
45
|
static nextLogID = 0;
|
46
|
-
version = "1.3.
|
46
|
+
version = "1.3.8";
|
47
47
|
options;
|
48
48
|
netLog = [];
|
49
49
|
constructor(options) {
|
@@ -177,7 +177,7 @@ class APIService extends BaseService_1.BaseService {
|
|
177
177
|
}, tme, req.path);
|
178
178
|
});
|
179
179
|
app.listen(this.options.port, () => {
|
180
|
-
|
180
|
+
(0, LogService_1.logCrit)('API Service started at: ' + this.options.port + ", with base endpoint:" + this.options.baseEndPoint + ", ver.: " + this.version);
|
181
181
|
});
|
182
182
|
}
|
183
183
|
sendResponse(res, data, requestTime, endpoint, log) {
|
@@ -1,13 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.BaseService = void 0;
|
4
|
+
const LogService_1 = require("./LogService");
|
4
5
|
class BaseService {
|
5
6
|
name;
|
6
7
|
constructor(name) {
|
7
8
|
this.name = name;
|
8
9
|
}
|
9
10
|
async init() {
|
10
|
-
|
11
|
+
(0, LogService_1.logInfo)("Service: " + this.name + " initialized");
|
11
12
|
}
|
12
13
|
applicationReady() { }
|
13
14
|
}
|
@@ -1,9 +1,15 @@
|
|
1
1
|
import Signal, { Req } from "badmfck-signal";
|
2
2
|
import { BaseService } from "./BaseService";
|
3
|
-
export
|
3
|
+
export declare enum LOG_LEVEL {
|
4
|
+
ALL = 0,
|
5
|
+
INFO = 1,
|
6
|
+
WARN = 2,
|
7
|
+
ERROR = 3,
|
8
|
+
CRIT = 4
|
9
|
+
}
|
4
10
|
export interface ILogItem {
|
5
11
|
id: number;
|
6
|
-
level:
|
12
|
+
level: LOG_LEVEL;
|
7
13
|
time: number;
|
8
14
|
text: string;
|
9
15
|
date: string;
|
@@ -18,11 +24,11 @@ export declare const logWarn: (message: any, ...optional: any[]) => void;
|
|
18
24
|
export declare const logCrit: (message: any, ...optional: any[]) => void;
|
19
25
|
export declare const logError: (message: any, ...optional: any[]) => void;
|
20
26
|
export declare const S_LOG: Signal<{
|
21
|
-
level:
|
27
|
+
level: LOG_LEVEL;
|
22
28
|
data: any[];
|
23
29
|
}>;
|
24
30
|
export declare const S_LOG_CREATED: Signal<ILogItem>;
|
25
|
-
export declare const S_LOG_CHANGE_LEVEL: Signal<
|
31
|
+
export declare const S_LOG_CHANGE_LEVEL: Signal<LOG_LEVEL>;
|
26
32
|
export declare const S_LOG_FLUSH: Signal<void>;
|
27
33
|
export declare const REQ_LOG: Req<{
|
28
34
|
lastID: number;
|
@@ -31,7 +37,7 @@ export declare class LogService extends BaseService {
|
|
31
37
|
epoch: number;
|
32
38
|
log: ILogItem[];
|
33
39
|
options: ILogServiceOptions;
|
34
|
-
level:
|
40
|
+
level: LOG_LEVEL;
|
35
41
|
constructor(opt?: ILogServiceOptions);
|
36
42
|
init(): Promise<void>;
|
37
43
|
createDate(d?: Date): string;
|
@@ -23,22 +23,30 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
23
|
return result;
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.LogService = exports.REQ_LOG = exports.S_LOG_FLUSH = exports.S_LOG_CHANGE_LEVEL = exports.S_LOG_CREATED = exports.S_LOG = exports.logError = exports.logCrit = exports.logWarn = exports.logInfo = exports.getDefaultLogOptions = void 0;
|
26
|
+
exports.LogService = exports.REQ_LOG = exports.S_LOG_FLUSH = exports.S_LOG_CHANGE_LEVEL = exports.S_LOG_CREATED = exports.S_LOG = exports.logError = exports.logCrit = exports.logWarn = exports.logInfo = exports.getDefaultLogOptions = exports.LOG_LEVEL = void 0;
|
27
27
|
const badmfck_signal_1 = __importStar(require("badmfck-signal"));
|
28
28
|
const BaseService_1 = require("./BaseService");
|
29
|
+
var LOG_LEVEL;
|
30
|
+
(function (LOG_LEVEL) {
|
31
|
+
LOG_LEVEL[LOG_LEVEL["ALL"] = 0] = "ALL";
|
32
|
+
LOG_LEVEL[LOG_LEVEL["INFO"] = 1] = "INFO";
|
33
|
+
LOG_LEVEL[LOG_LEVEL["WARN"] = 2] = "WARN";
|
34
|
+
LOG_LEVEL[LOG_LEVEL["ERROR"] = 3] = "ERROR";
|
35
|
+
LOG_LEVEL[LOG_LEVEL["CRIT"] = 4] = "CRIT";
|
36
|
+
})(LOG_LEVEL || (exports.LOG_LEVEL = LOG_LEVEL = {}));
|
29
37
|
const getDefaultLogOptions = () => {
|
30
38
|
return {
|
31
39
|
stackSize: 1000
|
32
40
|
};
|
33
41
|
};
|
34
42
|
exports.getDefaultLogOptions = getDefaultLogOptions;
|
35
|
-
const logInfo = (message, ...optional) => { exports.S_LOG.invoke({ level:
|
43
|
+
const logInfo = (message, ...optional) => { exports.S_LOG.invoke({ level: LOG_LEVEL.INFO, data: [message, optional] }); };
|
36
44
|
exports.logInfo = logInfo;
|
37
|
-
const logWarn = (message, ...optional) => { exports.S_LOG.invoke({ level:
|
45
|
+
const logWarn = (message, ...optional) => { exports.S_LOG.invoke({ level: LOG_LEVEL.WARN, data: [message, optional] }); };
|
38
46
|
exports.logWarn = logWarn;
|
39
|
-
const logCrit = (message, ...optional) => { exports.S_LOG.invoke({ level:
|
47
|
+
const logCrit = (message, ...optional) => { exports.S_LOG.invoke({ level: LOG_LEVEL.CRIT, data: [message, optional] }); };
|
40
48
|
exports.logCrit = logCrit;
|
41
|
-
const logError = (message, ...optional) => { exports.S_LOG.invoke({ level:
|
49
|
+
const logError = (message, ...optional) => { exports.S_LOG.invoke({ level: LOG_LEVEL.ERROR, data: [message, optional] }); };
|
42
50
|
exports.logError = logError;
|
43
51
|
exports.S_LOG = new badmfck_signal_1.default();
|
44
52
|
exports.S_LOG_CREATED = new badmfck_signal_1.default();
|
@@ -49,7 +57,7 @@ class LogService extends BaseService_1.BaseService {
|
|
49
57
|
epoch = 1699476234961;
|
50
58
|
log = [];
|
51
59
|
options;
|
52
|
-
level =
|
60
|
+
level = LOG_LEVEL.ALL;
|
53
61
|
constructor(opt) {
|
54
62
|
super("LogService");
|
55
63
|
if (!opt)
|
@@ -69,10 +77,8 @@ class LogService extends BaseService_1.BaseService {
|
|
69
77
|
exports.S_LOG_CHANGE_LEVEL.subscribe(l => { this.level = l; });
|
70
78
|
exports.S_LOG_FLUSH.subscribe(() => this.log = []);
|
71
79
|
exports.S_LOG.subscribe((log) => {
|
72
|
-
if (log.level
|
73
|
-
|
74
|
-
return;
|
75
|
-
}
|
80
|
+
if (log.level < this.level)
|
81
|
+
return;
|
76
82
|
const msg = log.data[0];
|
77
83
|
const optional = log.data[1];
|
78
84
|
let text = this.createText(msg);
|
@@ -128,6 +134,8 @@ class LogService extends BaseService_1.BaseService {
|
|
128
134
|
res = `${data}`;
|
129
135
|
}
|
130
136
|
}
|
137
|
+
if (Array.isArray(data))
|
138
|
+
res + ", total items: " + data.length;
|
131
139
|
}
|
132
140
|
else {
|
133
141
|
res = data + "";
|