1 | 1 | var chalk = require('chalk'); |
|
2 | 1 | var format = require('util').format; |
|
3 | |||
4 | /** |
||
5 | * some logging methods... |
||
6 | * info, warn, debug, process |
||
7 | * |
||
8 | */ |
||
9 | |||
10 | /** |
||
11 | * Outputs warn message to console |
||
12 | * |
||
13 | * @return Patternlibrary |
||
14 | */ |
||
15 | function warn ( msg, err ) { |
||
16 | 3 | var strings = { |
|
17 | time : chalk.yellow( (new Date()).toLocaleTimeString() ), |
||
18 | message : chalk.yellow( msg ) |
||
19 | }; |
||
20 | 3 | console.log( |
|
0 ignored issues
–
show
Debugging Code
introduced
by
Loading history...
|
|||
21 | '['+(strings.time)+'] Patternlibrary: ' + (strings.message) // + "\n" |
||
22 | ); |
||
23 | 3 | if (err) this.debug(err); |
|
24 | 3 | return (this); |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * Outputs log message to console if verbose option is set to `true` |
||
29 | * |
||
30 | * @return Patternlibrary |
||
31 | */ |
||
32 | function info ( msg ) { |
||
33 | 1029 | if (this.options.verbose === true) { |
|
34 | 2 | var strings = { |
|
35 | time : chalk.grey( (new Date()).toLocaleTimeString() ), |
||
36 | message : chalk.cyan( msg ) |
||
37 | }; |
||
38 | 2 | console.log( |
|
0 ignored issues
–
show
|
|||
39 | '['+(strings.time)+'] Patternlibrary: ' + (strings.message) // + "\n" |
||
40 | ); |
||
41 | } |
||
42 | 1029 | return (this); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Outputs debug info to console if verbose option is set to `true` |
||
47 | * |
||
48 | * @return Patternlibrary |
||
49 | */ |
||
50 | function debug ( ) { |
||
51 | 14 | if (this.options.verbose === true) { |
|
52 | 2 | var strings = { |
|
53 | time : chalk.grey( (new Date()).toLocaleTimeString() ), |
||
54 | title : chalk.yellow( 'Patternlibrary Debug:' ) |
||
55 | }; |
||
56 | 2 | console.log( |
|
0 ignored issues
–
show
|
|||
57 | '['+(strings.time)+'] '+(strings.title)+' '+"\n", |
||
58 | chalk.yellow(' >>> =================================================== <<< ') // +"\n" |
||
59 | ); |
||
60 | 2 | for (var arg of arguments) { |
|
61 | 2 | if (arg) console.log(arg); |
|
62 | } |
||
63 | 2 | console.log( |
|
64 | chalk.yellow(' >>> =================================================== <<< ') // +"\n" |
||
65 | ); |
||
66 | } |
||
67 | 2 | return (this); |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Outputs the completion of a page being processed to the console. |
||
72 | * |
||
73 | * @param {string} file - Name of the file. |
||
74 | * @param {object} data - Data object associated with the file. The list of adapters is pulled from this. |
||
75 | * @param {integer} time - Time it took to process the file. |
||
76 | */ |
||
77 | function processlog(file, data, time) { |
||
78 | 88 | if (this.options.verbose === true) { |
|
79 | 3 | var msg = ''; |
|
80 | 3 | var diff = (process.hrtime(time)[1] / 1000000000).toFixed(2); |
|
81 | 3 | var adapters = data; |
|
82 | 4 | if (data && data._adapterData) { |
|
83 | 1 | var adapters = Object.keys(data._adapterData).join(', '); |
|
84 | } |
||
85 | 3 | var strings = { |
|
86 | time : chalk.grey( (new Date()).toLocaleTimeString() ), |
||
87 | title : chalk.yellow( 'Patternlibrary process log:' ) |
||
88 | }; |
||
89 | |||
90 | 3 | msg += format('[%s] Patternlibrary: processed %s in %s', (strings.time), chalk.cyan(file), chalk.magenta(diff + ' s')); |
|
91 | |||
92 | 4 | if (adapters && adapters.length) { |
|
93 | 2 | msg += format(' with %s', chalk.yellow(adapters)); |
|
94 | } |
||
95 | |||
96 | 3 | console.log(msg); |
|
0 ignored issues
–
show
|
|||
97 | } |
||
98 | } |
||
99 | |||
100 | |||
101 | /*module.exports = { |
||
102 | log : info, |
||
103 | info : info, |
||
104 | process: process, |
||
105 | debug : debug, |
||
106 | warn : warn |
||
107 | };*/ |
||
108 | //module.exports = function () {}; |
||
109 | 1 | module.exports.log = info, |
|
110 | module.exports.info = info, |
||
111 | module.exports.process= processlog, |
||
112 | module.exports.debug = debug, |
||
113 | module.exports.warn = warn |
||
114 | |||
115 |