TraceFlow is a unified logging helper that routes messages to the right destination based on where your code runs — workflow database logs, console output, or Laravel’s log files.
Usage
Use the traceflow() helper anywhere in your application:
traceflow()->info('Processing started');
traceflow()->success('Operation completed');
traceflow()->warn('Rate limit approaching');
traceflow()->error('Something went wrong', $exception);
All methods accept an optional context array:
traceflow()->info('Processing order', ['order_id' => $order->id]);
Methods
| Method | Description |
|---|
info(string $message, ?array $context) | Informational message |
success(string $message, ?array $context) | Success message |
warn(string $message, ?array $context) | Warning message |
error(string $message, ?Throwable $exception) | Error with optional exception |
throw(string $message, Throwable $exception) | Log error and re-throw the exception |
raw(mixed $message) | Log raw data without formatting |
incrementProcessedCount(int $amount = 1) | Advance processed count or progress bar |
incrementFailureCount() | Increment failure count |
Routing Targets
TraceFlow automatically detects the execution context and routes accordingly:
| Context | Target | Behaviour |
|---|
Workflow | Database | Stored in traceflow_logs, linked to workflow |
Activity | Database | Stored in traceflow_logs, linked to parent workflow |
BaseCommand | Console | Output to terminal; incrementProcessedCount() advances the progress bar |
| Anywhere else | Log file | Written to storage/logs/laravel.log |
In commands with an active progress bar, info() messages appear as hints beneath it rather than new lines.
Progress Tracking
Call incrementProcessedCount() inside loops to track progress. In commands, this advances the progress bar set up with $this->setTotalCount(). In workflows and activities, it updates processed_count on the workflow record.
foreach ($items as $item) {
$this->processItem($item);
traceflow()->incrementProcessedCount();
}
Configuration
The default fallback target is set in config/core.php:
'traceflow' => [
'default_target' => \Inly\Core\Services\Traceflow\Targets\LogTarget::class,
],