micronodelib
v1.0.12
Published
Common core for NodeJs project
Downloads
8
Readme
Micronodelib
Common core for NodeJs project.
Features
- Request context injected
- Http request log
- Standard logging format
Install
npm install micronodelib
# Or
yarn add micronodelib
Usage
import express, {Application} from "express";
import {Logger, httpContextMiddleware, requestLogMiddleware} from "micronodelib";
const app: Application = express();
// Optional, if you want to override default console log
console.log = Logger.info
console.error = Logger.error
// Enable request context
app.use(httpContextMiddleware());
// Enable http request log
app.use(requestLogMiddleware({
// Ignore request log for specific routes
ignoreRoutes: ["/actuator/health"]
}));
app.listen(3000, () => {
// Using standard log level: debug, info, warn, error
Logger.info('App started');
})
Sample output format
Standard log format
{"level":"INFO","msg":"Test log message","request_meta":{"request_id":"a06dd50a-7127-4f87-bfe0-b7104fb453c9"},"ts":1652842663}
Http request log format
{"level":"INFO","msg":"finish router","request_meta":{"client_ip":null,"execution_time":4,"query":"","request_id":"a06dd50a-7127-4f87-bfe0-b7104fb453c9","request_method":"GET","request_path":"/example-path","request_pattern":"/example-path","status":200,"url":"/example-path","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"},"ts":1652842718}
Development
This package has been published at: https://www.npmjs.com/package/micronodelib
If you want to push new change to this, follow the following steps:
- Make change your code
- Run
npm run build
to build package - Update version in package.json
- Push new update to
main
remote branch. - Run
npm publish
to publish your changes.