Skip to content

Commit

Permalink
Apply newyslog to prevent large logfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mischabraam committed Dec 5, 2023
1 parent 263d7ed commit 7ffa575
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cli/ValetPlus/Extended/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,27 @@ class Configuration extends ValetConfiguration
{
/** @var string */
protected const CUSTOM_DRIVERS_STUB_DIR = __DIR__ . '/../../stubs/drivers/custom/';
/** @var string */
protected const LOG_ROTATE_STUB_FILE = __DIR__ . '/../../stubs/newsyslog.d/valet-plus.conf';
/** @var string */
protected const LOG_ROTATE_FILE = '/etc/newsyslog.d/valet-plus.conf';

/**
* @inheritdoc
*/
public function createDriversDirectory(): void
{
parent::createDriversDirectory();
$this->installCustomDrivers();
}

/**
* Installs custom drivers not supported by Valet.
*
* @return void
*/
protected function installCustomDrivers(): void
{
$driversDirectory = VALET_HOME_PATH . '/Drivers/';
foreach (scandir(static::CUSTOM_DRIVERS_STUB_DIR) as $driver) {
if (!is_dir($driver)) {
Expand All @@ -28,4 +41,40 @@ public function createDriversDirectory(): void
}
}
}

/**
* @inheritdoc
*/
public function createLogDirectory(): void
{
parent::createLogDirectory();
$this->installNewsysLogRotation();
}

/**
* Installing configuration files for log file rotation.
*
* This log file rotation is using the default MacOS newsyslog. It places a config file in the newsyslog.d directory
* which is automatically picked up and processed. You can run the following command to see what newsyslog will
* rotate.
*
* Command: `sudo newsyslog -vn`
*
* See https://www.real-world-systems.com/docs/newsyslog.1.html
*
* @return void
*/
protected function installNewsysLogRotation(): void
{
// Place config file to rotate log files in Valet+ log path.
$contents = $this->files->get(static::LOG_ROTATE_STUB_FILE);
$contents = str_replace('VALET_HOME_PATH', VALET_HOME_PATH, $contents);

$this->files->putAsUser(
static::LOG_ROTATE_FILE,
$contents
);

//@todo; Set up log rotation for BREW_PREFIX . '/var/log/' to rotate elasticsearch logs
}
}
4 changes: 4 additions & 0 deletions cli/stubs/newsyslog.d/valet-plus.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
VALET_HOME_PATH/Log/mysql.log 644 10 20480 * JN
VALET_HOME_PATH/Log/nginx-error.log 644 10 20480 * JN
VALET_HOME_PATH/Log/php-fpm.log 644 10 20480 * JN

0 comments on commit 7ffa575

Please sign in to comment.