From 7244468445be22ab4df909c5e5d0405eaf48a5cf Mon Sep 17 00:00:00 2001 From: James Furey Date: Thu, 4 Apr 2019 14:45:11 +1100 Subject: [PATCH 1/6] Added "logs" command (with optional "follow" and "lines" flags), defaulting to Valet's "/log/nginx-error.log" file if no "logs.[file]" configuration value is found in Valet's "config.json" file. --- cli/valet.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cli/valet.php b/cli/valet.php index e82bd81..9dd9851 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -289,6 +289,28 @@ })->descriptions('Change the version of php used by valet', [ 'phpVersion' => 'The PHP version you want to use, e.g php@7.2', ]); + + /** + * Tail log file. + */ + $app->command('logs [-f|--follow] [--lines=] [file]', function ($follow, $lines, $file = null) { + $defaultLogFile = VALET_HOME_PATH.'/Log/nginx-error.log'; + + $logFile = data_get(Configuration::read(), "logs.$file", $defaultLogFile); + + $options = []; + + if ($follow) $options[] = '-f'; + + if ((int) $lines) { + $options[] = '-n'; + $options[] = (int) $lines; + } + + $logCommand = implode(' ', array_merge(['tail'], $options, [$logFile])); + + passthru($logCommand); + })->descriptions('Tail log file'); } /** From b7633422b15a1bd62a5c0f607e75d1cffcbc4e52 Mon Sep 17 00:00:00 2001 From: James Furey Date: Tue, 9 Apr 2019 15:45:16 +1000 Subject: [PATCH 2/6] Added default logs array. Sorting merged default/config logs array. Added key/files table and guided info when no key is passed. Added warnings when accessing non-existent key/files. --- cli/valet.php | 59 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/cli/valet.php b/cli/valet.php index 9dd9851..e8808f6 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -291,26 +291,59 @@ ]); /** - * Tail log file. + * Tail log files. */ - $app->command('logs [-f|--follow] [--lines=] [file]', function ($follow, $lines, $file = null) { - $defaultLogFile = VALET_HOME_PATH.'/Log/nginx-error.log'; + $app->command('logs [-f|--follow] [-l|--lines=] [key]', function ($follow, $lines, $key = null) { + $defaultLogs = [ + 'php' => VALET_HOME_PATH.'/Log/php.log', + 'php-fpm' => '/usr/local/var/log/php-fpm.log', + 'nginx' => VALET_HOME_PATH.'/Log/nginx-error.log', + 'mysql' => VALET_HOME_PATH.'/Log/mysql.log', + 'mailhog' => '/usr/local/var/log/mailhog.log', + 'redis' => '/usr/local/var/log/redis.log', + ]; - $logFile = data_get(Configuration::read(), "logs.$file", $defaultLogFile); + $configLogs = data_get(Configuration::read(), 'logs'); + if (!is_array($configLogs)) $configLogs = []; - $options = []; - - if ($follow) $options[] = '-f'; + $logs = collect(array_merge($defaultLogs, $configLogs))->sortKeys(); - if ((int) $lines) { - $options[] = '-n'; - $options[] = (int) $lines; + 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")', + 'along with any optional tail parameters (e.g. "-f" for follow).', + null, + 'For example: "valet logs php -f --lines=3"', + 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; } - $logCommand = implode(' ', array_merge(['tail'], $options, [$logFile])); + if (!isset($logs[$key])) return warning('No logs found for ['.$key.'].'); - passthru($logCommand); - })->descriptions('Tail log file'); + $file = $logs[$key]; + 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; + + $command = implode(' ', array_merge(['tail'], $options, [$file])); + passthru($command); + })->descriptions('Tail log files'); } /** From 44ab8354c79b84ffb4130349c740e10d2feaa52d Mon Sep 17 00:00:00 2001 From: James Furey Date: Thu, 11 Apr 2019 11:48:23 +1000 Subject: [PATCH 3/6] Empty commit to restart Travis CI build. From cb1136e7a616b9c0231e99f95d23beb5686b0a0c Mon Sep 17 00:00:00 2001 From: James Furey Date: Fri, 12 Apr 2019 13:11:47 +1000 Subject: [PATCH 4/6] Resolutions to the following change requests: - https://github.com/laravel/valet/pull/757#discussion_r274547618 - https://github.com/laravel/valet/pull/757#discussion_r274549378 - https://github.com/laravel/valet/pull/757#discussion_r274549637 - https://github.com/laravel/valet/pull/757#discussion_r274549735 - https://github.com/laravel/valet/pull/757#discussion_r274550184 - https://github.com/laravel/valet/pull/757#discussion_r274550266 - https://github.com/laravel/valet/pull/757#discussion_r274550513 - https://github.com/laravel/valet/pull/757#discussion_r274550683 - https://github.com/laravel/valet/pull/757#discussion_r274550831 - https://github.com/laravel/valet/pull/757#discussion_r274550915 - https://github.com/laravel/valet/pull/757#discussion_r274551027 --- cli/valet.php | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/cli/valet.php b/cli/valet.php index e8808f6..1093cba 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -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) { + 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'); } /** From 12ca66ade13597c1a8bcc6f485e5a91a6e3fdc7a Mon Sep 17 00:00:00 2001 From: James Furey Date: Sat, 13 Apr 2019 12:31:36 +1000 Subject: [PATCH 5/6] Changed "logs" command name to "log". --- cli/valet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/valet.php b/cli/valet.php index 1093cba..67dafc2 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -293,7 +293,7 @@ /** * Tail log file. */ - $app->command('logs [-f|--follow] [-l|--lines=] [key]', function ($follow, $lines, $key = null) { + $app->command('log [-f|--follow] [-l|--lines=] [key]', function ($follow, $lines, $key = null) { $defaultLogs = [ 'php' => VALET_HOME_PATH.'/Log/php.log', 'php-fpm' => '/usr/local/var/log/php-fpm.log', From 138df82aa25073301ab962072f25b9c270101a87 Mon Sep 17 00:00:00 2001 From: James Furey Date: Sat, 13 Apr 2019 12:32:57 +1000 Subject: [PATCH 6/6] Removed "php" and "mysql" log key/path values. --- cli/valet.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/valet.php b/cli/valet.php index 67dafc2..32e0ceb 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -295,10 +295,8 @@ */ $app->command('log [-f|--follow] [-l|--lines=] [key]', function ($follow, $lines, $key = null) { $defaultLogs = [ - 'php' => VALET_HOME_PATH.'/Log/php.log', 'php-fpm' => '/usr/local/var/log/php-fpm.log', 'nginx' => VALET_HOME_PATH.'/Log/nginx-error.log', - 'mysql' => VALET_HOME_PATH.'/Log/mysql.log', 'mailhog' => '/usr/local/var/log/mailhog.log', 'redis' => '/usr/local/var/log/redis.log', ];