UNPKG

1.33 kBJavaScriptView Raw
1const chalk = require('chalk');
2
3/**
4 * used to log the program output and trace.
5 * @param debug
6 * @param info
7 * @param warning
8 * @param err
9 */
10const logger = {};
11
12/**
13 *
14 * log by the type of debug.
15 * @param msg
16 */
17logger.debug = function (type,msg) {
18 var time=__getCurrentTime();
19
20 var output=['[',time,' ','debug',']',chalk.blue(type),':',msg].join('');
21 console.log(output);
22}
23
24/**
25 *
26 * log by the type of info.
27 * @param msg
28 */
29logger.info = function (type,msg) {
30 var time=__getCurrentTime();
31
32 var output=['[',time,' ',chalk.green('info'),']',chalk.blue(type),':',chalk.green(msg)].join('');
33 console.log(output);
34}
35
36/**
37 *
38 * log by the type of warning.
39 * @param msg
40 */
41logger.warning = function (type,msg) {
42 var time=__getCurrentTime();
43
44 var output=['[',time,' ',chalk.yellow('warning'),']',chalk.blue(type),':',chalk.yellow(msg)].join('');
45 console.log(output);
46}
47
48/**
49 *
50 * log by the type of err.
51 * @param msg
52 */
53logger.err = function (type,msg) {
54 var time=__getCurrentTime();
55
56 var output=['[',time,' ',chalk.red('err'),']',chalk.blue(type),':',chalk.red(msg)].join('');
57 console.log(output);
58}
59
60function __getCurrentTime(){
61 return new Date().toLocaleTimeString();
62}
63
64module.exports=logger;
\No newline at end of file