artex / logger
Lightweight, PSR-3-compliant PHP logger for fast and efficient logging.
Requires (Dev)
- phpstan/phpstan: ^1.9
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-strict-rules: ^1.4
- phpunit/phpunit: ^10.5
README
LOGGER
FAST PSR-3 LOGGER
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.
Key Features
- 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.
Installation
composer "require artex/exceptions"
Usage
Basic Example
use Artex\Exceptions\ArtexRuntimeException; try { throw new ArtexRuntimeException("Something went wrong!", 500); } catch (ArtexRuntimeException $e) { echo $e->getMessage(); }
Adding Context to Exceptions
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()); }
Extending Exceptions
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); } }
Logging Exceptions
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(); }
Available Exceptions
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. |
Advanced Usage
Extending Exceptions
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); } }
Requirements
- PHP 8.0 or higher
Contributing
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.
LICENSE
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.
FOLLOW US
COPYRIGHT © 2025 ARTEX AGENCY INC.