npm.io
1.0.7 • Published 2 years ago

cmw-frontend-logger

Licence
MIT
Version
1.0.7
Deps
6
Size
22 kB
Vulns
0
Weekly
0

cmw-frontend-logger

cmw-frontend-logger is a logging utility that seamlessly captures console output, window interactions, and API request data within your applications.

Installation


npm install cmw-frontend-logger

Usage

Step 1 : Initialize the centralized logger in a file

In your project file, import the necessary functions from cmw-frontend-logger:
import { getEnv, getProjectId } from "path_to_env_file";
import { createLogger } from "cmw-frontend-logger";
export const centralizedLogger = () => {
  return createLogger({
    projectId: getProjectId(),
    disableLogs: getEnv() !== "dev",
  });
};

Configuration

The createLogger function can be configured using the following options:
{
  projectId: "projectName-stage"; // naming convention  : "projectName-envType" Unique ID for the logs stored in the database.
  //envType : ["dev","stage","prod"]
  disableLogs: false; //Boolean value to control error logging. Set to true to disable logging in dev environments.
}

Step 2: Use withLogAxios for Axios Requests

Now you can use the withLogAxios function to create an axios instance with logging capabilities:
import axios from "axios";
import { centralizedLogger } from "path_to_initialization_file_from_step_1";

const { createLogAxiosFn } = centralizedLogger();
const withLogAxios = createLogAxiosFn(axios);
// Use withLogAxios for axios requests

return withLogAxios({
  /* axios config */
})
  .then((response) => {
    // Handle the response
  })
  .catch((error) => {
    // Handle the error
  });

How to Publish the Package

Step 1: Update Package Version
In your package.json file, update the version number:
{
"name": "cmw-frontend-logger",
"version": "1.0.4",
// ... other package.json fields
}
Step 2: Publish to npm
Run the following command to publish your package to npm:

npm publish