aol-logger
v1.0.42
Published
A configurable logger package with audit support using winston
Maintainers
Readme
aol-logger
A lightweight, enterprise-ready logger. Supports structured logs for both application and audit events, and integrates smoothly with PM2 + ELK stack environments.
📦 Installation
npm install aol-logger🚀 Getting Started
Step 1: Initialize the Logger
In your service, create a logger.ts file to initialize and export the loggers:
// logger.ts
import { initLogger } from "aol-logger";
export const { logger, auditLogger } = initLogger("bx-be", "info");Parameters:
service_name: Name of the service (bx-be,caps-be, etc.)minLogLevel: Log level threshold (debug,info,warn,error)
📘 Usage
Import and use the logger and auditLogger as shown below:
// someService.ts
import { logger, auditLogger } from "./logger";
// General logs
logger.debug("Debugging mode active");
logger.info("User fetched successfully");
logger.warn("Disk space running low");
logger.error("Database connection failed");
// Audit logs
auditLogger.info("audit log", {
user_id: 1,
event_action: "create",
event_type: "course",
event_id: 123,
location_id: 1
});🔍 Audit Log Fields Explained
Audit logs are critical for maintaining traceability of important actions in your system. Here's what each field means in the auditLogger payload:
🧑 user_id
- Type:
number | string - Description: Unique identifier of the user who performed the action.
- Purpose: Allows identifying which user is responsible for an operation.
🛠️ event_action
- Type:
string - Examples:
"create","update","delete","view","login","logout" - Description: Describes the type of action performed.
- Purpose: Classifies the user’s operation for better auditing.
🧱 event_type
- Type:
string - Examples:
"course","user","payment","settings" - Description: The domain/entity that the action is related to.
- Purpose: Helps segment audit logs by entity or feature.
🆔 event_id
- Type:
number | string - Description: Identifier of the affected entity (e.g., course ID).
- Purpose: Gives context about the specific resource involved in the action.
🆔 location_id
- Type:
number | string - Description: Identifier for the location, tenant, or region where the action occurred.
- Purpose: Useful for filtering logs in multi-tenant or multi-region applications.
- Examples: In PF, use
tenant_id, In TPTM, useregion_id
✅ Example
auditLogger.info("audit log", {
user_id: 1,
event_action: "create",
event_type: "course",
event_id: 123,
location_id: 1
});📘 This means: "User 1 has created a course in location-1 with ID 123."
🔐 Best Practices
- Initialize
loggerandauditLoggeronce per service. - Use audit logs for all critical operations that affect user data or system state.
- Set
minLogLevelusing environment variables for different environments (dev, staging, prod).
🛠️ Supported Environments
- Node.js (Express, NestJS, etc.)
- Deno (via compatibility layer)
- Compatible with PM2, Docker, ELK, and more
📄 License
MIT © Art of Living Digital
