Skip to content

Instantly share code, notes, and snippets.

@AshleyCoder3
Created September 7, 2021 21:50
Show Gist options
  • Select an option

  • Save AshleyCoder3/5eba197279a3f45e0a5eb0b7a175f003 to your computer and use it in GitHub Desktop.

Select an option

Save AshleyCoder3/5eba197279a3f45e0a5eb0b7a175f003 to your computer and use it in GitHub Desktop.
Server logger to be used with Express
// Use as a basic logger middleware in your server
const logger = (req, res, next) => {
const formatUrl = `${req.baseUrl}${req.url}`
const log = `---------------------------
${Date()}
method: ${req.method}
URL: ${formatUrl}
status: ${res.statusCode}
requester IP: ${req.ip} \n************`
console.log(log)
next()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment