diff --git a/cli/Valet/Configuration.php b/cli/Valet/Configuration.php index 6b3eee7..7c68b80 100644 --- a/cli/Valet/Configuration.php +++ b/cli/Valet/Configuration.php @@ -27,6 +27,7 @@ function install() $this->createDriversDirectory(); $this->createSitesDirectory(); $this->createExtensionsDirectory(); + $this->createLogDirectory(); $this->writeBaseConfiguration(); $this->files->chown($this->path(), user()); @@ -81,6 +82,18 @@ function createExtensionsDirectory() $this->files->ensureDirExists(VALET_HOME_PATH.'/Extensions', user()); } + /** + * Create the directory for Caddy log. + * + * @return void + */ + function createLogDirectory() + { + $this->files->ensureDirExists(VALET_HOME_PATH.'/Log', user()); + $this->files->touch(VALET_HOME_PATH.'/Log/access.log'); + $this->files->touch(VALET_HOME_PATH.'/Log/error.log'); + } + /** * Write the base, initial configuration for Valet. */ diff --git a/cli/stubs/Caddyfile b/cli/stubs/Caddyfile index 4995ad7..5650dfb 100644 --- a/cli/stubs/Caddyfile +++ b/cli/stubs/Caddyfile @@ -8,4 +8,20 @@ import VALET_HOME_PATH/Caddy/* rewrite { to /server.php?{query} } + + log VALET_HOME_PATH/Log/access.log { + rotate { + size 10 + age 3 + keep 1 + } + } + + errors { + log VALET_HOME_PATH/Log/error.log { + size 10 + age 3 + keep 1 + } + } } diff --git a/cli/stubs/SecureCaddyfile b/cli/stubs/SecureCaddyfile index cbfdff9..b5f176c 100644 --- a/cli/stubs/SecureCaddyfile +++ b/cli/stubs/SecureCaddyfile @@ -12,4 +12,20 @@ https://VALET_SITE:443 { rewrite { to /server.php?{query} } + + log VALET_HOME_PATH/Log/access.log { + rotate { + size 10 + age 3 + keep 1 + } + } + + errors { + log VALET_HOME_PATH/Log/error.log { + size 10 + age 3 + keep 1 + } + } } diff --git a/cli/valet.php b/cli/valet.php index 3cdd701..60427d4 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -172,6 +172,23 @@ } })->descriptions('Stream all of the logs for all Laravel sites registered with Valet'); +/** + * Stream Caddy access- and error-log. + */ +$app->command('server-log', function () { + $files = Filesystem::scandir(VALET_HOME_PATH.'/Log'); + + $files = collect($files)->transform(function ($file) { + return escapeshellarg(VALET_HOME_PATH.'/Log/'.$file); + })->all(); + + if (count($files) > 0) { + passthru('tail -f '.implode(' ', $files)); + } else { + warning('No log files were found.'); + } +})->descriptions('Stream Caddy access- and error-log.'); + /** * Display all of the registered paths. */