Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for disabling shorten Closes #110 #111

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ And what does the `deployment.ini` file contain? **Only the `remote` item is req
; log file (defaults to config file with .log extension)
log = ...

; Show full log in command line (Defaults to no)
; Yes to disable shortening or list any of: http, local, remote, upload, exception
fullCliLog = http exception

; directory for temporary files (defaults to system's temporary directory)
tempDir = /temp/deployment

Expand Down
9 changes: 8 additions & 1 deletion src/Deployment/CliRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function run(): ?int
$this->logger = new Logger($config['log']);
$this->logger->useColors = (bool) $config['colors'];
$this->logger->showProgress = (bool) $config['progress'];
$this->logger->fullCliLog = $config['fullclilog'];

if (!is_dir($tempDir = $config['tempdir'])) {
$this->logger->log("Creating temporary directory $tempDir");
Expand Down Expand Up @@ -185,7 +186,7 @@ private function setupPhp(): void
});

set_exception_handler(function ($e) {
$this->logger->log("Error: {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}\n\n$e", 'red');
$this->logger->log("Error: {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}\n\n$e", 'red', $this->logger->shortenFor('exception'));
exit(1);
});
}
Expand Down Expand Up @@ -249,12 +250,18 @@ private function loadConfig(): ?array

$config = array_change_key_case($config, CASE_LOWER) + [
'log' => preg_replace('#\.\w+$#', '.log', $this->configFile),
'fullclilog' => [],
'tempdir' => sys_get_temp_dir() . '/deployment',
'progress' => true,
'colors' => (PHP_SAPI === 'cli' && ((function_exists('posix_isatty') && posix_isatty(STDOUT))
|| getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== false)),
];
$config['progress'] = $options['--no-progress'] ? false : $config['progress'];
if (is_string($config['fullclilog'])) {
$config['fullclilog'] = $config['fullclilog'] === '1'
? ['*']
: preg_split('/[\s,]+/', $config['fullclilog']);
}
return $config;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Deployment/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private function runJobs(array $jobs): void
}

if ($out != null) { // intentionally ==
$this->logger->log("-> $out", 'gray');
$this->logger->log("-> $out", 'gray', $this->logger->shortenFor($m[1]));
}
if ($err) {
throw new \RuntimeException('Job failed, ' . $err);
Expand Down
29 changes: 27 additions & 2 deletions src/Deployment/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class Logger
/** @var bool */
public $showProgress = true;

/** @var array */
public $fullCliLog = [];

/** @var resource */
private $file;

Expand Down Expand Up @@ -52,11 +55,11 @@ public function __construct(string $file)
}


public function log(string $s, string $color = null, bool $shorten = true): void
public function log(string $s, string $color = null, bool $shorten = null): void
{
fwrite($this->file, $s . "\n");

if ($shorten && preg_match('#^\n?.*#', $s, $m)) {
if (($shorten ?? $this->shortenFor('*')) && preg_match('#^\n?.*#', $s, $m)) {
$s = $m[0];
}
$s .= " \n";
Expand All @@ -78,4 +81,26 @@ public function progress(string $message): void
echo $message, "\x0D";
}
}


/**
* Check if given action should be shortened
*
* @param string $action
* @return bool
*/
public function shortenFor(string $action)
{
$aliases = [
'https' => 'http',
];
if (in_array('*', $this->fullCliLog, true)) {
return false;
}
if (isset($aliases[$action])) {
$action = $aliases[$action];
}
// If action is present in list, return false to disable shortening
return in_array($action, $this->fullCliLog, true) ? false : true;
}
}