Created
September 7, 2021 21:50
-
-
Save AshleyCoder3/5eba197279a3f45e0a5eb0b7a175f003 to your computer and use it in GitHub Desktop.
Server logger to be used with Express
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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