1.0.12 • Published 2 years ago

micronodelib v1.0.12

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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:

  1. Make change your code
  2. Run npm run build to build package
  3. Update version in package.json
  4. Push new update to main remote branch.
  5. Run npm publish to publish your changes.
1.0.9

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.12

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago