ng2-logger 21.0.32 → 21.0.34
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/browser/package.json +1 -1
- package/browser-prod/package.json +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/package.json +1 -1
- package/lib-prod/backend-logging.js +105 -0
- package/lib-prod/{build-info._auto-generated_.ts → build-info._auto-generated_.js} +1 -2
- package/lib-prod/display.js +96 -0
- package/lib-prod/env/{env.angular-node-app.ts → env.angular-node-app.js} +1 -1
- package/lib-prod/env/{env.docs-webapp.ts → env.docs-webapp.js} +1 -1
- package/lib-prod/env/{env.electron-app.ts → env.electron-app.js} +1 -1
- package/lib-prod/env/{env.mobile-app.ts → env.mobile-app.js} +1 -1
- package/lib-prod/env/{env.npm-lib-and-cli-tool.ts → env.npm-lib-and-cli-tool.js} +1 -1
- package/lib-prod/env/{env.vscode-plugin.ts → env.vscode-plugin.js} +1 -1
- package/lib-prod/{index._auto-generated_.ts → index._auto-generated_.js} +1 -1
- package/lib-prod/{index.ts → index.js} +1 -1
- package/lib-prod/level.js +30 -0
- package/lib-prod/log.js +164 -0
- package/lib-prod/logger.js +234 -0
- package/lib-prod/migrations/index.js +2 -0
- package/lib-prod/migrations/{migrations_index._auto-generated_.ts → migrations_index._auto-generated_.js} +0 -2
- package/lib-prod/package.json +1 -1
- package/lib-prod/start.js +39 -0
- package/package.json +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/package.json +1 -1
- package/lib-prod/backend-logging.ts +0 -111
- package/lib-prod/display.ts +0 -108
- package/lib-prod/level.ts +0 -31
- package/lib-prod/lib-info.md +0 -8
- package/lib-prod/log.ts +0 -186
- package/lib-prod/logger.ts +0 -257
- package/lib-prod/migrations/index.ts +0 -2
- package/lib-prod/migrations/migrations-info.md +0 -6
- package/lib-prod/start.ts +0 -44
- /package/lib-prod/env/{index.ts → index.js} +0 -0
package/browser/package.json
CHANGED
|
@@ -25,6 +25,6 @@ exports.CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
|
25
25
|
/**
|
|
26
26
|
* Autogenerated by current cli tool. Use *tnp release* to bump version.
|
|
27
27
|
*/
|
|
28
|
-
exports.CURRENT_PACKAGE_VERSION = '21.0.
|
|
28
|
+
exports.CURRENT_PACKAGE_VERSION = '21.0.34';
|
|
29
29
|
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
30
30
|
//# sourceMappingURL=build-info._auto-generated_.js.map
|
package/lib/package.json
CHANGED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
//#endregion
|
|
2
|
+
import { Level } from './level';
|
|
3
|
+
//#region @backend
|
|
4
|
+
import { chalk } from 'tnp-core/lib-prod';
|
|
5
|
+
import * as json5 from 'json5';
|
|
6
|
+
import * as stringify from 'json-stringify-safe';
|
|
7
|
+
import { Helpers__NS__error, Helpers__NS__info, Helpers__NS__log, Helpers__NS__success, Helpers__NS__taskDone, Helpers__NS__taskStarted, Helpers__NS__warn } from 'tnp-core/lib-prod';
|
|
8
|
+
//#endregion
|
|
9
|
+
export function consoleLog(data, level) {
|
|
10
|
+
//#region @backend
|
|
11
|
+
if (level === Level.INFO)
|
|
12
|
+
Helpers__NS__info(data);
|
|
13
|
+
else if (level === Level.ERROR)
|
|
14
|
+
Helpers__NS__error(data);
|
|
15
|
+
else if (level === Level.WARN)
|
|
16
|
+
Helpers__NS__warn(data);
|
|
17
|
+
else if (level === Level.SUCCESS)
|
|
18
|
+
Helpers__NS__success(data);
|
|
19
|
+
else if (level === Level.TASK_STARTED)
|
|
20
|
+
Helpers__NS__taskStarted(data);
|
|
21
|
+
else if (level === Level.TASK_DONE)
|
|
22
|
+
Helpers__NS__taskDone(data);
|
|
23
|
+
else
|
|
24
|
+
Helpers__NS__log(data);
|
|
25
|
+
//#endregion
|
|
26
|
+
}
|
|
27
|
+
export function displayParams(params = [], level) {
|
|
28
|
+
//#region @backend
|
|
29
|
+
params.forEach(param => {
|
|
30
|
+
if (typeof param === 'object') {
|
|
31
|
+
handleObjectData(param, level);
|
|
32
|
+
}
|
|
33
|
+
else if (isObjectAfterStringify(param)) {
|
|
34
|
+
handleObjectData(json5.parse(param), level);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
consoleLog(param, level);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
//#endregion
|
|
41
|
+
}
|
|
42
|
+
function replace(out, match, char, color) {
|
|
43
|
+
//#region @backend
|
|
44
|
+
let m = out.match(match);
|
|
45
|
+
let outer = out;
|
|
46
|
+
if (m)
|
|
47
|
+
m.forEach(p => {
|
|
48
|
+
const rep = p
|
|
49
|
+
.slice(1)
|
|
50
|
+
.replace(char, '');
|
|
51
|
+
outer = outer.replace(`"${rep}":`, `"${color.call(null, rep)}":`);
|
|
52
|
+
});
|
|
53
|
+
return outer;
|
|
54
|
+
//#endregion
|
|
55
|
+
}
|
|
56
|
+
function handleObjectData(param, level) {
|
|
57
|
+
//#region @backend
|
|
58
|
+
if (istartedInVscode()) {
|
|
59
|
+
consoleLog(param, level);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let out = stringify(param, null, 4);
|
|
63
|
+
out = replace(out, /\".*"\:\ \"/g, /\"\: "/, chalk.green);
|
|
64
|
+
out = replace(out, /\".*"\:\ \{/g, /\"\: \{/, chalk.yellow);
|
|
65
|
+
out = replace(out, /\".*"\:\ \[/g, /\"\: \[/, chalk.red);
|
|
66
|
+
out = replace(out, /\".*"\:\ true/g, /\"\: true/, chalk.blue);
|
|
67
|
+
out = replace(out, /\".*"\:\ false/g, /\"\: false/, chalk.blue);
|
|
68
|
+
out = replace(out, /\".*"\:\ (\-|[0-9])/g, /\"\: (\-|[0-9])/, chalk.magenta);
|
|
69
|
+
out = out.replace(/\"/g, chalk.dim('"'))
|
|
70
|
+
.replace(/\{/g, chalk.dim('{'))
|
|
71
|
+
.replace(/\}/g, chalk.dim('}'))
|
|
72
|
+
.replace(/\}/g, chalk.dim('}'));
|
|
73
|
+
if (process.stdout.columns && process.stdout.columns > 0) {
|
|
74
|
+
out = out.split('\n').map(line => {
|
|
75
|
+
return (line.length < process.stdout.columns ?
|
|
76
|
+
line :
|
|
77
|
+
line.slice(0, process.stdout.columns - 6) + chalk.dim('...'));
|
|
78
|
+
}).join('\n');
|
|
79
|
+
}
|
|
80
|
+
consoleLog(out, level);
|
|
81
|
+
//#endregion
|
|
82
|
+
}
|
|
83
|
+
export function istartedInVscode() {
|
|
84
|
+
//#region @backend
|
|
85
|
+
let args = process.execArgv;
|
|
86
|
+
if (args) {
|
|
87
|
+
return args.some((arg) => /^--debug=?/.test(arg) ||
|
|
88
|
+
/^--debug-brk=?/.test(arg) ||
|
|
89
|
+
/^--inspect=?/.test(arg) ||
|
|
90
|
+
/^--inspect-brk=?/.test(arg));
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
//#endregion
|
|
94
|
+
}
|
|
95
|
+
function isObjectAfterStringify(s) {
|
|
96
|
+
//#region @backend
|
|
97
|
+
try {
|
|
98
|
+
json5.parse(s);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
}
|
|
@@ -22,6 +22,5 @@ export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
|
22
22
|
/**
|
|
23
23
|
* Autogenerated by current cli tool. Use *tnp release* to bump version.
|
|
24
24
|
*/
|
|
25
|
-
export const CURRENT_PACKAGE_VERSION = '21.0.
|
|
25
|
+
export const CURRENT_PACKAGE_VERSION = '21.0.34';
|
|
26
26
|
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
27
|
-
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
//#endregion
|
|
2
|
+
import { Level } from './level';
|
|
3
|
+
import { UtilsOs__NS__isNode } from 'tnp-core/lib-prod';
|
|
4
|
+
import { consoleLog, displayParams } from './backend-logging';
|
|
5
|
+
//#region @backend
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
//#endregion
|
|
8
|
+
export class Display {
|
|
9
|
+
static msg(message, params, moduleName, moduleColor, level, moduleWidth, isProductionMode) {
|
|
10
|
+
if (isProductionMode) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
;
|
|
14
|
+
let color = 'gray';
|
|
15
|
+
if (level === Level.INFO) {
|
|
16
|
+
color = 'deepskyblue';
|
|
17
|
+
}
|
|
18
|
+
if (level === Level.ERROR) {
|
|
19
|
+
color = 'red';
|
|
20
|
+
}
|
|
21
|
+
if (level === Level.WARN) {
|
|
22
|
+
color = 'orange';
|
|
23
|
+
}
|
|
24
|
+
if (moduleWidth) {
|
|
25
|
+
const diff = moduleWidth - moduleName.length;
|
|
26
|
+
if (diff > 0) {
|
|
27
|
+
for (let i = 0; i < diff; i++) {
|
|
28
|
+
moduleName += ' ';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/* */
|
|
33
|
+
/* */
|
|
34
|
+
/* */
|
|
35
|
+
/* */
|
|
36
|
+
/* */
|
|
37
|
+
/* */
|
|
38
|
+
/* */
|
|
39
|
+
/* */
|
|
40
|
+
/* */
|
|
41
|
+
/* */
|
|
42
|
+
/* */
|
|
43
|
+
/* */
|
|
44
|
+
/* */
|
|
45
|
+
/* */
|
|
46
|
+
/* */
|
|
47
|
+
/* */
|
|
48
|
+
/* */
|
|
49
|
+
/* */
|
|
50
|
+
/* */
|
|
51
|
+
/* */
|
|
52
|
+
/* */
|
|
53
|
+
/* */
|
|
54
|
+
/* */
|
|
55
|
+
/* */
|
|
56
|
+
/* */
|
|
57
|
+
/* */
|
|
58
|
+
/* */
|
|
59
|
+
/* */
|
|
60
|
+
/* */
|
|
61
|
+
/* */
|
|
62
|
+
/* */
|
|
63
|
+
/* */
|
|
64
|
+
/* */
|
|
65
|
+
/* */
|
|
66
|
+
/* */
|
|
67
|
+
/* */
|
|
68
|
+
/* */
|
|
69
|
+
/* */
|
|
70
|
+
/* */
|
|
71
|
+
/* */
|
|
72
|
+
/* */
|
|
73
|
+
/* */
|
|
74
|
+
/* */
|
|
75
|
+
/* */
|
|
76
|
+
/* */
|
|
77
|
+
/* */
|
|
78
|
+
/* */
|
|
79
|
+
/* */
|
|
80
|
+
//#region @backend
|
|
81
|
+
if (UtilsOs__NS__isNode) {
|
|
82
|
+
let a1 = chalk.bgHex(moduleColor)(global.hideLog ? '' : `${chalk.black(moduleName)}`);
|
|
83
|
+
let p = params;
|
|
84
|
+
if (typeof message === 'string') {
|
|
85
|
+
a1 = a1 + chalk.keyword(color)(global.hideLog ? '' : ' [') + chalk.dim(message)
|
|
86
|
+
+ chalk.keyword(color)(global.hideLog ? '' : '] ');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
p = [message].concat(params);
|
|
90
|
+
}
|
|
91
|
+
consoleLog(a1, level);
|
|
92
|
+
displayParams(p, level);
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -63,4 +63,4 @@ export const ENV_ANGULAR_NODE_APP_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_ANGULAR_NODE_APP_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_ANGULAR_NODE_APP_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_ANGULAR_NODE_APP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_DOCS_WEBAPP_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_DOCS_WEBAPP_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_DOCS_WEBAPP_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_DOCS_WEBAPP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_ELECTRON_APP_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_ELECTRON_APP_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_ELECTRON_APP_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_ELECTRON_APP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_MOBILE_APP_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_MOBILE_APP_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_MOBILE_APP_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_MOBILE_APP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_NPM_LIB_AND_CLI_TOOL_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_NPM_LIB_AND_CLI_TOOL_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_NPM_LIB_AND_CLI_TOOL_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_NPM_LIB_AND_CLI_TOOL_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_VSCODE_PLUGIN_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_VSCODE_PLUGIN_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_VSCODE_PLUGIN_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_VSCODE_PLUGIN_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export var Level;
|
|
2
|
+
(function (Level) {
|
|
3
|
+
Level[Level["DATA"] = 0] = "DATA";
|
|
4
|
+
Level[Level["INFO"] = 1] = "INFO";
|
|
5
|
+
Level[Level["WARN"] = 2] = "WARN";
|
|
6
|
+
Level[Level["ERROR"] = 3] = "ERROR";
|
|
7
|
+
Level[Level["SUCCESS"] = 4] = "SUCCESS";
|
|
8
|
+
Level[Level["TASK_STARTED"] = 5] = "TASK_STARTED";
|
|
9
|
+
Level[Level["TASK_DONE"] = 6] = "TASK_DONE";
|
|
10
|
+
Level[Level["__NOTHING"] = 7] = "__NOTHING";
|
|
11
|
+
})(Level || (Level = {}));
|
|
12
|
+
export const LevelKey = {
|
|
13
|
+
[Level.DATA]: 'log',
|
|
14
|
+
[Level.INFO]: 'info',
|
|
15
|
+
[Level.WARN]: 'warn',
|
|
16
|
+
[Level.ERROR]: 'error',
|
|
17
|
+
[Level.SUCCESS]: 'success',
|
|
18
|
+
[Level.TASK_STARTED]: 'taskstarted',
|
|
19
|
+
[Level.TASK_DONE]: 'taskdone',
|
|
20
|
+
[Level.__NOTHING]: '',
|
|
21
|
+
};
|
|
22
|
+
export const LevelOrder = [
|
|
23
|
+
LevelKey[Level.DATA],
|
|
24
|
+
LevelKey[Level.TASK_STARTED],
|
|
25
|
+
LevelKey[Level.TASK_DONE],
|
|
26
|
+
LevelKey[Level.INFO],
|
|
27
|
+
LevelKey[Level.SUCCESS],
|
|
28
|
+
LevelKey[Level.WARN],
|
|
29
|
+
LevelKey[Level.ERROR],
|
|
30
|
+
];
|
package/lib-prod/log.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Logger } from './logger';
|
|
2
|
+
import { Level, LevelOrder, LevelKey } from './level';
|
|
3
|
+
import { Helpers__NS__contain, UtilsOs__NS__isNode } from 'tnp-core/lib-prod';
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region @backend
|
|
6
|
+
const randomcolor = require('randomcolor').default ?? require('randomcolor');
|
|
7
|
+
//#endregion
|
|
8
|
+
export class Log {
|
|
9
|
+
//#region singleton
|
|
10
|
+
constructor() {
|
|
11
|
+
this._logOnly = false;
|
|
12
|
+
this._logModules = false;
|
|
13
|
+
this.isDevelopmentMode = true;
|
|
14
|
+
this.modeIsSet = false;
|
|
15
|
+
this.fixedWidth = 0;
|
|
16
|
+
this.instances = {};
|
|
17
|
+
this.levels = [];
|
|
18
|
+
this.modules = [];
|
|
19
|
+
}
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
static get instance() {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
if (!Log['_instance']) {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
Log['_instance'] = new Log();
|
|
26
|
+
}
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
return Log['_instance'];
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
static { this.Logger = Logger; }
|
|
32
|
+
static create(name, ...level) {
|
|
33
|
+
return Log.instance.create(name, ...level);
|
|
34
|
+
}
|
|
35
|
+
static { this.consolelogfn = {}; }
|
|
36
|
+
static disableLogs(level = Level.__NOTHING) {
|
|
37
|
+
//#region @backend
|
|
38
|
+
// if (UtilsOs__NS__isNode && (level === Level.__NOTHING)) {
|
|
39
|
+
// if (!this.consolelogfn[PROCESS_STDOUT_WRITE]) {
|
|
40
|
+
// this.consolelogfn[PROCESS_STDOUT_WRITE] = process.stdout.write; // TOOD not working
|
|
41
|
+
// }
|
|
42
|
+
// process.stdout.write = (() => { }) as any;
|
|
43
|
+
// }
|
|
44
|
+
//#endregion
|
|
45
|
+
LevelOrder.reverse().find(a => {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
if (!this.consolelogfn[a]) {
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
this.consolelogfn[a] = console[a];
|
|
50
|
+
}
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
console[a] = () => { };
|
|
53
|
+
if (a === LevelKey[level]) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
static enableLogs() {
|
|
60
|
+
//#region @backend
|
|
61
|
+
// if (UtilsOs__NS__isNode) {
|
|
62
|
+
// process.stdout.write = this.consolelogfn[PROCESS_STDOUT_WRITE];
|
|
63
|
+
// }
|
|
64
|
+
//#endregion
|
|
65
|
+
LevelOrder.forEach(a => {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
console[a] = this.consolelogfn[a];
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//#region public api
|
|
71
|
+
setProductionMode() {
|
|
72
|
+
if (this.modeIsSet) {
|
|
73
|
+
this.modeIsSet = false;
|
|
74
|
+
throw '[ng2-logger] Production mode is already set';
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.modeIsSet = true;
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
if (this.modeIsSet && console !== void 0 && console.clear !== void 0) {
|
|
80
|
+
console.clear();
|
|
81
|
+
console.log = () => { };
|
|
82
|
+
console.error = () => { };
|
|
83
|
+
console.warn = () => { };
|
|
84
|
+
console.info = () => { };
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.isDevelopmentMode = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
onlyModules(...modules) {
|
|
91
|
+
if (this._logModules) {
|
|
92
|
+
throw '[ng2-logger] You should use funcion onlyModules only once';
|
|
93
|
+
}
|
|
94
|
+
if (!this._logModules) {
|
|
95
|
+
this._logModules = true;
|
|
96
|
+
}
|
|
97
|
+
if (modules.length === 0)
|
|
98
|
+
return;
|
|
99
|
+
this.modules = modules;
|
|
100
|
+
// console.log('only log this', Log.modules)
|
|
101
|
+
this.muteAllOtherModules();
|
|
102
|
+
}
|
|
103
|
+
onlyLevel(...level) {
|
|
104
|
+
if (this._logOnly) {
|
|
105
|
+
throw '[ng2-logger] You should use funcion onlyLevel only once';
|
|
106
|
+
}
|
|
107
|
+
if (!this._logOnly) {
|
|
108
|
+
this._logOnly = true;
|
|
109
|
+
}
|
|
110
|
+
this.levels = Array.isArray(level) ? level : [level];
|
|
111
|
+
for (const logName in this.instances) {
|
|
112
|
+
if (this.instances.hasOwnProperty(logName)) {
|
|
113
|
+
const element = this.instances[logName];
|
|
114
|
+
element['allowed'] = this.levels;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
create(name, ...level) {
|
|
120
|
+
let i;
|
|
121
|
+
if (Array.isArray(this.levels) && this.levels.length > 0) {
|
|
122
|
+
level = this.levels;
|
|
123
|
+
}
|
|
124
|
+
if (this.instances[name] === void 0) {
|
|
125
|
+
i = new Log.Logger(name, getRandomColor(), this.isDevelopmentMode, level, this.isMutedModule(name), this.levels.length > 0 ? this.fixedWidth : void 0);
|
|
126
|
+
this.instances[name] = i;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
i = this.instances[name];
|
|
130
|
+
}
|
|
131
|
+
return i;
|
|
132
|
+
}
|
|
133
|
+
isMutedModule(moduleName) {
|
|
134
|
+
if (this.modules.length == 0)
|
|
135
|
+
return false;
|
|
136
|
+
if (!Helpers__NS__contain(this.modules, moduleName))
|
|
137
|
+
return true;
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
muteAllOtherModules() {
|
|
141
|
+
for (var moduleName in this.instances) {
|
|
142
|
+
if (!Helpers__NS__contain(this.modules, moduleName))
|
|
143
|
+
this.instances[moduleName].mute();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function getRandomColor() {
|
|
148
|
+
//#region @backend
|
|
149
|
+
if (UtilsOs__NS__isNode) {
|
|
150
|
+
return randomcolor({ luminosity: 'light', count: 10 });
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
let letters = '012345'.split('');
|
|
154
|
+
let color = '#';
|
|
155
|
+
color += letters[Math.round(Math.random() * 5)];
|
|
156
|
+
letters = '0123456789ABCDEF'.split('');
|
|
157
|
+
for (let i = 0; i < 5; i++) {
|
|
158
|
+
color += letters[Math.round(Math.random() * 15)];
|
|
159
|
+
}
|
|
160
|
+
if (color === void 0) {
|
|
161
|
+
return getRandomColor();
|
|
162
|
+
}
|
|
163
|
+
return color;
|
|
164
|
+
}
|