@maqsoodia777/ghostlogger
v1.0.3
Published
A logging utility with a real-time monitoring dashboard.
Maintainers
Readme
GhostLogger
A high-performance logging utility with real-time monitoring, sensitive data masking, and a central dashboard.
Features
- Real-time Log Monitoring: View your application logs in real-time on the GhostLogger dashboard.
- Sensitive Data Masking: Automatically mask passwords, API keys, and other sensitive fields.
- Dynamic Rules Syncing: Sync masking rules directly from your dashboard without redeploying.
- Sampling Logic: Control the volume of logs sent to the cloud to optimize costs.
- Express Middleware: Easy integration with Express.js to log and mask incoming request data.
- Customizable: Configure colors, timestamps, JSON output, and local file logging.
Installation
Install the package via npm:
npm i @maqsoodia777/ghostloggerQuick Start
1. Configuration
Initialize the logger with your API key and other optional settings:
const {
configure,
gLog,
ghostMiddleware,
} = require("@maqsoodia777/ghostlogger");
configure({
apiKey: "YOUR_GHOST_API_KEY",
endpoint: "https://api.ghostlogger.io/api/logs", // Optional: Custom endpoint
enabled: true,
colors: true,
timestamps: true,
samplingRate: 1.0, // 100% logs (0.0 to 1.0)
sensitiveKeys: ["password", "token", "secret"], // Default masking keys
});
// Enable automatic syncing of masking rules from the dashboard
gLog.startAutoSync();2. Basic Logging
Use the gLog object for different log levels:
gLog.info("User logged in", { userId: 123 });
gLog.warn("High memory usage detected", { usage: "85%" });
gLog.error("Database connection failed", new Error("Connection timeout"));
gLog.debug("Query execution time", { ms: 45 });3. Middleware Integration (Express)
Automatically log and mask sensitive data in incoming requests:
const express = require("express");
const { ghostMiddleware } = require("@maqsoodia777/ghostlogger");
const app = express();
app.use(express.json());
// Apply GhostLogger middleware
app.use(ghostMiddleware);
app.post("/login", (req, res) => {
// Passwords and tokens in req.body/headers will be automatically masked in logs
res.send("Logged in!");
});Advanced Features
Sensitive Data Masking
GhostLogger automatically scans log objects and masks fields matching your sensitiveKeys or custom regex rules synced from the dashboard.
gLog.info("Processing payment", {
card_number: "1234-5678-9012-3456", // Masked if rule exists
cvv: "123", // Masked if rule exists
});Remote Rules Syncing
You can manage masking rules (regex patterns) from the GhostLogger dashboard. Call gLog.startAutoSync() to keep your local instance updated with the latest rules every 5 minutes.
Sampling
Reduce log volume by setting a samplingRate (0.0 to 1.0). For example, a rate of 0.1 will only send 10% of logs to the cloud.
configure({ samplingRate: 0.1 });Configuration Options
| Option | Type | Default | Description |
| :-------------- | :--------- | :------ | :------------------------------------------------ |
| apiKey | string | "" | Your GhostLogger project API key. |
| enabled | boolean | true | Enable or disable logging. |
| colors | boolean | true | Enable colored console output. |
| timestamps | boolean | true | Include timestamps in logs. |
| json | boolean | false | Output logs in JSON format to console. |
| samplingRate | number | 1.0 | Probability of sending logs to SaaS (0.0 to 1.0). |
| sensitiveKeys | string[] | [] | List of keys to always mask. |
| endpoint | string | "" | SaaS API endpoint for log delivery. |
| filePath | string | "" | Local file path to save logs. |
| maskAll | boolean | false | If true, masks all fields in the data object. |
Dashboard
Access your logs and manage rules at ghostlogger.io.
