https://github.com/aerisweather/winstonjs-transport-http-headers
A WinstonJS transport that logs to HTTP headers, useful for sending profiling data to the browser that doesn't muddle the response body.
https://github.com/aerisweather/winstonjs-transport-http-headers
express logging nodejs winston
Last synced: 3 months ago
JSON representation
A WinstonJS transport that logs to HTTP headers, useful for sending profiling data to the browser that doesn't muddle the response body.
- Host: GitHub
- URL: https://github.com/aerisweather/winstonjs-transport-http-headers
- Owner: aerisweather
- License: mit
- Created: 2016-02-05T21:49:05.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-02-05T21:11:32.000Z (over 7 years ago)
- Last Synced: 2025-11-22T05:03:12.082Z (8 months ago)
- Topics: express, logging, nodejs, winston
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
WinstonJS Transport: HTTP Headers
=================================
A WinstonJS transport that logs to HTTP headers, useful for sending profiling data to the browser that doesn't muddle the response body.
Master Build Status:
[](https://travis-ci.org/aerisweather/winstonjs-transport-http-headers)
[](https://coveralls.io/github/aerisweather/winstonjs-transport-http-headers?branch=master)
__This project sponsored by:__
[](http://www.aerisweather.com) - Empowering the next generation, [aerisweather.com](https://www.aerisweather.com)
Installation
------------
This project is available on npm:
```sh
npm install --save winstonjs-transport-http-headers
```
Example
-------
**Note:** A full example can be found in `example.js` which integrates an ExpressJS HTTP Server
The logger should be added to the response, probably in middleware:
```javascript
// Middleware example to setup our logger.
app.use(function(req, res, next) {
res.logger = new (winston.Logger)({
transports: [
// Here is our new logger
new HttpHeaderTransport({
setHeader: res.set.bind(res),
level: 'debug'
}),
// We can use the HTTP Header logger in combination with other loggers too.
new (winston.transports.Console)({
level: 'warn'
})
],
//Setup Levels for this logger
levels: {
warn: 4,
info: 6,
debug: 7
}
});
next();
});
```
Then in an action, we can log something to the response:
```javascript
// Will log to a header: `x-logger-0-debug`
res.logger.log('debug', 'Basic Log Message');
// Will log to both a header and the console (as defined above)
res.logger.log('warn', 'Uh oh');
```
Docs
----
### new HttpHeaders(options)
| Param | Type | Default | Description |
| ------------ | ---------- | ------------- | ------------------------------------------------------------------------- |
| setHeader | `function` | | A callable (key, value) that will set the header to the request. |
| silent | `boolean` | `false` | If enabled, logger will not log to HTTP Header, will not emit events. |
| level | `level` | `"debug"` | What level this logger should respond to, see Winston docs for more info. |
| headerPrefix | `string` | `"X-Logger-"` | A callable that provides a string that is prepended to each header. |
| getHeaderId | `function` | `(default)` | A callable that gets a header ID based on passed options. |
| cleanId | `function` | `(default)` | Cleans a string into a nice HTTP friendly header ID. |