Laravel has readable log and stacktrace when exception caught, for example:
production.ERROR: Command "test" is not defined.
Did you mean this?
make:test {"exception":"[object] (Symfony\\Component\\Console\\Exception\\CommandNotFoundException(code: 0): Command \"test\" is not defined.
Did you mean this?
make:test at {root}/vendor/symfony/console/Application.php:618)
[stacktrace]
#0 {root}/vendor/symfony/console/Application.php(229): Symfony\\Component\\Console\\Application->find('test')
#1 {root}/vendor/symfony/console/Application.php(148): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#2 {root}/vendor/laravel/framework/src/Illuminate/Console/Application.php(88): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#3 {root}/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#4 {root}/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#5 {main}
"}
The question is: is it possible to catch the exception myself, and log the same format of the stacktrace, and continue the program execution. By far, I am logging the error by Log::error(json_encode(debug_backtrace()));
which is really ugly and hard to trace. The example code:
try {
foo();
} catch(\Exception $e) {
Log::error(json_encode(debug_backtrace()));
}
bar();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With