mb-logger
v1.0.5
Published
Downloads
39
Readme
Logger for Node Applications
Create logger
import { createMBLogger, ILoggerOptions } from "mb-logger"
const loggerOptions: ILoggerOptions = {
serviceName: "service_name",
env: "development",
transports: {}
};
const logger = createMBLogger(loggerOptions);
Usage
import { ICustomAttributes, sessionMiddleware, loggerMiddleware } from "mb-logger"
/* Custom logging fields can be added to the logger. These are field that are intercepted from request object and added to each log. The middleware needs to be added to application. */
const customOptions : ICustomAttributes = {
include: {
headers: ["user-agent"],
body: [],
meta: ["originalUrl", "baseUrl", "url",],
resMeta: []
},
exclude: {
params: ["emailID"],
endPoints: ["/health"]
}
}
// terminal logs
app.use(sessionMiddleware())
// request response logs
app.use(loggerMiddleware(logger))
implementation
https://docsapp.atlassian.net/wiki/spaces/LABS/pages/2722988037/LoggerService+node+Implementation+mb-logger
Output
error: service_name: 01-Dec-2022 01:41:24: Cannot read properties of null (reading 'a') :: {"stack":["TypeError: Cannot read properties of null (reading 'a')\n at AppController.getOrders (/Users/shanawarhasnain/Documents/workspace/service_name/src/app.controller.ts:20:18)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"],"user-agent":"PostmanRuntime/7.29.2","originalUrl":"/app/orders","url":"/app/orders","params":{},"method":"GET","hostname":"localhost","ip":"::1","x-mb-rid":"ba653089-f6c6-42a8-9678-fc31108a6445","customMessage":"Error message"}