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
Markdown
# ๐งช 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)