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.

157 lines (107 loc) โ€ข 3.73 kB
# ๐Ÿงช Testing Cron Log Service with Your Database This guide shows you how to test the logstack with your existing database containing logs. ## ๐Ÿ“‹ Prerequisites 1. **MongoDB running** on localhost:27017 (or update connection string) 2. **Your database** with existing log data 3. **Node.js** and npm installed ## ๐Ÿš€ Quick Test Methods ### Method 1: Test with Sample Data (Recommended for first test) ```bash npm run test:sample-data ``` This will: - Create a test database with sample API logs - Process the logs and generate files - Show you exactly how the system works ### Method 2: Test with Your Existing Database 1. **Update the database name** in `examples/testExistingDb.ts`: ```typescript dbUri: "mongodb://localhost:27017/YOUR_DATABASE_NAME"; ``` 2. **Run the test**: ```bash npm run test:existing-db ``` ### Method 3: Basic Test ```bash npm run test:basic ``` ## ๐Ÿ”ง Customizing for Your Database ### Step 1: Update Connection String Edit any example file and change: ```typescript dbUri: "mongodb://localhost:27017/YOUR_ACTUAL_DB_NAME"; ``` ### Step 2: Customize Data Provider (Optional) If you want to fetch from specific collections, edit `lib/userDataProvider.ts`: ```typescript // Replace collection names with your actual collections const possibleCollections = ["your_logs", "audit_logs", "app_logs"]; // Replace timestamp field names with your actual fields const timestampFields = ["timestamp", "created_at", "log_time"]; ``` ## ๐Ÿ“ Output Files Generated files will be saved to: ``` your-project-directory/ โ””โ”€โ”€ YYYY-MM-DD/ # Date folder โ”œโ”€โ”€ 00-01.json # Hour 00-01 logs โ”œโ”€โ”€ 01-02.json # Hour 01-02 logs โ””โ”€โ”€ ... # Other hours ``` ## ๐Ÿƒโ€โ™‚๏ธ Running the Tests ```bash # Build first npm run build # Test with sample data (recommended first) npm run test:sample-data # Test with your existing database npm run test:existing-db # Basic functionality test npm run test:basic ``` ## ๐Ÿ” What Each Test Does ### `test:sample-data` - Creates sample API logs in MongoDB - Processes them into files - Perfect for understanding how the system works ### `test:existing-db` - Connects to your existing database - Tries to find logs in common collections - Processes real data from your database ### `test:basic` - Simple test with minimal logging - Uses automatic data detection - Good for quick verification ## ๐Ÿ› Troubleshooting ### No logs found? - Check your database name in the connection string - Verify your collections have data - Look at console output for diagnostic information ### Permission errors? - Ensure MongoDB is running - Check file system permissions for output directory - Verify MongoDB connection credentials ### Custom collection names? Edit `lib/userDataProvider.ts` and update the collection names: ```typescript const possibleCollections = ["your_actual_collection_name"]; ``` ## ๐Ÿ“Š Example Output ``` ๐Ÿš€ Starting basic logstack test... โœ… Service initialized ๐Ÿ“… Creating daily jobs for 2025-08-25 โšก Running hourly job... ๐Ÿ” Fetching data for 2025-08-25 10-11 ๐Ÿ“Š Found 15 API logs for 10-11 ๐Ÿ“ Generated files should be in: E:\your-project\2025-08-25\ ๐ŸŽ‰ Basic test completed! ``` ## ๐ŸŽฏ Next Steps 1. **Run a test** to see the system in action 2. **Check generated files** in the date folder 3. **Customize** the data provider for your specific needs 4. **Set up cron jobs** for automatic processing 5. **Configure cloud storage** if needed (S3, GCS, Azure)