@domain.js/main 0.3.24 → 0.3.25
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/deps/logger/index.d.ts +1 -0
- package/dist/deps/logger/index.js +13 -16
- package/package.json +1 -1
|
@@ -4,19 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Deps = exports.Main = void 0;
|
|
7
|
-
const fs_1 =
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const util_1 = require("util");
|
|
10
11
|
const date = (offset = 0) => new Date(Date.now() + (offset | 0)).toISOString();
|
|
11
12
|
function Main(cnf, deps) {
|
|
12
|
-
const { logger: { errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
|
|
13
|
+
const { logger: { level, errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
|
|
13
14
|
const { _, uuid: { v4: uuid }, } = deps;
|
|
14
15
|
const makeDir = _.memoize((dir) => {
|
|
15
|
-
if (!fs_1.
|
|
16
|
-
fs_1.
|
|
16
|
+
if (!(0, fs_1.existsSync)(dir))
|
|
17
|
+
(0, fs_1.mkdirSync)(dir);
|
|
17
18
|
});
|
|
18
19
|
const ignores = new Set(ignoreErrors);
|
|
19
20
|
const error = (e, extra) => {
|
|
21
|
+
if (level === "none")
|
|
22
|
+
return;
|
|
20
23
|
if (!e) {
|
|
21
24
|
console.trace("Logger.error but error is null or undefined");
|
|
22
25
|
return;
|
|
@@ -49,14 +52,11 @@ function Main(cnf, deps) {
|
|
|
49
52
|
}
|
|
50
53
|
if (e.stack)
|
|
51
54
|
content.push(JSON.stringify(e.stack));
|
|
52
|
-
|
|
53
|
-
fs_1.default.appendFileSync(file, `${content.join("\t")}\n`);
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
console.error("Logger.error appendFileSync faid: %o", err);
|
|
57
|
-
}
|
|
55
|
+
promises_1.default.appendFile(file, `${content.join("\t")}\n`).catch(console.error);
|
|
58
56
|
};
|
|
59
57
|
const info = (message, extra) => {
|
|
58
|
+
if (level === "none" || level === "error")
|
|
59
|
+
return;
|
|
60
60
|
const time = date();
|
|
61
61
|
const today = time.split("T")[0];
|
|
62
62
|
const dir = path_1.default.resolve(infoLogPath, today);
|
|
@@ -72,14 +72,11 @@ function Main(cnf, deps) {
|
|
|
72
72
|
content.push((0, util_1.format)(extra));
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
fs_1.default.appendFileSync(file, `${content.join("\t")}\n`);
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
console.error("Logger.info appendFileSync faid: %o", e);
|
|
80
|
-
}
|
|
75
|
+
promises_1.default.appendFile(file, `${content.join("\t")}\n`).catch(console.error);
|
|
81
76
|
};
|
|
82
77
|
const logger = (fn, name, isAsync = false, transform = (x) => x, errorHandler = (e) => (e instanceof Error ? e.message : ""), argsHandler = JSON.stringify) => {
|
|
78
|
+
if (level === "none")
|
|
79
|
+
return fn;
|
|
83
80
|
if (isAsync) {
|
|
84
81
|
const handler = {
|
|
85
82
|
async apply(fn, me, args) {
|