Artex Logger is a lightweight, high-performance PHP logging library that adheres to PSR-3 standards, making it highly compatible with existing frameworks. It provides structured logging, supports log rotation, and offers optional asynchronous logging to ensure minimal performance impact.
- Lightweight & High-Performance: Minimal overhead, designed for speed.
- PSR-3 Compliant: Fully compatible with existing logging frameworks.
- Structured Logging: Supports JSON and customizable log formats.
- Log Rotation: Prevents uncontrolled growth of log files.
- Asynchronous Logging: Optional non-blocking log writing.
composer "require artex/exceptions"
use Artex\Exceptions\ArtexRuntimeException;
try {
throw new ArtexRuntimeException("Something went wrong!", 500);
} catch (ArtexRuntimeException $e) {
echo $e->getMessage();
}
use Artex\Exceptions\ArtexException;
try {
throw new ArtexException(
"Validation failed!",
422,
['field' => 'email', 'error' => 'Invalid format']
);
} catch (ArtexException $e) {
// Access additional context
var_dump($e->getContext());
}
You can easily extend any Artex exception to create project-specific exceptions:
namespace MyApp\Exceptions;
use Artex\Exceptions\ArtexRuntimeException;
class CustomException extends ArtexRuntimeException
{
public function __construct(string $message = "", int $code = 0, array $context = [])
{
parent::__construct($message, $code, $context);
}
}
The library can seamlessly log exceptions if a PSR-3 compatible logger is available:
use Artex\Exceptions\ArtexRuntimeException;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// Set up a PSR-3 logger
$logger = new Logger('example');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
// Register the logger
ArtexRuntimeException::registerLogger($logger);
try {
throw new ArtexRuntimeException("Critical failure", 500);
} catch (ArtexRuntimeException $e) {
// Exception is automatically logged
echo "Exception logged: " . $e->getMessage();
}
The library ships with the following prebuilt exceptions:
Exception Class | Description |
---|---|
ArtexException |
Base exception class for all custom exceptions. |
ArtexRuntimeException |
For runtime errors. |
ArtexInvalidArgumentException |
For invalid arguments passed to functions. |
ArtexLogicException |
For logical errors in the application. |
ArtexUnexpectedValueException |
For unexpected values in operations. |
ValidationException |
For validation-specific errors. |
DatabaseException |
For database-related errors. |
FileException |
For file-related errors. |
You can easily extend any Artex exception to create project-specific exceptions:
namespace MyApp\Exceptions;
use Artex\Exceptions\ArtexRuntimeException;
class CustomException extends ArtexRuntimeException
{
public function __construct(string $message = "", int $code = 0, array $context = [])
{
parent::__construct($message, $code, $context);
}
}
- PHP 8.0 or higher
We welcome contributions to the Artex Standard Exceptions Library! If you have an idea, feature request, or find a bug, please open an issue or submit a pull request.
This software is distributed under the Apache 2.0 License, granting you the freedom to use, modify, and distribute the software, provided you adhere to the terms outlined in the license.
See the LICENSE file for details.