# Quick Log Reference When something fails, use these commands to quickly check logs. ## 🚀 Quick Commands ### Check All Services for Errors ```bash ./scripts/check-logs.sh ``` Shows PM2 status and recent errors from all services. ### Follow Errors in Real-Time ```bash ./scripts/tail-errors.sh ``` Watches all error logs live (press Ctrl+C to exit). ### View Recent Errors (Last 10 minutes) ```bash ./scripts/view-recent-errors.sh ``` ### View Errors from Last 30 minutes ```bash ./scripts/view-recent-errors.sh 30 ``` ## 📋 PM2 Commands ```bash # View all logs pm2 logs # View specific service logs pm2 logs punimtag-api pm2 logs punimtag-worker pm2 logs punimtag-admin pm2 logs punimtag-viewer # View only errors pm2 logs --err # Monitor services pm2 monit # Check service status pm2 status pm2 list ``` ## 📁 Log File Locations All logs are in: `/home/appuser/.pm2/logs/` - **API**: `punimtag-api-error.log`, `punimtag-api-out.log` - **Worker**: `punimtag-worker-error.log`, `punimtag-worker-out.log` - **Admin**: `punimtag-admin-error.log`, `punimtag-admin-out.log` - **Viewer**: `punimtag-viewer-error.log`, `punimtag-viewer-out.log` ### Click Logs (Admin Frontend) Click logs are in: `/opt/punimtag/logs/` - **Click Log**: `admin-clicks.log` (auto-rotates at 10MB, keeps 5 backups) - **View live clicks**: `tail -f /opt/punimtag/logs/admin-clicks.log` - **View recent clicks**: `tail -n 100 /opt/punimtag/logs/admin-clicks.log` - **Search clicks**: `grep "username\|page" /opt/punimtag/logs/admin-clicks.log` - **Cleanup old logs**: `./scripts/cleanup-click-logs.sh` **Automated Cleanup (Crontab):** ```bash # Add to crontab: cleanup logs weekly (Sundays at 2 AM) 0 2 * * 0 /opt/punimtag/scripts/cleanup-click-logs.sh ``` ## 🔧 Direct Log Access ```bash # View last 50 lines of API errors tail -n 50 /home/appuser/.pm2/logs/punimtag-api-error.log # Follow worker errors tail -f /home/appuser/.pm2/logs/punimtag-worker-error.log # Search for specific errors grep -i "error\|exception\|traceback" /home/appuser/.pm2/logs/punimtag-*-error.log ``` ## 🔄 Log Rotation Setup Run once to prevent log bloat: ```bash ./scripts/setup-log-rotation.sh ``` This configures: - Max log size: 50MB (auto-rotates) - Retain: 7 rotated files - Compress: Yes - Daily rotation: Yes (midnight) ## 💡 Troubleshooting Tips 1. **Service keeps crashing?** ```bash ./scripts/check-logs.sh pm2 logs punimtag-worker --err --lines 100 ``` 2. **API not responding?** ```bash pm2 logs punimtag-api --err pm2 status ``` 3. **Large log files?** ```bash # Check log sizes du -h /home/appuser/.pm2/logs/* # Setup rotation if not done ./scripts/setup-log-rotation.sh ``` 4. **Need to clear old logs?** ```bash # PM2 can manage this with rotation, but if needed: pm2 flush # Clear all logs (be careful!) ``` 5. **Viewing click logs?** ```bash # Watch clicks in real-time tail -f /opt/punimtag/logs/admin-clicks.log # View recent clicks tail -n 100 /opt/punimtag/logs/admin-clicks.log # Search for specific user or page grep "admin\|/identify" /opt/punimtag/logs/admin-clicks.log ```