1.0.11 • Published 10 days ago

dm-logger v1.0.11

Weekly downloads
-
License
ISC
Repository
-
Last release
10 days ago

Steps to Run

  1. npm run build
  2. cd demo
  3. node logger-demo.js
  4. npx ts-node -P tsconfig.demo.json index.ts

How to integrate this logger ?

  1. Add an .npmrc file
  2. Add this package from Azure Feeds to package.json
  3. Install Dependencies - npm i
  4. 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;
        };
  5. 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;
  6. Use the logger.info, logger.debug, logger.warn and logger.error functions to log messages.

  7. All the above functions have 2 args - message as string, props as obj.
  8. Guidelines for props
    1. prompt: object
      1. key: string
      2. value: string
    2. error: object (Make sure that this is a pure error object, do not print any other values using this key)
      1. name: string
      2. stack: string
      3. status: string
      4. message: string
    3. browser: string
    4. config: string
    5. cookies: string
    6. createdBy: string
    7. isTrusted: boolean
    8. licenseType: string
    9. port: string
    10. host: string
    11. key: string
    12. message: string
    13. type: string
    14. body: string
    15. token: string
    16. sender: string
    17. wsId: string
    18. botId: string
    19. userId: string
    20. agentId: string
    21. loginId: string
    22. clientId: string
    23. channelId: string
    24. requestId: string
    25. sessionId: string
    26. messageId: string
    27. routeName: string
    28. userData: string
    29. propString: string (For all other props or any props that Dev wants to check)
  9. Installing Filebeat link
  10. 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
      }
    }
  }
}
1.0.11

10 days ago

1.0.10

16 days ago

1.0.9

3 months ago

1.0.8

3 months ago

1.0.7

3 months ago

1.0.6

3 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

2.0.0

6 years ago