|
1 | 1 | /* eslint-disable no-param-reassign */ |
2 | 2 | /* eslint no-console: off */ |
3 | 3 | import _ from 'lodash' |
| 4 | +<<<<<<< HEAD |
| 5 | +import chalk from 'chalk' |
| 6 | +// import chalkExt from './chalkExt' |
| 7 | +======= |
4 | 8 |
|
5 | 9 | import chalkExt from './chalkExt' |
| 10 | +>>>>>>> 1871a68 (* feat: pass options to Logger instance) |
6 | 11 |
|
| 12 | +// TODO: use static props -> update babel! |
7 | 13 | class Logger { |
8 | 14 |
|
9 | | - // use static props -> update babel! |
10 | 15 | defaults = { |
11 | | - prefix: '[StackR23]', |
12 | | - debug: {color: 'cyan', prefix: 'DEBUG'}, |
13 | | - error: {color: 'red', prefix: 'ERROR'}, |
14 | | - success: {color: 'green', prefix: 'SUCCESS'} |
| 16 | + prefix: '{bold.yellow [StackR23] }', |
| 17 | + log: {style: 'reset', prefix: 'bold.yellow LOG - '}, |
| 18 | + debug: {style: 'cyan', prefix: '{bold.cyan DEBUG: }'}, |
| 19 | + error: {style: 'red', prefix: '{bold.red ERROR: }'}, |
| 20 | + success: {style: 'green', prefix: '{bold.green SUCCESS: }'} |
15 | 21 | } |
16 | 22 |
|
17 | 23 | constructor(options) { |
18 | | - console.log('options :>> ', options) |
19 | | - |
20 | 24 | this.options = _.merge(this.defaults, options) |
21 | 25 | console.log('this.defaults :>> ', this.defaults) |
22 | 26 | console.log('this.options :>> ', this.options) |
23 | 27 | } |
24 | 28 |
|
25 | | - log(str, typePrefix, styleType, styleString) { |
26 | | - if (arguments.length === 1) { |
27 | | - console.log(chalkExt`{${this.options.prefixColor}.bold ${this.options.prefix}} ${str}`) |
| 29 | + log(str, type = 'log', styleCustom) { |
| 30 | + const {prefix, [type]: typeOptions} = this.options |
28 | 31 |
|
| 32 | +<<<<<<< HEAD |
29 | 33 | return true |
30 | 34 | } |
31 | 35 |
|
32 | | - if (arguments.length === 2) { |
33 | | - const type = typePrefix |
34 | | - const {color, prefix} = this.options[type] // |
| 36 | + const {style, prefix} = this.options |
| 37 | + const typeOptions = this.options[type] |
35 | 38 |
|
36 | | - typePrefix = prefix || type |
37 | | - // styleType = colorType || color |
38 | | - styleString = color |
| 39 | +======= |
| 40 | + if (arguments.length === 1) { |
| 41 | + console.log(chalkExt`${prefix}${str}`) |
| 42 | + return |
39 | 43 | } |
40 | 44 |
|
| 45 | +>>>>>>> 1871a68 (* feat: pass options to Logger instance) |
41 | 46 | console.log( |
42 | | - // ${styleType} |
43 | | - chalkExt`{{bold ${this.options.prefix} ${typePrefix}:} {${styleString} ${str}}` |
| 47 | + (prefix ? chalkExt`${prefix}` : '') + |
| 48 | + (typeOptions.prefix ? chalkExt`${typeOptions.prefix}` : '') + |
| 49 | + chalkExt`{${typeOptions.style} ${str}}` |
44 | 50 | ) |
45 | | - |
46 | | - return true |
47 | 51 | } |
48 | 52 |
|
49 | | - dir = arg => console.dir(...arg) |
50 | | - |
51 | 53 | debug = str => this.log(str, 'debug') |
52 | | - |
53 | | - error = str => this.log(str, 'error') //, `${this.options.errorColor}Bright.bgBlack`, this.options.errorColor) |
54 | | - |
55 | | - success = str => this.log(str, 'success') //, `${this.options.successColor}Bright`, this.options.successColor) |
| 54 | + error = str => this.log(str, 'error') |
| 55 | + success = str => this.log(str, 'success') |
56 | 56 | } |
57 | 57 |
|
| 58 | +export {Logger} |
58 | 59 | export default new Logger() |
0 commit comments