@schema31/react-gcloud-monitoring-sdk

1.1.6 • Public • Published

react-gcloud-monitoring-sdk

Setup

import Logger from "@schema31/react-gcloud-monitoring-sdk";

const LoggerConfig = {
  streamname: "development", //mandatory: the log stream name
  authentication: "456476567567", //mandatory: the log stream authentication key
  threshold: 7, //optional: the default value is 7, corresponding to DEBUG level
  url: "https://yourStreamUrl.com/" //optional: default url for logging 
}
const devMode = true;

/**
  *
  * @param {object} LoggerConfig - Basic configurations to setup the logging stream
  * @param {bool} devMode - if true enables additional console logging
  *
  */
const logger = new Logger(LoggerConfig, devMode);

Levels and Thresholds

const EMERGENCY = 0;
const ALERT = 1;
const CRITICAL = 2;
const ERROR = 3;
const WARNING = 4;
const NOTICE = 5;
const INFO = 6;
const DEBUG = 7;

Basic Usage

Exception Logging

try{
   throw Error("Error")
}catch(e){
  logger.logException(e, {
      "Type": "Exception",
      "AppName": "Your application name",
      ...
  })
}

Info Logging

logger.LogInfo({ 
  "short_message": "message_name", //optional: if missing, a default value is provided
  "full_message": "message_name", //optional
  "additionals": {} // optional
})

Debug Logging

logger.LogDebug({ 
  "short_message": "message_name", //optional: if missing, a default value is provided
  "full_message": "message_name", //optional
  "additionals": {} // optional
})

Notice Logging

logger.LogNotice({ 
  "short_message": "message_name", //optional: if missing, a default value is provided
  "full_message": "message_name", //optional
  "additionals": {} // optional
})

Warning Logging

logger.LogWarning({ 
  "short_message": "message_name", //optional: if missing, a default value is provided
  "full_message": "message_name", //optional
  "additionals": {} // optional
})

Error Logging

logger.LogError({ 
  "short_message": "message_name", //optional: if missing, a default value is provided
  "full_message": "message_name", //optional
  "additionals": {} // optional
})

Critical Logging

logger.LogCritical({ 
  "short_message": "message_name", //optional: if missing, a default value is provided
  "full_message": "message_name", //optional
  "additionals": {} // optional
})

Alert Logging

logger.LogAlert({ 
  "short_message": "message_name", //optional: if missing, a default value is provided
  "full_message": "message_name", //optional
  "additionals": {} // optional
})

Emergency Logging

logger.LogEmergency({ 
  "short_message": "message_name", //optional: if missing, a default value is provided
  "full_message": "message_name", //optional
  "additionals": {} // optional
})

In case short_message is not set, the library will send a default code corresponding to the current level: "debug" for DEBUG, "info" for INFO, "notice" for NOTICE, "warning" for WARNING, "error" for EMERGENCY, ALERT, CRITICAL and ERROR.

Package Sidebar

Install

npm i @schema31/react-gcloud-monitoring-sdk

Weekly Downloads

3

Version

1.1.6

License

MIT

Unpacked Size

14.7 kB

Total Files

5

Last publish

Collaborators

  • abrancatelli
  • elorenzo31