Currently, the method write from the LogWritter class forces the full rewrite of the log file, which can get massive in production environments, causing unnecessary disk usage.
The correct way for production environments should just append to the file, using the file's internal pointer. This way is much faster and avoids unnecessary problems.
I suggest that the log, by default, append to file unless a config, such as 'log.mode', explicitly says to prepend to file, like in the example below:
`
protected function writeAsLeaf($message, $level)
{
$this->trueWrite(
"[" . (new \Leaf\Date())->tick()->now() . "]\n" . $level . "$message\n\n"
);
}
protected function writeAsLinux($message, $level)
{
$this->trueWrite(
"[" . (new \Leaf\Date())->tick()->now() . "] " . $level . "$message\n\n"
);
}
private function trueWrite(string $formmatedMessage)
{
if ( \Leaf\Config::get('log.mode') === 'prepend') {
$contentToWrite = function ($content) use ($message, $level) {
return $formmatedMessage . $content;
};
$mode = 0;
} else {
$contentToWrite = $formmatedMessage;
$mode = FILE_APPEND;
}
FS\File::write(
$this->logFile,
$contentToWrite,
$mode
);
}
}
`
Currently, the method write from the LogWritter class forces the full rewrite of the log file, which can get massive in production environments, causing unnecessary disk usage.
The correct way for production environments should just append to the file, using the file's internal pointer. This way is much faster and avoids unnecessary problems.
I suggest that the log, by default, append to file unless a config, such as 'log.mode', explicitly says to prepend to file, like in the example below:
`
protected function writeAsLeaf($message, $level)
{
$this->trueWrite(
"[" . (new \Leaf\Date())->tick()->now() . "]\n" . $level . "$message\n\n"
);
}
}
`