Zusammengeführt
Oldperl hat 17 Commits von feature/make-logrotation-switchable-#9 nach develop 2024-03-12 18:26:58 +00:00 zusammengeführt
3 geänderte Dateien mit 58 neuen und 0 gelöschten Zeilen
Nur Änderungen aus Commit ed6b5569fd werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -0,0 +1,8 @@
<?php
namespace ConLite\Exceptions;
class FileNotFoundException extends RuntimeException
{
}

Datei anzeigen

@ -0,0 +1,8 @@
<?php
namespace ConLite\Exceptions;
class RuntimeException extends Exception
{
}

Datei anzeigen

@ -2,7 +2,49 @@
namespace ConLite\Log;
use ConLite\Exceptions\Exception;
use ConLite\Exceptions\FileNotFoundException;
class LogWriterFile extends LogWriter
{
/**
* @var resource
*/
protected $handle = NULL;
/**
* @throws FileNotFoundException
* @throws Exception
*/
public function __construct(array $options = []) {
parent::__construct($options);
$this->createHandle();
}
/**
* @param string $message
* @param int $priority
* @return bool
*/
public function write($message, $priority): bool
{
return fwrite($this->handle, $message) != false;
}
/**
* @throws Exception
* @throws FileNotFoundException
*/
protected function createHandle(): void
{
$destination = $this->getOption('destination');
if ($destination == '') {
throw new Exception('No destination was specified.');
}
if (($this->handle = fopen($destination, 'a')) === false) {
throw new FileNotFoundException('Destination handle could not be created.');
}
}
}