punimtag/QUICK_LOG_REFERENCE.md
tanyar09 d0dd5c82ea
Some checks failed
CI / skip-ci-check (pull_request) Successful in 8s
CI / lint-and-type-check (pull_request) Successful in 54s
CI / test-backend (pull_request) Has been cancelled
CI / build (pull_request) Has been cancelled
CI / secret-scanning (pull_request) Has been cancelled
CI / dependency-scan (pull_request) Has been cancelled
CI / sast-scan (pull_request) Has been cancelled
CI / workflow-summary (pull_request) Has been cancelled
CI / python-lint (pull_request) Has been cancelled
feat: add click logging for admin frontend
- Add backend click logging utility with file rotation and retention
- Add POST /api/v1/log/click endpoint for logging click events
- Add frontend click logger service with batching and context extraction
- Add global click handler in App.tsx for authenticated users
- Add log cleanup script for old log files
- Update QUICK_LOG_REFERENCE.md with click log documentation

Logs are written to /opt/punimtag/logs/admin-clicks.log with:
- Auto-rotation at 10MB (keeps 5 backups)
- 30-day retention
- Format: timestamp | username | page | element_type | element_id | element_text | context
2026-02-05 17:50:15 +00:00

3.1 KiB

Quick Log Reference

When something fails, use these commands to quickly check logs.

🚀 Quick Commands

Check All Services for Errors

./scripts/check-logs.sh

Shows PM2 status and recent errors from all services.

Follow Errors in Real-Time

./scripts/tail-errors.sh

Watches all error logs live (press Ctrl+C to exit).

View Recent Errors (Last 10 minutes)

./scripts/view-recent-errors.sh

View Errors from Last 30 minutes

./scripts/view-recent-errors.sh 30

📋 PM2 Commands

# 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):

# Add to crontab: cleanup logs weekly (Sundays at 2 AM)
0 2 * * 0 /opt/punimtag/scripts/cleanup-click-logs.sh

🔧 Direct Log Access

# 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:

./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?

    ./scripts/check-logs.sh
    pm2 logs punimtag-worker --err --lines 100
    
  2. API not responding?

    pm2 logs punimtag-api --err
    pm2 status
    
  3. Large log files?

    # 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?

    # PM2 can manage this with rotation, but if needed:
    pm2 flush  # Clear all logs (be careful!)
    
  5. Viewing click logs?

    # 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