@f3rm1/logger 1.0.0
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/.idea/@f3rm1-logger.iml +12 -0
- package/.idea/misc.xml +10 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/logger.js +89 -0
- package/package.json +22 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
package/.idea/misc.xml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="MaterialThemeProjectNewConfig">
|
|
4
|
+
<option name="metadata">
|
|
5
|
+
<MTProjectMetadataState>
|
|
6
|
+
<option name="userId" value="2aa97953:1962e9c7577:-7ffd" />
|
|
7
|
+
</MTProjectMetadataState>
|
|
8
|
+
</option>
|
|
9
|
+
</component>
|
|
10
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/@f3rm1-logger.iml" filepath="$PROJECT_DIR$/.idea/@f3rm1-logger.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
package/logger.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
|
|
3
|
+
// config
|
|
4
|
+
const LOG_LEVELS = {
|
|
5
|
+
info: {
|
|
6
|
+
label: '[INFO]',
|
|
7
|
+
color: chalk.cyan,
|
|
8
|
+
},
|
|
9
|
+
success: {
|
|
10
|
+
label: '[SUCCESS]',
|
|
11
|
+
color: chalk.green,
|
|
12
|
+
},
|
|
13
|
+
warn: {
|
|
14
|
+
label: '[WARN]',
|
|
15
|
+
color: chalk.yellow,
|
|
16
|
+
type: 'warn',
|
|
17
|
+
},
|
|
18
|
+
error: {
|
|
19
|
+
label: '[ERROR]',
|
|
20
|
+
color: chalk.red.bold,
|
|
21
|
+
},
|
|
22
|
+
debug: {
|
|
23
|
+
label: '[DEBUG]',
|
|
24
|
+
color: chalk.magenta,
|
|
25
|
+
},
|
|
26
|
+
start: {
|
|
27
|
+
label: '[START]',
|
|
28
|
+
color: chalk.green.bold,
|
|
29
|
+
},
|
|
30
|
+
stop: {
|
|
31
|
+
label: '[STOP]',
|
|
32
|
+
color: chalk.red,
|
|
33
|
+
},
|
|
34
|
+
wait: {
|
|
35
|
+
label: '[WAIT]',
|
|
36
|
+
color: chalk.blue,
|
|
37
|
+
},
|
|
38
|
+
event: {
|
|
39
|
+
label: '[EVENT]',
|
|
40
|
+
color: chalk.cyan.bold,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// auto creating methods for logger
|
|
45
|
+
const logger = createLoggerMethods();
|
|
46
|
+
/**
|
|
47
|
+
* Creates your own logger instance with custom preferences.
|
|
48
|
+
*/
|
|
49
|
+
class Logger {
|
|
50
|
+
constructor(prefix) {
|
|
51
|
+
this.prefix = prefix;
|
|
52
|
+
Object.assign(this, createLoggerMethods(prefix));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { logger, Logger };
|
|
57
|
+
|
|
58
|
+
const MAX_LABEL_WIDTH = Math.max(...Object.values(LOG_LEVELS).map(level => level.label.length));
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Creates logger methods. Can accept prefix for Logger instance.
|
|
62
|
+
*/
|
|
63
|
+
function createLoggerMethods(prefix = '') {
|
|
64
|
+
const methods = {};
|
|
65
|
+
|
|
66
|
+
Object.entries(LOG_LEVELS).forEach(([level, config]) => {
|
|
67
|
+
methods[level] = (message, ...args) => {
|
|
68
|
+
const logMethod = /warn|error/.test(config.type) ? console[config.type] : console.log;
|
|
69
|
+
logMethod(logBody(config.label, config.color, config.color(message), prefix), ...args);
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return methods;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getTimeLabel() {
|
|
77
|
+
const now = new Date();
|
|
78
|
+
return chalk.gray(`[${now.toLocaleTimeString()}]`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function padLabel(label, colorFn) {
|
|
82
|
+
// adding padding and only after adding a color
|
|
83
|
+
const paddedLabel = label.padEnd(MAX_LABEL_WIDTH, ' ');
|
|
84
|
+
return colorFn(paddedLabel);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function logBody(label, colorFn, message, prefix) {
|
|
88
|
+
return `${getTimeLabel()}${prefix ? ' ' + chalk.bgBlack.whiteBright.bold(` ${prefix} `) : ''} ${padLabel(label, colorFn)} ${message}`;
|
|
89
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@f3rm1/logger",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "logger.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"patch": "npm version patch && npm publish"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"type": "commonjs",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"chalk": "^4.1.2"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"chalk": "^4.1.2"
|
|
21
|
+
}
|
|
22
|
+
}
|