diff --git a/README.md b/README.md index d93a862..cb68776 100644 --- a/README.md +++ b/README.md @@ -235,7 +235,7 @@ plankton() ```javascript plankton() - .useLogger((msg, type) => { + .useLogger((msg, level) => { // handler... }) .map('/', (req, res) => { diff --git a/lib/logger.js b/lib/logger.js index 2d825b0..7251081 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -3,33 +3,33 @@ export class Logger { this.callback = callback } - log(msg, type = 'info') { + log(msg, level = 'info') { msg += '\n' if (this.callback) { - this.callback(msg, type) + this.callback(msg, level) return } - switch (type) { + switch (level) { case 'error': - console.error(`${type}: ${msg}`) + console.error(`${level}: ${msg}`) break case 'warn': - console.warn(`${type}: ${msg}`) + console.warn(`${level}: ${msg}`) break case 'debug': - console.debug(`${type}: ${msg}`) + console.debug(`${level}: ${msg}`) break case 'info': - console.info(`${type}: ${msg}`) + console.info(`${level}: ${msg}`) break default: - console.log(`${type}: ${msg}`) + console.log(`${level}: ${msg}`) break } } diff --git a/lib/plankton.js b/lib/plankton.js index ba4755a..4142b26 100644 --- a/lib/plankton.js +++ b/lib/plankton.js @@ -63,8 +63,13 @@ export class Plankton { return this } - useLogger(logger) { - this.logger = logger + useLogger(callback) { + if (callback instanceof Logger) { + this.logger = callback + } + else { + this.logger = new Logger(callback) + } return this } diff --git a/package.json b/package.json index 5dfcb1a..8be48c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lixinyang123/plankton", - "version": "0.1.9", + "version": "0.1.10", "description": "Fast, Sample, Zero dependenecs Node.js mvc web framework", "author": "lllxy", "type": "module",