Back to FormattedtextLogger class

Method __destruct

public
__destruct
()
If deferred, write all pending logs.
Since
  • 3.9.0

Method __destruct - Source code

/**
 * If deferred, write all pending logs.
 *
 * @since  3.9.0
 */
public function __destruct()
{
    // Nothing to do
    if (!$this->defer || empty($this->deferredEntries)) {
        return;
    }
    // Initialise the file if not already done.
    $this->initFile();
    // Format all lines and write to file.
    $lines = array_map(array($this, 'formatLine'), $this->deferredEntries);
    if (!File::append($this->path, implode("\n", $lines) . "\n")) {
        throw new \RuntimeException('Cannot write to log file.');
    }
}