https://github.com/hash-bang/node-express-log-url
ExpressJS pretty printer for URLs
https://github.com/hash-bang/node-express-log-url
Last synced: 2 months ago
JSON representation
ExpressJS pretty printer for URLs
- Host: GitHub
- URL: https://github.com/hash-bang/node-express-log-url
- Owner: hash-bang
- License: mit
- Created: 2015-07-24T07:51:27.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-18T23:27:28.000Z (about 1 year ago)
- Last Synced: 2025-02-17T20:41:01.259Z (3 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
express-log-url
===============
Simple, nice-looking, logging for Express.
Installation
============Install package
---------------```
npm --save install express-log-url
```Install within Express
----------------------```javascript
// Somewhere within your server setupapp.use(require('express-log-url'));
```Surpressing log entries
-----------------------
To surpress logging set `res.logIgnore = true`.Socket logging
---------------
The module also contains an extremely simple socket logging function:```javascript
var io = require('socket.io').listen(server);
io.on('connect', socket => {
socket.on('something', require('express-log-url').socket);
socket.on('something', ()=> ...Actually do work...);
})
```Manual logging
--------------
The module supports an object containing optional fields which will be output as if it were a fresh server request```javascript
var logger = require('express-log-url');// Simulate a GET request
logger.log({method: 'GET', code: 200, path: '/', responseTime: 10});// Simulate a POST request with additional fields
logger.log({method: 'POST', code: 400, path: '/some/post', responseTime: 20, info: 'Lack of widgets'});
```Supported fields:
| Field | Description |
|----------------|----------------------------------------------------------|
| `indent` | Indentation to use. Is commonly a number of spaces |
| `method` | Short (ideally no more than 5 characters) method to show |
| `code` | The status code returned by the server |
| `responseTime` | The time (in milliseconds) the server took to respond |
| `info` | Additional information to log against the request |Options
=======
Set the following options via `app.set('OPTION', 'VALUE');`| Setting | Type | Default | Description |
|-------------------|------------|----------------------------------------------|---------------------------------------|
| `log.indent` | String | `null` | Prefix for any log entry |
| `log.username ` | Function | `req => req.user ? req.user.username || req.user.email : false` | How to determine the current username |