1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 08:30:07 +01:00
James Furey
2019-04-12 13:11:47 +10:00
parent 44ab8354c7
commit cb1136e7a6

View File

@@ -291,7 +291,7 @@
]);
/**
* Tail log files.
* Tail log file.
*/
$app->command('logs [-f|--follow] [-l|--lines=] [key]', function ($follow, $lines, $key = null) {
$defaultLogs = [
@@ -304,46 +304,60 @@
];
$configLogs = data_get(Configuration::read(), 'logs');
if (!is_array($configLogs)) $configLogs = [];
if (! is_array($configLogs)) {
$configLogs = [];
}
$logs = collect(array_merge($defaultLogs, $configLogs))->sortKeys();
if (! $key) {
info(implode(PHP_EOL, [
'Here are the logs you might be interested in.',
null,
'In order to tail a log, pass the relevant log key (e.g. "php")',
'In order to tail a log, pass the relevant log key (e.g. "nginx")',
'along with any optional tail parameters (e.g. "-f" for follow).',
null,
'For example: "valet logs php -f --lines=3"',
'For example: "valet logs nginx -f --lines=3"',
null,
'Here are the logs you might be interested in.',
null,
]));
table(
['Keys', 'Files'],
collect($logs)->map(function ($file, $key) {
return [$key, $file];
})->toArray()
);
info(implode(PHP_EOL, [
null,
'Tip: Set custom logs by adding a "logs" key/file object',
'to your "'.Configuration::path().'" file.',
]));
exit;
}
if (!isset($logs[$key])) return warning('No logs found for ['.$key.'].');
if (! isset($logs[$key])) {
return warning('No logs found for ['.$key.'].');
}
$file = $logs[$key];
if (!file_exists($file)) return warning('Log path ['.$file.'] does not (yet) exist.');
if (! file_exists($file)) {
return warning('Log path ['.$file.'] does not (yet) exist.');
}
$options = [];
if ($follow) $options[] = '-f';
if ((int) $lines) $options[] = '-n '.(int) $lines;
if ($follow) {
$options[] = '-f';
}
if ((int) $lines) {
$options[] = '-n '.(int) $lines;
}
$command = implode(' ', array_merge(['tail'], $options, [$file]));
passthru($command);
})->descriptions('Tail log files');
})->descriptions('Tail log file');
}
/**