Skip to content

Commit

Permalink
fixed logger error
Browse files Browse the repository at this point in the history
  • Loading branch information
lixinyang123 committed Apr 8, 2024
1 parent 1f17d6c commit 13fa7ed
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ plankton()

```javascript
plankton()
.useLogger((msg, type) => {
.useLogger((msg, level) => {
// handler...
})
.map('/', (req, res) => {
Expand Down
16 changes: 8 additions & 8 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/plankton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 13fa7ed

Please sign in to comment.