@zishone/logan
Version:
A logger and log middleware. Why logan? Because it sounds like morgan
50 lines (35 loc) • 1.64 kB
Markdown
# logan [](https://www.npmjs.com/package/@zishone/logan) [](https://github.com/zishone/logan/actions?query=workflow%3Abuild) [](https://codecov.io/gh/zishone/logan) [](https://github.com/zishone/logan/blob/master/LICENSE)
A logger and log middleware. Why logan? Because it sounds like [morgan](https://www.npmjs.com/package/morgan).
## Installation
```shell
$ npm i @zishone/logan
```
## Usage
```javascript
const express = require('express');
const { Logger, log } = require('@zishone/logan');
const app = express();
const logger = new Logger();
app.use(log(logger));
app.get('/get', (req, res) => {
// To log info
req.logger.info('Message', { /* any data */ });
// To log error
req.logger.error('Message', { /* any data */ });
// To log debug
req.logger.debug('Message', { /* any data */ });
// To add any data to per request log
req.addLogData({ /* any data */ });
// To add error data to per request log
req.addLogError(new Error());
res.send({});
});
app.listen(port, () => {
console.log('Listening at port 3000')
})
```
## Authors
* **Zishran Garces**
See also the list of [contributors](https://github.com/zishone/logan/contributors) who participated in this project.
## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/zishone/logan/blob/master/LICENSE) file for details.