1 | "use strict";
|
2 | var __importStar = (this && this.__importStar) || function (mod) {
|
3 | if (mod && mod.__esModule) return mod;
|
4 | var result = {};
|
5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6 | result["default"] = mod;
|
7 | return result;
|
8 | };
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const cluster = __importStar(require("cluster"));
|
11 | const core = __importStar(require("@akala/core"));
|
12 | let customOutputs = ['error', 'warn', 'verbose', 'debug', 'info'];
|
13 | exports.logger = new Proxy(function (rootNamespace) {
|
14 | return new Proxy({}, {
|
15 | get: function (target, prop) {
|
16 | if (!Reflect.has(target, prop) && typeof (prop) == 'string')
|
17 | target[prop] = log(prop + ':' + rootNamespace);
|
18 | return Reflect.get(target, prop);
|
19 | }
|
20 | });
|
21 | }, {
|
22 | get: function (target, prop) {
|
23 | if (!Reflect.has(target, prop) && typeof (prop) == 'string')
|
24 | target[prop] = log(prop);
|
25 | return Reflect.get(target, prop);
|
26 | }
|
27 | });
|
28 | function log(namespace) {
|
29 | if (!cluster.isMaster) {
|
30 | var customOutput = customOutputs.find(o => namespace.startsWith(o + ':'));
|
31 | if (customOutput)
|
32 | namespace = namespace.substring((customOutput + ':').length);
|
33 | customOutput = customOutput || customOutputs.find(o => namespace == o);
|
34 | var moduleNamespace = process.argv[2].replace(/[@\/]/g, ':');
|
35 | if (moduleNamespace[0] == ':')
|
36 | moduleNamespace = moduleNamespace.substring(1);
|
37 | if (customOutput) {
|
38 | if (namespace == moduleNamespace || customOutput == namespace)
|
39 | namespace = moduleNamespace = customOutput + ':' + moduleNamespace;
|
40 | else
|
41 | moduleNamespace = customOutput + ':' + moduleNamespace;
|
42 | }
|
43 | if (!namespace.startsWith(moduleNamespace))
|
44 | namespace = moduleNamespace + ':' + namespace;
|
45 | }
|
46 | return core.log(namespace);
|
47 | }
|
48 | exports.log = log;
|
49 |
|
\ | No newline at end of file |