Skip to content

Latest commit

 

History

History
216 lines (162 loc) · 8.15 KB

File metadata and controls

216 lines (162 loc) · 8.15 KB

Prolog Server Debug Logging Guide

Overview

Comprehensive debug logging has been added to track whether the Prolog server is running the scheduling algorithms or if the system is falling back to C# implementations.

Debug Log Markers

All debug logs related to Prolog scheduling use specific prefixes for easy filtering:

  • [SCHEDULER-DEBUG] - BackendService SchedulingService logs
  • [PROLOG-IMPL] - PrologSchedulerImpl initialization and setup
  • [PROLOG-EXEC] - Actual Prolog execution (calls to HTTP service)
  • [PROLOG-SUCCESS] - Successful Prolog execution
  • [PROLOG-WARNING] - Prolog warnings (no results, invalid format)
  • [PROLOG-FALLBACK] - Fallback to C# implementation
    • [PROLOG-FALLBACK-EDT] - EDT algorithm fallback
    • [PROLOG-FALLBACK-GENETIC] - Genetic algorithm fallback
    • [PROLOG-FALLBACK-GREEDY] - Greedy heuristic fallback
  • [OEM-SCHEDULING] - OEMService scheduling calls
  • [OEM-SCHEDULING-ERROR] - OEMService error handling
  • [OPERATION-PLAN] - Operation plan generation tracking

Execution Flow & Log Points

1. Operation Plan Generation (OEMService)

OperationPlanService.GenerateAsync()
  └─> [OPERATION-PLAN] SchedulingServiceClient called with date and algorithm
      └─> SchedulingServiceClient.GenerateDailyScheduleAsync()
          └─> [OEM-SCHEDULING] HTTP request to BackendService

2. Backend Scheduling Service (BackendService)

SchedulingService.ComputeDailyScheduleAsync()
  └─> [SCHEDULER-DEBUG] Service entry point
      - Scheduler Implementation type (PrologSchedulerImpl)
      - Resource counts (visits, docks, cranes, staff, storage)
      - Algorithm requested
      └─> PrologScheduler.ComputeDailySchedule()
          └─> [PROLOG-IMPL] Implementation initialization
              - Resource availability checks
              - Job mapping
              └─> ComputeSequenceAsync()
                  └─> [PROLOG-EXEC] Prolog execution attempt
                      - Algorithm and vessel count
                      - Prolog program size
                      - Goal being executed
                      
                      ✓ SUCCESS:
                      └─> [PROLOG-SUCCESS] JSON response parsed
                          └─> Return scheduled operations
                      
                      ✗ FAILURE:
                      └─> [PROLOG-FALLBACK] Exception caught
                          ├─> [PROLOG-FALLBACK-EDT] EDT algorithm fallback
                          ├─> [PROLOG-FALLBACK-GENETIC] Genetic fallback
                          └─> [PROLOG-FALLBACK-GREEDY] Greedy fallback
                              └─> Return C# computed schedule

Interpreting the Logs

Success Path (Prolog Running)

[PROLOG-EXEC] Starting Prolog computation. Algorithm: minimize-delay, Vessels: 3, Cranes: 2
[PROLOG-EXEC] Calling Prolog with goal: run_scheduler. Program length: 1245 chars
[PROLOG-EXEC] Prolog query returned 1 solutions
[PROLOG-SUCCESS] Successfully parsed Prolog JSON response
[SCHEDULER-DEBUG] ComputeDailyScheduleAsync completed. Algorithm Used: prolog:minimize-delay...

