1.1.2 • Published 5 years ago

express-simple-logger v1.1.2

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

express-simple-logger

npm version build status

A logger middleware for express.Similar with koa-logger.

[2019-7-22 17:24:30] <-- GET /
[2019-7-22 17:24:31] --> GET / 200 835ms
[2019-7-22 17:24:48] <-- GET /
[2019-7-22 17:24:49] --> GET / 200 960ms
[2019-7-22 17:25:27] <-- GET /api
[2019-7-22 17:25:28] --> GET /api 200 357ms
[2019-7-22 17:25:53] <-- GET /users?page=2
[2019-7-22 17:25:54] --> GET /users?page=2 200 466ms

Installation

Install via npm or yarn

# Use npm
$ npm i express-simple-logger

# Use yarn
$ yarn add express-simple-logger

Example

const express = require('express')
const logger = require('express-simple-logger')

const app = express()

app.use(logger())

Notes

Recommended that you .use() this middleware near the top to "wrap" all subsequent middleware.

Option

paramstyperequireddefaultdescription
unlessArrayfalse[]ignore path list
logTimeBooleanfalsetruewhether to log time
loggerFunctionfalse--custom logger (str:String, args:Array)

Param str is output string, args.join(' ') Param args is a array by [logTime, format, method, url, status, time], when opt.logTime is false, logTime = ''

const http = require('http')

...
app.use(logger({
  unless: ['/ignorepath'],
  logTime: false,
  // custom logger
  // add short description of status code
  logger (str, args) {
    if (args.length === 6) {
      // response logger
      args[4] = args[4] + ' ' + http.STATUS_CODES[args[4]]
      console.log(...args)
    }
  }
}))

License

MIT

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago