file === null) { throw new ConfigurationError('Required logging configuration directive \'file\' missing'); } $this->file = $config->file; if (substr($this->file, 0, 6) !== 'php://' && ! file_exists(dirname($this->file))) { throw new ConfigurationError( 'Log path "%s" does not exist', dirname($this->file) ); } try { $this->write(''); // Avoid to handle such errors on every write access } catch (Exception $e) { throw new ConfigurationError( 'Cannot write to log file "%s" (%s)', $this->file, $e->getMessage() ); } } /** * Log a message * * @param int $level The logging level * @param string $message The log message */ public function log($level, $message) { $this->write(date('c') . ' - ' . Logger::$levels[$level] . ' - ' . $message . PHP_EOL); } /** * Write a message to the log * * @param string $message */ protected function write($message) { $file = new File($this->file, 'a'); $file->fwrite($message); $file->fflush(); } }