Read the old content into $content
, then write $string . $content
back into the file: not working, new messages are printed at the end of the file.
Relevant methods in the Logger
class:
public function __construct($filename)
{
$this->filename = $filename;
$this->fp = fopen($this->filename, "w+");
if (!$this->fp) throw new Exception("Errore nel file: " . $this->filename);
}
protected function log($severity, $message)
{
$string = sprintf("[%s] (%s): %s", $severity, date('d/m/Y H:i:s'), $message);
$content = !filesize($this->filename)? '' :
fread($this->fp, filesize($this->filename));
fwrite($this->fp, $string . $content . "\n");
return $message;
}