ag-common 0.0.21 → 0.0.22
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,8 +1,8 @@
|
|
|
1
1
|
export declare type TLogType = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
|
|
2
2
|
export declare const GetLogLevel: (l: TLogType) => number;
|
|
3
|
-
export declare const trace: (...args: any[]) => void;
|
|
4
3
|
export declare const debug: (...args: any[]) => void;
|
|
5
4
|
export declare const info: (...args: any[]) => void;
|
|
6
5
|
export declare const warn: (...args: any[]) => void;
|
|
6
|
+
export declare const trace: (...args: any[]) => void;
|
|
7
7
|
export declare const error: (...args: any[]) => void;
|
|
8
8
|
export declare const fatal: (...args: any[]) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fatal = exports.error = exports.
|
|
3
|
+
exports.fatal = exports.error = exports.trace = exports.warn = exports.info = exports.debug = exports.GetLogLevel = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
const _1 = require(".");
|
|
6
6
|
const GetLogLevel = (l) => ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].findIndex((s) => s === l);
|
|
@@ -11,68 +11,43 @@ function dateF() {
|
|
|
11
11
|
const str = `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}`;
|
|
12
12
|
return str;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
const ret = [];
|
|
16
|
-
args.forEach((a) => {
|
|
17
|
-
a.forEach((v) => {
|
|
18
|
-
if (v !== null &&
|
|
19
|
-
typeof v !== 'undefined' &&
|
|
20
|
-
v.toString().indexOf('Error:') !== -1 &&
|
|
21
|
-
v.stack) {
|
|
22
|
-
ret.push(`${v.stack}`);
|
|
23
|
-
}
|
|
24
|
-
else if (typeof v === 'string') {
|
|
25
|
-
if (v.trim() !== 'undefined') {
|
|
26
|
-
ret.push(`${v.trim()}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else if (typeof v === 'object') {
|
|
30
|
-
ret.push(JSON.parse(JSON.stringify(v)));
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
ret.push(v);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
return ret;
|
|
38
|
-
}
|
|
39
|
-
function logprocess(type, date, args) {
|
|
14
|
+
function logprocess(type, args) {
|
|
40
15
|
var _a;
|
|
41
|
-
const msg = `[${date}] ${type} `;
|
|
42
|
-
const argsClean = args.filter(_1.notEmpty);
|
|
43
16
|
const min = (0, exports.GetLogLevel)((_a = process.env.LOG_LEVEL) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'WARN';
|
|
44
17
|
const typesLogLevel = (0, exports.GetLogLevel)(type);
|
|
45
18
|
// env ignores it
|
|
46
19
|
if (typesLogLevel < min) {
|
|
47
20
|
return;
|
|
48
21
|
}
|
|
22
|
+
////////
|
|
23
|
+
const log = [`[${dateF()}]`, type, ...args.filter(_1.notEmpty)];
|
|
49
24
|
switch (type) {
|
|
50
25
|
case 'TRACE': {
|
|
51
|
-
console.trace(
|
|
26
|
+
console.trace(...log);
|
|
52
27
|
break;
|
|
53
28
|
}
|
|
54
29
|
case 'DEBUG': {
|
|
55
|
-
console.debug(
|
|
30
|
+
console.debug(...log);
|
|
56
31
|
break;
|
|
57
32
|
}
|
|
58
33
|
case 'INFO': {
|
|
59
|
-
console.log(
|
|
34
|
+
console.log(...log);
|
|
60
35
|
break;
|
|
61
36
|
}
|
|
62
37
|
case 'WARN': {
|
|
63
|
-
console.warn(
|
|
38
|
+
console.warn(...log);
|
|
64
39
|
break;
|
|
65
40
|
}
|
|
66
41
|
case 'ERROR': {
|
|
67
|
-
console.error(
|
|
42
|
+
console.error(...log);
|
|
68
43
|
break;
|
|
69
44
|
}
|
|
70
45
|
case 'FATAL': {
|
|
71
|
-
console.error(
|
|
46
|
+
console.error(...log);
|
|
72
47
|
break;
|
|
73
48
|
}
|
|
74
49
|
default: {
|
|
75
|
-
console.log(
|
|
50
|
+
console.log(...log);
|
|
76
51
|
break;
|
|
77
52
|
}
|
|
78
53
|
}
|
|
@@ -131,23 +106,25 @@ function printStackTrace(...args) {
|
|
|
131
106
|
}
|
|
132
107
|
return callstack.join('\n');
|
|
133
108
|
}
|
|
109
|
+
const debug = (...args) => logprocess('DEBUG', args);
|
|
110
|
+
exports.debug = debug;
|
|
111
|
+
const info = (...args) => logprocess('INFO', args);
|
|
112
|
+
exports.info = info;
|
|
113
|
+
const warn = (...args) => logprocess('WARN', args);
|
|
114
|
+
exports.warn = warn;
|
|
115
|
+
//
|
|
134
116
|
const trace = (...args) => {
|
|
135
|
-
const argsNice = nicify(args);
|
|
136
117
|
args.push(printStackTrace());
|
|
137
|
-
logprocess('TRACE',
|
|
118
|
+
logprocess('TRACE', args);
|
|
138
119
|
};
|
|
139
120
|
exports.trace = trace;
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const warn = (...args) => logprocess('WARN', dateF(), nicify(args));
|
|
145
|
-
exports.warn = warn;
|
|
146
|
-
const error = (...args) => logprocess('ERROR', dateF(), nicify(args));
|
|
121
|
+
const error = (...args) => {
|
|
122
|
+
args.push(printStackTrace());
|
|
123
|
+
logprocess('ERROR', args);
|
|
124
|
+
};
|
|
147
125
|
exports.error = error;
|
|
148
126
|
const fatal = (...args) => {
|
|
149
|
-
const argsNice = nicify(args);
|
|
150
127
|
args.push(printStackTrace());
|
|
151
|
-
logprocess('FATAL',
|
|
128
|
+
logprocess('FATAL', args);
|
|
152
129
|
};
|
|
153
130
|
exports.fatal = fatal;
|
|
@@ -53,7 +53,7 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
53
53
|
((_e = ae.response) === null || _e === void 0 ? void 0 : _e.statusText) ||
|
|
54
54
|
((_f = ae.response) === null || _f === void 0 ? void 0 : _f.status) ||
|
|
55
55
|
'ERROR');
|
|
56
|
-
if (status === 403) {
|
|
56
|
+
if (status === 403 || status === 401) {
|
|
57
57
|
logout();
|
|
58
58
|
return {
|
|
59
59
|
error: ae,
|
|
@@ -76,10 +76,7 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
76
76
|
data,
|
|
77
77
|
error,
|
|
78
78
|
loading: false,
|
|
79
|
-
reFetch: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
-
const ret = func(cl);
|
|
81
|
-
return ret;
|
|
82
|
-
}),
|
|
79
|
+
reFetch: () => __awaiter(void 0, void 0, void 0, function* () { return func(cl); }),
|
|
83
80
|
url: func.toString(),
|
|
84
81
|
datetime: new Date().getTime(),
|
|
85
82
|
};
|