2.0.1 • Published 5 months ago

kareem_custom_auditor v2.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

Custom Audit Logger

This Node.js module provides a flexible audit logging mechanism that allows you to log events to both MongoDB and Winston based on your application's needs. The module utilizes the EventEmitter module to emit events, and it comes with a configurable settings class to customize its behavior.

Installation

First, install the required dependencies:

npm install events mongodb winston

Then, you can install the custom audit logger:

npm install path/to/custom_audit_logger

Usage

Import the Module

const {
  custom_audit,
  auditor_Settings: Settings,
} = require("path/to/custom_audit_logger");

Initialize Settings

Create an instance of the Settings class to configure the behavior of the custom audit logger:

const settings = new Settings();
settings.set_settings({
  log_inputs_to_console: false,
  log_inputs_to_winston: true,
  log_inputs_to_mongodb: true,
  winston_logs_directory: "path/to/logs", // Change this to the desired directory
  winston_default_severity_level: "info", // Change this to the desired default severity level for Winston
  mongodb_uri: "mongodb://localhost:27017",
  password: "x",
  database: "audits",
  default_collection: "audits",
});

Show Current Settings (Optional)

If needed, you can check the current settings:

settings.show_settings();

Emit Audit Events

Use the custom_audit function to emit audit events. It takes the following parameters:

  • input (Object or String): The data to be logged.
  • severity_level (String, optional): The severity level for Winston logs. Ignored if input is a String.
  • collection (String, optional): The MongoDB collection to log to. Ignored if input is a String.

Example:

const auditData = { user: "john_doe", action: "login" };
custom_audit(auditData, "info", "user_activity_logs");

This example logs the auditData to both MongoDB and Winston with the specified severity level and collection.

Note

  • If input is an Object, the audit event will be logged to both MongoDB and Winston (if configured).
  • If input is a String, only a Winston log will be generated (if configured).
  • The default severity level for Winston is used if no severity level is provided.

Feel free to customize the settings and usage according to your application's requirements.

2.0.1

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago