feat(core): add debug exception processor
I would expect the framework to log exceptions using the logger I set up in the config.
I always log everything to php://stdout and I don't want to keep track of some log path during development. This is especially useful in docker.
I decided to go with using get(Logger::class) instead of injecting it, as I thought that this should be a bit safer if framework fails at some really early stage? I'm not sure, I would be happy to be corrected if that's not the case.
Hmm, we actually need to make this more configurable, because outside of Docker, the current approach is super useful. (it writes debug-styled log entries into a file, which can be tailed with
tempest tail)Of course, your approach is also useful in other cases. @innocenzi how do you envision we make this part configurable? We could have two implementations of log processors, but then what? How do we pick the right one?
Maybe these should be two different processors: LogExceptionProcessor and DebugExceptionProcessor.
Agree. I'm only not sure how we decide between the two. Enzo is working on exception handling, so I want to check whether he already had a plan for this. Probably by adding entires in AppConfig, but I wanna make sure :)
Having two exception processors by default seems fine to me. FYI, I plan on improving the logging as well, I'd like to implement a web-based Ray-like UI in addition to a console server for debugging, @brendt, so the tail-based implementation we have might be less useful in the future. (this is blocked by the command bus only having a sync transport)
In the meantime, I agree with having two different processors. I'm not a fan of having a specific configuration for them though, and I'd recommend using the kernel boot event to configure them as needed:
use Tempest\Core\AppConfig;
use Tempest\Core\KernelEvent;
use Tempest\Core\LogExceptionProcessor;
use Tempest\EventBus\EventHandler;
use Tempest\Support\Arr;
final class ConfigureExceptionProcessors
{
public function __construct(
private AppConfig $appConfig,
) {
}
#[EventHandler(KernelEvent::BOOTED)]
public function __invoke()
{
Arr\forget_values($this->appConfig->exceptionProcessors, LogExceptionProcessor::class);
}
}
@aazsamir do you want to implement in this PR or do you want me to do it?
I reverted previous processor, just named it differently. Now exception is both logged by configured logger and put in debug log.
I think I'm not sure about this configuring processors by config or another service? So I'm leaving it as is.
Should one of them be off by default?
By the way, it's sage to inject the logger. The constructor is called right before the process method anyway.
Also, it'd be great to add the context from HasContext to the LogExceptionProcessor as well.
This pull request is stale because it has been open for 30 days with no activity.
I'm working on an improved debug experience in Tempest, so this will no longer be necessary