Skip to content

Commit

Permalink
Log unhandled Exceptions into logfile (#1482)
Browse files Browse the repository at this point in the history
* log symfony-console handled exceptions into logfile

* log early bootstrap exceptions into logfile

* updated CHANGELOG.md

* fixed CS

* try to fix php warning

Declaration of Deployer\Console\Application::renderException(Exception $e, Symfony\Component\Console\Output\OutputInterface $output) should be compatible with Symfony\Component\Console\Application::renderException($e, $output)

* log in TaskCommand instead of Application, to prevent x-symfony-console version issues
  • Loading branch information
staabm authored and antonmedv committed Apr 18, 2018
1 parent 373d7e4 commit 8d6740e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Added
- Added a description to the autocomplete command [#1472]
- Log unhandled exceptions into logfile [#1481]

### Fixed
- fix within() to also restore the working-path when the given callback throws a Exception [#1463]
Expand All @@ -22,7 +23,7 @@
### Changed
- Added support for GroupTask in invoke() [#1364]
- Magento2 recipe optimizes the autoloader after the DI compilation [#1365]
- Host's `roles()` API now can accept arrays too
- Host's `roles()` API now can accept arrays too
- Fixed bug where wrong time format is passed to touch when deploying assets [#1390]
- Added artisan:migrate:fresh task for laravel recipe
- Added platform config to composer.json [#1426]
Expand All @@ -39,7 +40,7 @@
### Changed
- Laravel version check defaults to 5.5 if not found [#1352]

### Fixed
### Fixed
- Updated Laravel recipe to not run `artisan:optimize` on Laravel >= 5.5, as that command is now deprecated ([see upgrade notes](https://laravel.com/docs/5.5/upgrade)) [#1352]


Expand Down Expand Up @@ -341,6 +342,7 @@
- Fixed typo3 recipe
- Fixed remove of shared dir on first deploy

[#1481]: https://github.com/deployphp/deployer/issues/1481
[#1472]: https://github.com/deployphp/deployer/pull/1472
[#1463]: https://github.com/deployphp/deployer/pull/1463
[#1455]: https://github.com/deployphp/deployer/pull/1455
Expand Down
1 change: 1 addition & 0 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Deployer\Component\PharUpdate\Console\Command as PharUpdateCommand;
use Deployer\Component\PharUpdate\Console\Helper as PharUpdateHelper;
use Deployer\Deployer;
use Symfony\Component\Console\Application as Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;
Expand Down
3 changes: 3 additions & 0 deletions src/Console/TaskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ protected function execute(Input $input, Output $output)
try {
$executor->run($tasks, $hosts);
} catch (\Throwable $exception) {
$this->deployer->logger->log('['. get_class($exception) .'] '. $exception->getMessage());
$this->deployer->logger->log($exception->getTraceAsString());

if ($exception instanceof GracefulShutdownException) {
throw $exception;
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,13 @@ public static function run($version, $deployFile)
$deployer = new self($console);

// Pretty-print uncaught exceptions in symfony-console
set_exception_handler(function ($e) use ($input, $output) {
set_exception_handler(function ($e) use ($input, $output, $deployer) {
$io = new SymfonyStyle($input, $output);
$io->block($e->getMessage(), get_class($e), 'fg=white;bg=red', ' ', true);
$io->block($e->getTraceAsString());

$deployer->logger->log('['. get_class($e) .'] '. $e->getMessage());
$deployer->logger->log($e->getTraceAsString());
exit(1);
});

Expand Down

0 comments on commit 8d6740e

Please sign in to comment.