public function testReuseCurrentFile() { $log = __DIR__ . '/Fixtures/foo-' . date('Y-m-d') . '.rot'; file_put_contents($log, "foo"); $handler = new RotatingFileHandler(__DIR__ . '/Fixtures/foo.rot'); $handler->write(array('message' => 'test')); $this->assertEquals('footest', file_get_contents($log)); }
/** * {@inheritdoc} */ protected function write(array $record) { if (!file_exists($this->url)) { touch($this->url); // Create blank file chmod($this->url, 0777); } parent::write($record); }
/** * Writes the log record to a separate rotatingFileHandler * * @param $record array * @return void */ public function writeWithRotation(array $record) { $logDir = $this->filesystem->getParentDirectory($this->url); if (!$this->filesystem->isDirectory($logDir)) { $this->filesystem->createDirectory($logDir, DriverInterface::WRITEABLE_DIRECTORY_MODE); } // make sure the handler is at least there if ($this->rotatingFileHandler != null) { $this->rotatingFileHandler->write($record); } else { // write the log somewhere $record['message'] .= ' - ERROR ROTATING LOG FILE'; parent::write($record); } }