nebka-logger v1.0.2
š¦ Logger Package - Send Logs to RabbitMQ with JWT Authentication
A Node.js package for sending logs to RabbitMQ with JWT authentication (RSA). This package is designed for distributed services that require secure logging.
š Features
ā
Send logs to RabbitMQ with persistent messages
ā
JWT authentication with RSA keys (Private key for signing, Public key for verification)
ā
Uses environment variables (.env
) for secure configurations
ā
Supports TypeScript and JavaScript
ā
Optimized and lightweight for microservices
š„ Installation
Install the package using npm
or yarn
:
# Using NPM
npm install nebka-logger
# Using Yarn
yarn add nebka-logger
āļø Environment Variables (.env
)
After installing the package, create a .env
file in the root of your project and set the following values:
# š RSA key paths for signing tokens
PRIVATE_KEY_PATH=/secure/path/to/rsaKeys/tokenPrivate.key
PUBLIC_KEY_PATH=/secure/path/to/rsaKeys/tokenPublic.key
# Or use Base64 encoded keys
# PRIVATE_KEY_BASE64=MIICWwIBAAKBgQC...
# ā
Allow token generation
ALLOW_GENERATE_TOKEN=true
# š RabbitMQ Configuration
RABBITMQ_URL=amqp://localhost
LOG_QUEUE=logQueue
š Security Tip:
Always add.env
to your.gitignore
file to prevent sensitive data from being committed.
š Usage
1. Initialize and Use in Your Project
const Logger = require("your-logger-package");
// Create a logger instance with a custom service name
const logger = new Logger("MyService");
// Send a log message
logger.sendLogInfo({ level: "info", message: "Logger initialized!" });
2. Example Log Messages
logger.sendLogInfo({ level: "info", message: "Operation successful." });
logger.sendLogInfo({
level: "error",
message: "An error occurred!",
errorCode: 500
});
logger.sendLogInfo({
level: "warning",
message: "High memory usage detected!",
details: { memoryUsage: "85%" }
});
š Log Message Structure
Each message sent to RabbitMQ includes the following fields:
{
"level": "info",
"message": "Your log message",
"timestamp": "2025-03-03T12:00:00Z",
"service": "MyService",
"token": "eyJhbGciOiJIUzI1NiIsInR..."
}
š Authentication & RSA Keys
1. If You Don't Have RSA keys:
:You have to use Nebka private and public keys due to security logic in other services.
š Project Dependencies
This package uses the following libraries:
Dependency | Recommended Version |
---|---|
amqplib | ^0.10.3 |
jsonwebtoken | ^9.0.2 |
dotenv | ^16.4.7 |
š Developing & Testing the Package
1. Clone the Repository
git clone
cd logger-package
2. Install Dependencies
npm install
3. Run Tests
npm test
š” Security Best Practices
- Never expose your private key (
tokenPrivate.key
). - Add
.env
to.gitignore
to prevent committing sensitive data. - Use a Secret Manager for production environments instead of storing keys in files.
- Configure RabbitMQ to ensure messages persist and are not lost.
š© Author: NEBKA-DEV.com
š GitHub Repository: []
š Enjoy using the package and feel free to contribute!