diff --git a/package.json b/package.json index 99ee97f..ee74e15 100644 --- a/package.json +++ b/package.json @@ -83,25 +83,16 @@ }, "homepage": "https://github.com/stackr23/logger#readme", "devDependencies": { - "@babel/cli": "^7.1.5", - "@babel/core": "^7.1.6", - "@babel/plugin-proposal-class-properties": "^7.1.0", - "@babel/preset-env": "^7.1.6", - "@babel/register": "^7.0.0", + "@babel/cli": "^7.13.16", + "@babel/core": "^7.14.0", + "@babel/plugin-proposal-class-properties": "^7.13.0", + "@babel/preset-env": "^7.14.1", + "@babel/register": "^7.13.16", "@viewar/config-eslint": "^1.12.0", - "babel-eslint": "^10.0.1", - "babel-preset-minify": "^0.5.0", - "eslint": "^6.0.0", - "eslint-config-airbnb": "^17.1.0", - "eslint-plugin-import": "^2.17.0", - "eslint-plugin-jsx-a11y": "^6.1.2", - "eslint-plugin-node": "^9.0.0", - "eslint-plugin-promise": "^4.0.1", - "eslint-plugin-react": "^7.12.3", - "eslint-plugin-standard": "^4.0.0", + "babel-preset-minify": "^0.5.1", "husky": "^6.0.0", "lint-staged": "^10.5.4", - "travis-deploy-once": "^5.0.9" + "lodash": "^4.17.21" }, "dependencies": { "chalk": "^4.1.1" diff --git a/src/index.js b/src/index.js index 0abe500..3e5bcbe 100644 --- a/src/index.js +++ b/src/index.js @@ -1,58 +1,43 @@ /* eslint-disable no-param-reassign */ /* eslint no-console: off */ +import _ from 'lodash' + import chalkExt from './chalkExt' +// TODO: use static props -> update babel! class Logger { - constructor() { - this.options = { - prefix: '{yellow [StackR23]}', - debug: { - color: 'cyan' - }, - error: { - color: 'red' - }, - success: { - color: 'green', - }, - } - } - - setPrefix(prefix) { - this.options.prefix = prefix || '' + defaults = { + prefix: '{bold.yellow [StackR23] }', + log: {style: 'reset', prefix: 'bold.yellow LOG - '}, + debug: {style: 'cyan', prefix: '{bold.cyan DEBUG: }'}, + error: {style: 'red', prefix: '{bold.red ERROR: }'}, + success: {style: 'green', prefix: '{bold.green SUCCESS: }'} } - log(str, typePrefix, styleType, styleString) { - if (arguments.length === 1) { - console.log(chalkExt`{bold ${this.options.prefix}} ${str}`) - - return true - } + constructor(options) { + this.options = _.merge(this.defaults, options) + } - if (arguments.length === 2) { - const type = typePrefix - const {color, prefix, colorType} = this.options[type] + log(str, type = 'log', styleCustom) { + const {prefix, [type]: typeOptions} = this.options - typePrefix = prefix || type - styleType = colorType || color - styleString = color + if (arguments.length === 1) { + console.log(chalkExt`${prefix}${str}`) + return } console.log( - chalkExt`{${styleType} {bold ${this.options.prefix} ${typePrefix}:} {${styleString} ${str}}}` + (prefix ? chalkExt`${prefix}` : '') + + (typeOptions.prefix ? chalkExt`${typeOptions.prefix}` : '') + + chalkExt`{${typeOptions.style} ${str}}` ) - - return true } - dir = arg => console.dir(...arg) - debug = str => this.log(str, 'debug') - - error = str => this.log(str, 'ERROR', `${this.options.error.color}Bright.bgBlack`, this.options.error.color) - - success = str => this.log(str, 'SUCCESS', `${this.options.success.color}Bright`, this.options.success.color) + error = str => this.log(str, 'error') + success = str => this.log(str, 'success') } +export {Logger} export default new Logger() diff --git a/test/index.js b/test/index.js index 3d54f76..5f7dd99 100644 --- a/test/index.js +++ b/test/index.js @@ -1,7 +1,15 @@ -/* eslint-disable-next-line import/no-unresolved */ -import Logger from '../dist' +import {Logger} from '../src/index' + +const log = new Logger({ + prefix: '{cyan.bold [CUSTOM PREFIX] }', + debug: {prefix: '{bold.blue CUSTOMDEBUG }'} +}) + +log.debug('standard debug message') +log.debug('{bgBlue.magenta CUSTOM{reset.yellow debug}{bgBlack.cyan info}}') + +log.error('unexpected bahavior') +log.success('logger running!') + +log.log('{bgBlue.bold.magenta custom output style}') -Logger.success('logger running!') -Logger.error('unexpected bahavior') -Logger.log('{reset.magenta custom {bgBlackBright.yellow output style}}') -Logger.debug('standard debug info')