Fallback Path (Using C#)

[PROLOG-EXEC] Starting Prolog computation. Algorithm: minimize-delay, Vessels: 2, Cranes: 1
[PROLOG-EXEC] Calling Prolog with goal: run_scheduler. Program length: 890 chars
[PROLOG-FALLBACK] Prolog scheduler error, falling back to Greedy heuristic
[PROLOG-FALLBACK-GREEDY] Using Greedy heuristic fallback for minimize-delay
[SCHEDULER-DEBUG] ComputeDailyScheduleAsync completed. Algorithm Used: prolog:minimize-delay...

Key Indicators

Algorithm Field in Response

The algorithm field returned in the schedule response indicates:

  • prolog:minimize-delay - Prolog minimize-delay algorithm was used
  • prolog:edt - Prolog Early Departure Time algorithm was used
  • prolog:genetic - Prolog Genetic algorithm was used
  • prolog-stub:* - C# stub was used (if registered instead of impl)

Log Analysis Checklist

When investigating scheduling issues:

  1. Is Prolog executing?

    • Look for [PROLOG-EXEC] logs
    • Check if [PROLOG-SUCCESS] appears after execution
    • If you see [PROLOG-FALLBACK], Prolog failed
  2. What error occurred?

    • Check the exception message in [PROLOG-FALLBACK] logs
    • Review [PROLOG-WARNING] for JSON parsing issues
    • Look for HTTP connection errors in [OEM-SCHEDULING-ERROR]
  3. Resource availability

    • Check [PROLOG-IMPL] logs for resource warnings
    • Verify vessel counts match expected data
    • Confirm all dependencies available (docks, cranes, staff, storage)
  4. Performance metrics

    • Note the Prolog program size (Program length)
    • Track execution time between [PROLOG-EXEC] start and result
    • Compare algorithm used vs requested

Enabling Debug Logs

In appsettings.json (Backend)

{
  "Logging": {
    "LogLevel": {
      "PortLogistics.Application.Backend.Domain.Scheduling.SchedulingService": "Information",
      "PortLogistics.Application.Backend.Infrastructure.Scheduling.PrologSchedulerImpl": "Information",
      "Default": "Information"
    }
  }
}

In appsettings.json (OEMService)

{
  "Logging": {
    "LogLevel": {
      "OEMService.Services.SchedulingServiceClient": "Information",
      "OEMService.Domain.OperationPlans.OperationPlanService": "Information",
      "Default": "Information"
    }
  }
}

Example Log Output

Complete execution trace with all logs:

[OPERATION-PLAN] Schedule received from backend. Algorithm: prolog:minimize-delay, Feasible: true, Operations: 5, TotalDelay: 120

[SCHEDULER-DEBUG] ComputeDailyScheduleAsync completed. Algorithm Used: prolog:minimize-delay, Feasible: true, Operations Scheduled: 5, Total Delay Minutes: 120, Warnings: 0

[PROLOG-SUCCESS] Successfully parsed Prolog JSON response

[PROLOG-EXEC] Prolog query returned 1 solutions

[PROLOG-EXEC] Calling Prolog with goal: run_scheduler. Program length: 2156 chars

[PROLOG-EXEC] Starting Prolog computation. Algorithm: minimize-delay, Vessels: 5, Cranes: 3

[PROLOG-IMPL] ComputeDailySchedule completed. Schedule generated with 5 scheduled operations

[PROLOG-IMPL] ComputeDailyScheduleAsync called. Scheduler Implementation: PrologSchedulerImpl, TargetDate: 2025-12-31, Algorithm: minimize-delay, Active Visits: 5, Docks: 2, Cranes: 3, Staff: 4, Storage Areas: 2

[SCHEDULER-DEBUG] ComputeDailyScheduleAsync called. Scheduler Implementation: PrologSchedulerImpl, TargetDate: 2025-12-31, Algorithm: minimize-delay, Active Visits: 5, Docks: 2, Cranes: 3, Staff: 4, Storage Areas: 2

[OEM-SCHEDULING] Successfully received daily schedule. Algorithm: prolog:minimize-delay, Operations: 5, Feasible: true, TotalDelay: 120 minutes

[OEM-SCHEDULING] BackendService responded with status 200

[OEM-SCHEDULING] Calling BackendService to generate daily schedule. TargetDate: 2025-12-31, Algorithm: minimize-delay

Troubleshooting

Prolog server not responding

  • Look for HTTP exceptions in [OEM-SCHEDULING-ERROR] or [PROLOG-EXEC]
  • Check Prolog service logs for errors
  • Verify network connectivity: docker logs prolog

Always falling back to C#

  • Check if Prolog service is running
  • Verify Prolog configuration in appsettings (Base URL, port)
  • Review exception messages in [PROLOG-FALLBACK] logs
  • Check Prolog program syntax in logs

Inconsistent algorithms returned

  • Verify request algorithm parameter matches what's logged
  • Check if algorithm is supported by Prolog service
  • Review [SCHEDULER-DEBUG] for which scheduler implementation is registered

Related Files Modified

  • Application/BackendService/Domain/Scheduling/SchedulingService.cs
  • Application/BackendService/Infrastructure/Scheduling/PrologSchedulerImpl.cs
  • Application/OEMService/Services/SchedulingServiceClient.cs
  • Application/OEMService/Domain/OperationPlans/OperationPlanService.cs

Configuration

To switch between real Prolog and C# stub, modify Startup.cs:

// For real Prolog:
services.AddSingleton<IPrologScheduler, PrologSchedulerImpl>();

// For C# stub (testing without Prolog service):
services.AddSingleton<IPrologScheduler, PrologSchedulerStub>();

Currently registered: PrologSchedulerImpl (real Prolog)