1.0.2 • Published 5 months ago

nebka-logger v1.0.2

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

šŸ“¦ 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:

DependencyRecommended 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!

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago