logstack-zee
Version:
Complete Node.js logging solution with 6 integration methods, S3 bidirectional operations, advanced analytics, and multi-cloud storage support for enterprise-scale applications.
279 lines (218 loc) โข 6.39 kB
Markdown
# ๐ LogStack Package Link Setup Guide
## โ
Step 1: Package Linked Successfully
You've already run `npm link` in the LogStack directory, which means the package is now globally linked.
## ๐ Step 2: Use in Another Project
### **Method 1: Link in Existing Project**
Navigate to your test project directory and run:
```bash
cd /path/to/your/test-project
npm link logstack
```
### **Method 2: Create New Test Project**
```bash
# Create a new test project
mkdir logstack-test
cd logstack-test
npm init -y
# Link the logstack package
npm link logstack
# Install other dependencies if needed
npm install express mongoose
```
## ๐ Step 3: Test the Package
### **Create test file: `test-logstack.js`**
```javascript
const { init, createDailyJobs, saveApiLog } = require("logstack");
async function testLogStack() {
console.log("๐งช Testing LogStack package...");
const config = {
dbUri: "mongodb://localhost:27017/logstack-test",
uploadProvider: "local",
outputDirectory: "./test-logs",
retention: {
dbRetentionDays: 7,
fileRetentionDays: 30,
},
dataMasking: {
enabled: true,
maskPasswords: true,
maskEmails: false,
},
};
try {
// Initialize LogStack
await init(config);
console.log("โ
LogStack initialized successfully");
// Test saving a log
await saveApiLog({
method: "GET",
path: "/api/test",
statusCode: 200,
responseTime: 123,
timestamp: new Date(),
clientIP: "127.0.0.1",
userAgent: "Test Agent",
});
console.log("โ
Test log saved successfully");
// Create daily jobs
await createDailyJobs();
console.log("โ
Daily jobs created successfully");
console.log("๐ All tests passed!");
} catch (error) {
console.error("โ Test failed:", error);
}
}
testLogStack();
```
### **Run the test:**
```bash
node test-logstack.js
```
## ๐ง Step 4: Express.js Integration Test
### **Create `express-test.js`:**
```javascript
const express = require("express");
const { init, saveApiLog } = require("logstack");
const app = express();
app.use(express.json());
// Initialize LogStack
async function setupLogStack() {
await init({
dbUri: "mongodb://localhost:27017/express-test",
uploadProvider: "local",
outputDirectory: "./express-logs",
});
console.log("โ
LogStack ready for Express");
}
// Logging middleware
app.use(async (req, res, next) => {
const startTime = Date.now();
res.on("finish", async () => {
try {
await saveApiLog({
method: req.method,
path: req.path,
statusCode: res.statusCode,
responseTime: Date.now() - startTime,
timestamp: new Date(),
clientIP: req.ip,
userAgent: req.get("User-Agent"),
});
} catch (error) {
console.error("Logging error:", error);
}
});
next();
});
// Test routes
app.get("/api/test", (req, res) => {
res.json({ message: "LogStack test successful!", timestamp: new Date() });
});
app.post("/api/data", (req, res) => {
res.json({ received: req.body, processed: true });
});
// Start server
const PORT = 3001;
setupLogStack().then(() => {
app.listen(PORT, () => {
console.log(`๐ Test server running on http://localhost:${PORT}`);
console.log("๐ LogStack logging active");
console.log("\n๐งช Test endpoints:");
console.log(` GET http://localhost:${PORT}/api/test`);
console.log(` POST http://localhost:${PORT}/api/data`);
});
});
```
### **Run Express test:**
```bash
node express-test.js
```
## ๐ Step 5: File Structure Check
After running tests, your test project should look like:
```
your-test-project/
โโโ package.json
โโโ test-logstack.js
โโโ express-test.js
โโโ test-logs/ # LogStack output directory
โ โโโ logs_2025-09-03/
โโโ node_modules/
โโโ logstack -> [linked to your dev package]
```
## ๐ Step 6: Making Changes & Testing
When you make changes to your LogStack package:
1. **Build the changes:**
```bash
cd /path/to/logstack
npm run build
```
2. **Test immediately** (no need to re-link):
```bash
cd /path/to/your-test-project
node test-logstack.js
```
## ๐งช Step 7: Advanced Testing
### **Test with Different Configurations:**
```javascript
// test-configurations.js
const { init } = require("logstack");
const configs = [
{
name: "Local Storage",
config: {
dbUri: "mongodb://localhost:27017/test-local",
uploadProvider: "local",
outputDirectory: "./logs-local",
},
},
{
name: "S3 Storage",
config: {
dbUri: "mongodb://localhost:27017/test-s3",
uploadProvider: "s3",
s3: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: "us-east-1",
bucket: "test-logs-bucket",
},
},
},
];
async function testConfigurations() {
for (const test of configs) {
console.log(`\n๐งช Testing: ${test.name}`);
try {
await init(test.config);
console.log(`โ
${test.name} - Success`);
} catch (error) {
console.error(`โ ${test.name} - Failed:`, error.message);
}
}
}
testConfigurations();
```
## ๐ฏ Quick Commands Summary
```bash
# In your LogStack development directory:
npm link # Already done โ
# In your test project:
npm link logstack # Link the package
node test-logstack.js # Run basic test
node express-test.js # Run Express integration test
# When making changes to LogStack:
cd /path/to/logstack
npm run build # Build changes
cd /path/to/test-project
node test-logstack.js # Test immediately
```
## ๐ Step 8: Unlink When Done
When you're finished testing:
```bash
# In test project:
npm unlink logstack
# In LogStack directory:
npm unlink
```
## ๐ You're Ready!
Your LogStack package is now linked and ready for testing in any project. The linked package will automatically reflect any changes you make to the source code (after building). Happy testing! ๐