UNPKG

@zishone/logan

Version:

A logger and log middleware. Why logan? Because it sounds like morgan

50 lines (35 loc) 1.64 kB
# logan [![NPM](https://img.shields.io/npm/v/@zishone/logan)](https://www.npmjs.com/package/@zishone/logan) [![Build](https://github.com/zishone/logan/workflows/build/badge.svg)](https://github.com/zishone/logan/actions?query=workflow%3Abuild) [![codecov](https://codecov.io/gh/zishone/logan/branch/main/graph/badge.svg?token=8aHZoVtJqd)](https://codecov.io/gh/zishone/logan) [![License](https://img.shields.io/github/license/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.