1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 16:40:05 +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) { $app->command('logs [-f|--follow] [-l|--lines=] [key]', function ($follow, $lines, $key = null) {
$defaultLogs = [ $defaultLogs = [
@@ -304,46 +304,60 @@
]; ];
$configLogs = data_get(Configuration::read(), 'logs'); $configLogs = data_get(Configuration::read(), 'logs');
if (!is_array($configLogs)) $configLogs = []; if (! is_array($configLogs)) {
$configLogs = [];
}
$logs = collect(array_merge($defaultLogs, $configLogs))->sortKeys(); $logs = collect(array_merge($defaultLogs, $configLogs))->sortKeys();
if (! $key) { if (! $key) {
info(implode(PHP_EOL, [ info(implode(PHP_EOL, [
'Here are the logs you might be interested in.', 'In order to tail a log, pass the relevant log key (e.g. "nginx")',
null,
'In order to tail a log, pass the relevant log key (e.g. "php")',
'along with any optional tail parameters (e.g. "-f" for follow).', 'along with any optional tail parameters (e.g. "-f" for follow).',
null, 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, null,
])); ]));
table( table(
['Keys', 'Files'], ['Keys', 'Files'],
collect($logs)->map(function ($file, $key) { collect($logs)->map(function ($file, $key) {
return [$key, $file]; return [$key, $file];
})->toArray() })->toArray()
); );
info(implode(PHP_EOL, [ info(implode(PHP_EOL, [
null, null,
'Tip: Set custom logs by adding a "logs" key/file object', 'Tip: Set custom logs by adding a "logs" key/file object',
'to your "'.Configuration::path().'" file.', 'to your "'.Configuration::path().'" file.',
])); ]));
exit; 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]; $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 = []; $options = [];
if ($follow) $options[] = '-f'; if ($follow) {
if ((int) $lines) $options[] = '-n '.(int) $lines; $options[] = '-f';
}
if ((int) $lines) {
$options[] = '-n '.(int) $lines;
}
$command = implode(' ', array_merge(['tail'], $options, [$file])); $command = implode(' ', array_merge(['tail'], $options, [$file]));
passthru($command); passthru($command);
})->descriptions('Tail log files'); })->descriptions('Tail log file');
} }
/** /**