# error_log() to ordio_log() Migration Plan


**Last Updated:** 2025-11-20

**Date:** 2025-11-17  
**Status:** ✅ **COMPLETED** (API Endpoints Phase)

## Overview

Systematic migration of 880+ `error_log()` calls across 16 API endpoint files to structured `ordio_log()` calls with appropriate log levels.

**Completion Date:** 2025-11-17  
**Files Migrated:** 16/16 API endpoints  
**Calls Migrated:** 880+  
**Remaining:** Config/Helper files (low priority, ~30 calls)

## File Inventory

### High Priority (API Endpoints - 10 files, ~500 calls)

1. `v2/api/shiftops.php` - 233 calls
2. `v2/api/lead-capture.php` - 173 calls
3. `v2/api/generate_excel.php` - 71 calls
4. `v2/api/shiftops-recommendations-engine.php` - 43 calls
5. `v2/api/shiftops-hubspot.php` - 34 calls
6. `v2/api/addon-request.php` - 29 calls
7. `v2/api/submit-template.php` - 28 calls
8. `v2/api/export-workdays.php` - 27 calls
9. `v2/api/webinar-registration.php` - 16 calls
10. `v2/api/payroll-webinar-registration.php` - 20 calls
11. `v2/api/collect-lead.php` - 8 calls
12. `v2/api/shiftops-nps.php` - 2 calls

### Medium Priority (ShiftOps API - 4 files, ~180 calls)

13. `v2/api/shiftops-customer-matcher.php` - 126 calls
14. `v2/api/shiftops-competitive-analyzer.php` - 7 calls
15. `v2/api/shiftops-hubspot-customers.php` - 13 calls
16. `v2/api/shiftops-cost-calculator.php` - 1 call

### Low Priority (Config/Helpers - 6 files, ~30 calls)

17. `v2/config/hubspot-api-helpers.php` - 6 calls
18. `v2/config/utm-validation.php` - 7 calls
19. `v2/config/hubspot.php` - 9 calls
20. `v2/config/hubspot-config.php` - 3 calls
21. `v2/config/google-maps.php` - 3 calls
22. `v2/config/shiftops-customers.php` - 2 calls
23. `v2/helpers/hubspot-context.php` - 4 calls
24. `v2/helpers/logger.php` - 3 calls (fallback only)

### Excluded Files

- `v2/PHPMailer/` - Third-party library
- `v2/vendor/` - Third-party libraries
- `v2/auth/callback.php` - 1 call (low priority)
- `v2/base/` - 2 calls (low priority)

## Log Level Mapping Strategy

### DEBUG Level

- Debugging information
- Detailed flow tracking
- UTM parameter processing details
- Attribution logic decisions

### INFO Level

- Normal operations
- Successful API calls
- Request processing
- General flow information

### WARN Level

- Validation failures
- Rate limit warnings
- Non-critical errors
- Unexpected but handled conditions

### ERROR Level

- API call failures
- Processing errors
- Critical business logic failures
- Exception handling

### CRITICAL Level

- System failures
- Configuration errors
- Fatal errors
- Security issues

## Migration Patterns

### Pattern 1: Simple String Messages

```php
// Before
error_log("Message here");

// After
ordio_log('INFO', 'Message here');
```

### Pattern 2: Messages with Variables

```php
// Before
error_log("Variable value: $variable");

// After
ordio_log('INFO', 'Variable value', ['variable' => $variable]);
```

### Pattern 3: Error Messages

```php
// Before
error_log("Error occurred: " . $error);

// After
ordio_log('ERROR', 'Error occurred', ['error' => $error]);
```

### Pattern 4: Debug Messages

```php
// Before
error_log("Debug: Processing step X");

// After
ordio_log('DEBUG', 'Processing step X');
```

### Pattern 5: Warning Messages

```php
// Before
error_log("WARNING: Something unexpected");

// After
ordio_log('WARN', 'Something unexpected');
```

## Migration Order

1. **Phase 1**: API Endpoints (12 files, ~500 calls)

   - Start with smaller files first (build confidence)
   - Then tackle larger files
   - Test after each file

2. **Phase 2**: ShiftOps API (4 files, ~180 calls)

   - Similar patterns to API endpoints
   - Can reuse migration patterns

3. **Phase 3**: Config/Helpers (6 files, ~30 calls)
   - Lower volume, easier to complete
   - Critical infrastructure files

## Testing Strategy

- Syntax check after each file
- Verify log output format
- Check log levels are appropriate
- Ensure no information loss
- Test error scenarios

## Progress Tracking

- [x] **Phase 1: API Endpoints** ✅ **COMPLETED**

  - [x] collect-lead.php (12 calls) ✅
  - [x] shiftops-nps.php (8 calls) ✅
  - [x] payroll-webinar-registration.php (16 calls) ✅
  - [x] webinar-registration.php (12 calls) ✅
  - [x] export-workdays.php (4 calls) ✅
  - [x] submit-template.php (6 calls) ✅
  - [x] addon-request.php (5 calls) ✅
  - [x] shiftops-hubspot.php (34 calls) ✅
  - [x] shiftops-recommendations-engine.php (43 calls) ✅
  - [x] generate_excel.php (71 calls) ✅
  - [x] lead-capture.php (173 calls) ✅
  - [x] shiftops.php (233 calls) ✅

- [x] **Phase 2: ShiftOps API** ✅ **COMPLETED**

  - [x] shiftops-cost-calculator.php (1 call) ✅
  - [x] shiftops-competitive-analyzer.php (5 calls) ✅
  - [x] shiftops-hubspot-customers.php (3 calls) ✅
  - [x] shiftops-customer-matcher.php (126 calls) ✅

- [ ] Phase 3: Config/Helpers
  - [ ] hubspot-config.php (3 calls)
  - [ ] google-maps.php (3 calls)
  - [ ] shiftops-customers.php (2 calls)
  - [ ] utm-validation.php (7 calls)
  - [ ] hubspot.php (9 calls)
  - [ ] hubspot-api-helpers.php (6 calls)
  - [ ] hubspot-context.php (4 calls)
  - [ ] logger.php (3 calls - fallback only)
