Skip to content

Commit a413f95

Browse files
committed
Merge branch 'develop'
2 parents 13bfa06 + f582a62 commit a413f95

File tree

3 files changed

+46
-60
lines changed

3 files changed

+46
-60
lines changed

package.json

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,16 @@
8383
},
8484
"homepage": "https://github.com/stackr23/logger#readme",
8585
"devDependencies": {
86-
"@babel/cli": "^7.1.5",
87-
"@babel/core": "^7.1.6",
88-
"@babel/plugin-proposal-class-properties": "^7.1.0",
89-
"@babel/preset-env": "^7.1.6",
90-
"@babel/register": "^7.0.0",
86+
"@babel/cli": "^7.13.16",
87+
"@babel/core": "^7.14.0",
88+
"@babel/plugin-proposal-class-properties": "^7.13.0",
89+
"@babel/preset-env": "^7.14.1",
90+
"@babel/register": "^7.13.16",
9191
"@viewar/config-eslint": "^1.12.0",
92-
"babel-eslint": "^10.0.1",
93-
"babel-preset-minify": "^0.5.0",
94-
"eslint": "^6.0.0",
95-
"eslint-config-airbnb": "^17.1.0",
96-
"eslint-plugin-import": "^2.17.0",
97-
"eslint-plugin-jsx-a11y": "^6.1.2",
98-
"eslint-plugin-node": "^9.0.0",
99-
"eslint-plugin-promise": "^4.0.1",
100-
"eslint-plugin-react": "^7.12.3",
101-
"eslint-plugin-standard": "^4.0.0",
92+
"babel-preset-minify": "^0.5.1",
10293
"husky": "^6.0.0",
10394
"lint-staged": "^10.5.4",
104-
"travis-deploy-once": "^5.0.9"
95+
"lodash": "^4.17.21"
10596
},
10697
"dependencies": {
10798
"chalk": "^4.1.1"

src/index.js

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,45 @@
11
/* eslint-disable no-param-reassign */
22
/* eslint no-console: off */
3+
import _ from 'lodash'
4+
35
import chalkExt from './chalkExt'
46

7+
// TODO: use static props -> update babel!
58
class Logger {
6-
constructor() {
7-
this.options = {
8-
prefix: '{yellow [StackR23]}',
9-
debug: {
10-
color: 'cyan'
11-
},
12-
error: {
13-
color: 'red'
14-
},
15-
success: {
16-
color: 'green',
17-
},
18-
}
19-
}
20-
219

22-
setPrefix(prefix) {
23-
this.options.prefix = prefix || ''
10+
defaults = {
11+
prefix: '{bold.yellow [StackR23] }',
12+
log: {style: 'reset', prefix: 'bold.yellow LOG - '},
13+
debug: {style: 'cyan', prefix: '{bold.cyan DEBUG: }'},
14+
error: {style: 'red', prefix: '{bold.red ERROR: }'},
15+
success: {style: 'green', prefix: '{bold.green SUCCESS: }'}
2416
}
2517

26-
log(str, typePrefix, styleType, styleString) {
27-
if (arguments.length === 1) {
28-
console.log(chalkExt`{bold ${this.options.prefix}} ${str}`)
29-
30-
return true
31-
}
18+
constructor(options) {
19+
this.options = _.merge(this.defaults, options)
20+
console.log('this.defaults :>> ', this.defaults)
21+
console.log('this.options :>> ', this.options)
22+
}
3223

33-
if (arguments.length === 2) {
34-
const type = typePrefix
35-
const {color, prefix, colorType} = this.options[type]
24+
log(str, type = 'log', styleCustom) {
25+
const {prefix, [type]: typeOptions} = this.options
3626

37-
typePrefix = prefix || type
38-
styleType = colorType || color
39-
styleString = color
27+
if (arguments.length === 1) {
28+
console.log(chalkExt`${prefix}${str}`)
29+
return
4030
}
4131

4232
console.log(
43-
chalkExt`{${styleType} {bold ${this.options.prefix} ${typePrefix}:} {${styleString} ${str}}}`
33+
(prefix ? chalkExt`${prefix}` : '') +
34+
(typeOptions.prefix ? chalkExt`${typeOptions.prefix}` : '') +
35+
chalkExt`{${typeOptions.style} ${str}}`
4436
)
45-
46-
return true
4737
}
4838

49-
dir = arg => console.dir(...arg)
50-
5139
debug = str => this.log(str, 'debug')
52-
53-
error = str => this.log(str, 'ERROR', `${this.options.error.color}Bright.bgBlack`, this.options.error.color)
54-
55-
success = str => this.log(str, 'SUCCESS', `${this.options.success.color}Bright`, this.options.success.color)
40+
error = str => this.log(str, 'error')
41+
success = str => this.log(str, 'success')
5642
}
5743

44+
export {Logger}
5845
export default new Logger()

test/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
/* eslint-disable-next-line import/no-unresolved */
2-
import Logger from '../dist'
1+
import {Logger} from '../src/index'
2+
3+
const log = new Logger({
4+
prefix: '{cyan.bold [CUSTOM PREFIX] }',
5+
debug: {prefix: '{bold.blue CUSTOMDEBUG }'}
6+
})
7+
8+
log.debug('standard debug message')
9+
log.debug('{bgBlue.magenta CUSTOM{reset.yellow debug}{bgBlack.cyan info}}')
10+
11+
log.error('unexpected bahavior')
12+
log.success('logger running!')
13+
14+
log.log('{bgBlue.bold.magenta custom output style}')
315

4-
Logger.success('logger running!')
5-
Logger.error('unexpected bahavior')
6-
Logger.log('{reset.magenta custom {bgBlackBright.yellow output style}}')
7-
Logger.debug('standard debug info')

0 commit comments

Comments
 (0)