UNPKG

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
# ๐Ÿ”— 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! ๐Ÿš€