dm-logger
v1.0.12
Published
1. npm run build 1. cd demo 1. node logger-demo.js 1. npx ts-node -P tsconfig.demo.json index.ts
Downloads
162
Readme
Steps to Run
- npm run build
- cd demo
- node logger-demo.js
- npx ts-node -P tsconfig.demo.json index.ts
How to integrate this logger ?
- Add an .npmrc file
- Add this package from Azure Feeds to package.json
- Install Dependencies - npm i
- Create a logger initialization file (standard name - addLogConfig.js) with the following code snippet:
const { logConfig: LogConfig } = require('@privatelib/logger'); module.exports = (serviceConfigurations) => { const logConfig = new LogConfig(); if (!serviceConfigurations) { return logConfig; } logConfig.debug = serviceConfigurations.debug; logConfig.logFileRetention = serviceConfigurations.logFileRetention; logConfig.datePattern = serviceConfigurations.datePattern; logConfig.logFolder = process.env.SERVICE_LOGS_PATH || serviceConfigurations.logFolder; logConfig.env = serviceConfigurations.env; logConfig.hostname = serviceConfigurations.hostname; logConfig.ipaddress = serviceConfigurations.ipaddress; logConfig.servicename = serviceConfigurations.servicename; return logConfig; };
- Add the following code to the starting point of the application. Make sure to add this before the other modules are getting loaded in the application.
const loggerModule = require('@privatelib/logger'); const addLogConfig = require('../addLogConfig'); const logConfig = addLogConfig(configJson.logOptions); const loggerObject = new loggerModule.logWrapper(logConfig); loggerModule.logger = loggerObject;
- Use the logger.info, logger.debug, logger.warn and logger.error functions to log messages.
- All the above functions have 2 args - message as string, props as obj.
- Guidelines for props
- prompt: object
- key: string
- value: string
- error: object (Make sure that this is a pure error object, do not print any other values using this key)
- name: string
- stack: string
- status: string
- message: string
- browser: string
- config: string
- cookies: string
- createdBy: string
- isTrusted: boolean
- licenseType: string
- port: string
- host: string
- key: string
- message: string
- type: string
- body: string
- token: string
- sender: string
- wsId: string
- botId: string
- userId: string
- agentId: string
- loginId: string
- clientId: string
- channelId: string
- requestId: string
- sessionId: string
- messageId: string
- routeName: string
- userData: string
- propString: string (For all other props or any props that Dev wants to check)
- prompt: object
- Installing Filebeat link
- The docker-compose's env vars are populated inside filebeat.
smart-analytics: container_name: smart-analytics image: sbh/smart-analytics:dev-latest environment: - NODE_ENV=DEV - PORT=6790 - KAFKA_HOST=x.x.x.x - KAFKA_PORT=xxxx - SERVICE_LOGS_PATH=x/x/x/*.log
Appendix
Installing Filebeat in Docker-Ubuntu
RUN mkdir /etc/apt/keyrings/
RUN wget -O - https://artifacts.elastic.co/GPG-KEY-elasticsearch | gpg --dearmor -o /etc/apt/keyrings/elasticsearch-keyring.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-8.x.list
RUN apt update
RUN apt -y install filebeat=8.7.1
ElasticSearch Mappings
{
"mappings": {
"dynamic": false,
"properties": {
"infolog": {
"properties": {
"env": {
"type": "text",
"store": true
},
"event": {
"type": "text",
"store": true
},
"exception": {
"type": "text",
"store": true
},
"hostname": {
"type": "text",
"store": true
},
"ipaddress": {
"type": "text",
"store": true
},
"level": {
"type": "text",
"store": true
},
"loggerVersion": {
"type": "text",
"store": true
},
"servicename": {
"type": "text",
"store": true
},
"serviceVersion": {
"type": "text",
"store": true
},
"stackTrace": {
"type": "text",
"store": true
},
"timestamp": {
"type": "date",
"store": true
},
"ingesttimestamp": {
"type": "date",
"store": true
},
"message": {
"type": "text",
"store": true
},
"properties": {
"properties": {
"prompt": {
"properties": {
"key": {
"type": "text",
"store": true
},
"value": {
"type": "text",
"store": true
}
}
},
"error": {
"properties": {
"name": {
"type": "text",
"store": true
},
"stack": {
"type": "text",
"store": true
},
"status": {
"type": "text",
"store": true
},
"message": {
"type": "text",
"store": true
}
}
},
"browser": {
"type": "text",
"store": true
},
"config": {
"type": "text",
"store": true
},
"cookies": {
"type": "text",
"store": true
},
"createdBy": {
"type": "text",
"store": true
},
"isTrusted": {
"type": "boolean",
"store": true
},
"licenseType": {
"type": "text",
"store": true
},
"port": {
"type": "text",
"store": true
},
"host": {
"type": "text",
"store": true
},
"key": {
"type": "text",
"store": true
},
"message": {
"type": "text",
"store": true
},
"type": {
"type": "text",
"store": true
},
"body": {
"type": "text",
"store": true
},
"token": {
"type": "text",
"store": true
},
"sender": {
"type": "text",
"store": true
},
"wsId": {
"type": "text",
"store": true
},
"botId": {
"type": "text",
"store": true
},
"userId": {
"type": "text",
"store": true
},
"agentId": {
"type": "text",
"store": true
},
"loginId": {
"type": "text",
"store": true
},
"clientId": {
"type": "text",
"store": true
},
"channelId": {
"type": "text",
"store": true
},
"requestId": {
"type": "text",
"store": true
},
"sessionId": {
"type": "text",
"store": true
},
"messageId": {
"type": "text",
"store": true
},
"routeName": {
"type": "text",
"store": true
},
"userData": {
"type": "text",
"store": true
},
"propString": {
"type": "text",
"store": true
}
}
}
}
},
"LEVEL": {
"type": "keyword",
"store": true
}
}
}
}