logginglibraryformerndevdashboard
v3.2.0
Published
The Logging Library for the DevDashboard is designed to provide robust logging capabilities throughout the application. It focuses on capturing detailed logs with custom decorators that handle both success and error states efficiently, and it supports han
Downloads
8
Readme
Logging Library
The Logging Library for the DevDashboard is designed to provide robust logging capabilities throughout the application. It focuses on capturing detailed logs with custom decorators that handle both success and error states efficiently, and it supports handling of circular references in logged data.
Features
- Logging Decorator: Enhances functions with automatic logging of input, output, exceptions, and other operational metadata.
- Circular Reference Handling: Utilizes a custom JSON stringification method to safely log data structures that include circular references.
- File Logging: Automatically writes logs to a JSON file, which can be used for auditing and debugging purposes.
Installation
Ensure you have Node.js installed on your system to use the Logging Library. Follow these steps to set up the library in your project:
Clone the DevDashboard repository if you haven't already:
git clone https://github.com/yourgithub/devdashboard.git cd DevDashboard/loggingLibrary npm install
Usage
The logDecorator can be imported into your Node.js modules to enhance any function with logging capabilities. Here's how to use it:
import { logDecorator } from './src/logging.js';
const exampleFunction = async (data) => {
return "Processing complete";
};
const options = {
expectedInput: "Sample data",
expectedOutput: "Processing complete",
criticality: "High",
description: "Example function for demonstration",
environment: process.env.NODE_ENV || "development",
};
const decoratedFunction = logDecorator(exampleFunction, options);
// Use the decorated function as normal
decoratedFunction("Sample data").then(console.log).catch(console.error);
Logging Decorator Details
The logging decorator wraps any asynchronous function, capturing and logging the following information:
- Function Name: Automatically captured from the function it decorates.
- Timestamp: The time at which the function was called.
- Expected and Actual Input/Output: Logs what inputs were received and what outputs were produced.
- Criticality and Description: Custom descriptions and criticality levels for better understanding of log entries.
- Environment: The environment in which the function is running, typically development, staging, or production.
- Status: Indicates success or error states.
- Exceptions: Captures any exceptions thrown by the function.
- Sub-functions: Allows for nesting logs of other functions called within the decorated function.
Testing
To run tests and ensure the logging functionality works as expected:
npm test
This will execute predefined test cases that verify the decorator handles various scenarios correctly, including proper function enhancement, error handling, and circular reference management.
Contributing
Contributions to enhance or expand the logging library are welcome. Please ensure to follow standard coding practices and add tests for new features.
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Project Link: https://github.com/mwegter95/dev-dashboard