# Curl Commands Log File

## Overview

All curl commands sent to createMenu.php are:
1. **Printed to console** (with formatting)
2. **Written to `logs/curl_commands.log`** (plain text, easy to copy)
3. **Logged to `logs/app.log`** (JSON format)

---

## Log File: `logs/curl_commands.log`

### Location
```
logs/curl_commands.log
```

### Format

Each curl command is logged with metadata and the full command:

```
================================================================================
Timestamp: 2025-12-10T14:23:48.123456
Request ID: 550e8400-e29b-41d4-a716-446655440000
Attempt: 1/3
City: sofia
================================================================================
curl --location 'https://zavedenia.com/apps/orderapprestaurant/api/createMenu.php' \
--header 'Content-Type: application/json' \
--data '{"city":"sofia","token":"8800a3a64cfa947c552391f48069cacd","menu":[...]}'
================================================================================

================================================================================
Timestamp: 2025-12-10T14:25:12.234567
Request ID: 660f9511-f39c-52e5-b827-557766551111
Attempt: 1/3
City: plovdiv
================================================================================
curl --location 'https://zavedenia.com/apps/orderapprestaurant/api/createMenu.php' \
--header 'Content-Type: application/json' \
--data '{"city":"plovdiv","token":"8800a3a64cfa947c552391f48069cacd","menu":[...]}'
================================================================================
```

---

## How to Use

### 1. View Recent Curl Commands

```bash
# View last 50 lines
./view_curl_log.sh

# View last 100 lines
./view_curl_log.sh 100

# Or use tail directly
tail -f logs/curl_commands.log
```

### 2. Extract Specific Curl Command

```bash
# List recent request IDs
./extract_curl_from_logs.sh

# Extract curl for specific request
./extract_curl_from_logs.sh 550e8400-e29b-41d4-a716-446655440000

# This creates an executable script
./curl_command_550e8400-e29b-41d4-a716-446655440000.sh
```

### 3. Copy Curl Command Manually

```bash
# Open the log file
cat logs/curl_commands.log

# Or view in editor
nano logs/curl_commands.log
vim logs/curl_commands.log

# Copy the curl command and run it
```

### 4. Search by City or Request ID

```bash
# Find all curls for sofia
grep -A 5 "City: sofia" logs/curl_commands.log

# Find curl for specific request ID
grep -A 5 "550e8400-e29b-41d4-a716-446655440000" logs/curl_commands.log

# Show just the curl commands (no metadata)
grep "^curl --location" logs/curl_commands.log
```

---

## Example Log Entry

```
================================================================================
Timestamp: 2025-12-10T14:23:48.123456
Request ID: 550e8400-e29b-41d4-a716-446655440000
Attempt: 1/3
City: sofia
================================================================================
curl --location 'https://zavedenia.com/apps/orderapprestaurant/api/createMenu.php' \
--header 'Content-Type: application/json' \
--data '{
  "city": "sofia",
  "token": "8800a3a64cfa947c552391f48069cacd",
  "menu": [
    {
      "name": "Salads",
      "name_uk": "Salads",
      "description": "Fresh salads",
      "description_uk": "Fresh salads",
      "items": [
        {
          "name": "Caesar Salad",
          "name_uk": "Caesar Salad",
          "description": "Classic Caesar",
          "description_uk": "Classic Caesar",
          "measure": 1,
          "items": [
            {
              "name": "Стандартна порция",
              "gramaj": 250,
              "cena": 15.0
            }
          ]
        }
      ]
    }
  ]
}'
================================================================================
```

---

## Console vs Log File

### Console Output
```
================================================================================
EQUIVALENT CURL COMMAND FOR createMenu.php
================================================================================
Request ID: 550e8400-e29b-41d4-a716-446655440000
Attempt: 1/3

You can run this command manually to test:

curl --location 'https://zavedenia.com/...' \
--header 'Content-Type: application/json' \
--data '{...}'

================================================================================
```

### Log File (`logs/curl_commands.log`)
```
================================================================================
Timestamp: 2025-12-10T14:23:48.123456
Request ID: 550e8400-e29b-41d4-a716-446655440000
Attempt: 1/3
City: sofia
================================================================================
curl --location 'https://zavedenia.com/...' \
--header 'Content-Type: application/json' \
--data '{...}'
================================================================================
```

### App Log (`logs/app.log`)
```json
{
  "timestamp": "2025-12-10T14:23:48.123456",
  "level": "INFO",
  "event": "CREATE_MENU_CURL_COMMAND",
  "request_id": "550e8400-e29b-41d4-a716-446655440000",
  "curl_command": "curl --location '...' --header '...' --data '{...}'",
  "curl_log_file": "logs/curl_commands.log"
}
```

---

## Log Rotation

The `logs/curl_commands.log` file will grow over time. You can:

### Manual Cleanup
```bash
# Backup old curls
cp logs/curl_commands.log logs/curl_commands_backup_$(date +%Y%m%d).log

# Clear the file
> logs/curl_commands.log
```

### Keep Last N Entries
```bash
# Keep only last 100 curl commands
tail -n 2000 logs/curl_commands.log > logs/curl_commands.tmp
mv logs/curl_commands.tmp logs/curl_commands.log
```

### Archive by Date
```bash
# Archive monthly
mv logs/curl_commands.log logs/curl_commands_$(date +%Y_%m).log
touch logs/curl_commands.log
```

---

## Quick Reference

### View Commands
```bash
./view_curl_log.sh              # View last 50 lines
tail -f logs/curl_commands.log  # Follow in real-time
cat logs/curl_commands.log      # View entire file
```

### Extract Commands
```bash
./extract_curl_from_logs.sh                              # List recent
./extract_curl_from_logs.sh 550e8400-e29b-41d4-a716...  # Extract specific
```

### Search Commands
```bash
grep "sofia" logs/curl_commands.log           # Find by city
grep "550e8400" logs/curl_commands.log        # Find by request ID
grep -c "^curl" logs/curl_commands.log        # Count total commands
```

### Run Commands
```bash
# Copy from log and run directly
curl --location 'https://...' --data '{...}'

# Or use extracted script
./curl_command_550e8400-e29b-41d4-a716-446655440000.sh
```

---

## Summary

✅ **Console**: Pretty formatted output during execution
✅ **logs/curl_commands.log**: Plain text, easy to copy and search
✅ **logs/app.log**: Structured JSON for programmatic access
✅ **Helper scripts**: Extract and run curls easily
✅ **Searchable**: Find curls by request ID, city, timestamp
✅ **Executable**: Create runnable scripts from logs

All curl commands are now logged in three places for maximum convenience! 🎉
