rpulogger
v1.0.19
Published
A CDP Library built for Rug Pad USA
Downloads
8
Readme
RPU Logger Documentation
Overview
RPU Logger is a TypeScript-based logging utility designed for Node.js environments. It provides a structured and validated way to log information, errors, and other data, ensuring consistency and reliability in log output.
Features
- Schema Validation: Utilizes Joi for log data validation, ensuring that all logs conform to a predefined schema.
- Flexible Log Data: Supports a variety of log data, including error messages, stack traces, and additional custom data.
- Remote Logging: Capable of sending log data to a remote server for centralized logging.
Installation
To install RPU Logger, use npm:
npm install rpulogger
Usage
Importing RPU Logger
import { createLog, LogData } from "rpu-logger";
Creating a Log Entry
To create a log entry, you need to provide an object that matches the LogData
interface.
const logData: LogData = {
name: "ExampleLog",
source: "exampleSource",
status: 200, // HTTP status code for example
userMessage: "This is a user message",
logtoken: "your-log-token",
// Optional fields
errorMessage: "Error occurred here",
stack_trace: "Error stack trace",
additional_data: { additional: "info" },
};
createLog(logData)
.then(() => {
console.log("Log created successfully");
})
.catch((error) => {
console.error("Log creation failed", error);
});
Log Data Schema
The log data must conform to the following schema:
- name:
string
(required) - Name of the log entry. - source:
string
(required) - Source of the log. - status:
number
(required) - Status code (e.g., HTTP status codes). - userMessage:
string
(required) - A message suitable for user display. - errorMessage:
string
(optional) - Detailed error message. - stack_trace:
string | object
(optional) - Stack trace of the error. - additional_data:
object
(optional) - Any additional data. - logtoken:
string
(required) - A token to authenticate or identify the log entry.
Validating Log Data
The createLog
function internally validates the log data against the schema. If the data is invalid, it throws an error.
Sending Log Data
The createLog
function sends the validated log data to a remote server. Ensure to replace the URL in the addLogEntry
function with your logging endpoint.
Configuration
- The api key must be set under RUGPADWEB_LOG_TOKEN and NEXT_PUBLIC_RUGPADWEB_LOG_TOKEN
- Schema validation rules can be adjusted in the
logSchema
definition as per your requirements.
Best Practices
- Always catch and handle errors when creating logs.
- Ensure sensitive information is not logged.
- Update the logging endpoint to a secure and reliable server.
For more information or support, visit the RPU Logger Repository.
(Note: The above link is a placeholder, replace with the actual URL to your repository/documentation.)