andrepayone/payone-sdk-silent-logger
PSR-3 silent/noop logger for the PAYONE Payment Integration PHP SDK. Use it when you need to satisfy logging dependencies without writing any logs—ideal for tests, minimal setups, or disabling SDK logging in production.
Installation:
composer require andrepayone/payone-sdk-silent-logger
Add to your composer.json under require if not using Composer directly.
First Use Case: Replace the default logger in the PAYONE SDK with this silent logger to suppress all logging output during production or testing.
use Andrepayone\PayoneSdk\SilentLogger;
use Payone\Sdk\Payone;
$payone = new Payone([
'logger' => new SilentLogger(), // Inject the silent logger
'merchantId' => 'YOUR_MERCHANT_ID',
'secretKey' => 'YOUR_SECRET_KEY',
]);
Where to Look First:
Dependency Injection:
Always inject the SilentLogger when initializing the PAYONE SDK client. This ensures no logs are emitted during runtime.
$payone = new Payone([
'logger' => new SilentLogger(),
// Other PAYONE SDK config...
]);
Conditional Logging: Use the silent logger in production or testing environments where logs are unnecessary. For development, switch to a verbose logger (e.g., Monolog).
$logger = app()->environment('production') ? new SilentLogger() : new Monolog\Logger('payone');
Service Provider Integration: Bind the logger to Laravel’s container for easy reuse:
// In AppServiceProvider@boot()
$this->app->singleton(SilentLogger::class, function () {
return new SilentLogger();
});
Then resolve it anywhere:
$payone = new Payone([
'logger' => app(SilentLogger::class),
]);
Testing: Use the silent logger in PHPUnit tests to avoid cluttering output:
public function testPayment()
{
$payone = new Payone([
'logger' => new SilentLogger(),
]);
// Test logic...
}
Logger Persistence:
The SilentLogger is a noop implementation—it discards all log messages. If you later need logs (e.g., debugging), ensure you’re not permanently bound to this logger in production code.
PAYONE SDK Version Mismatch:
The package is designed for the Cakasim/php-payone-sdk. Ensure your SDK version is compatible (check the SDK’s README for logger requirements).
composer.json if using this package:
"require": {
"cakasim/payone-sdk": "^x.y.z",
"andrepayone/payone-sdk-silent-logger": "^0.2"
}
PSR-3 Compliance:
While this logger adheres to PSR-3, some SDKs may expect additional methods (e.g., pushHandler). Verify the SDK’s logger interface requirements.
Performance Overhead: The silent logger is minimal, but if you’re logging heavily in a loop, even a noop logger might add negligible overhead. Profile if critical.
Extending the Logger:
Subclass SilentLogger to add conditional logging (e.g., log only errors):
class ConditionalSilentLogger extends SilentLogger {
public function error($level, \String $message, array $context = []): void {
if ($level === LoggerInterface::ERROR) {
parent::log($level, $message, $context);
}
}
}
Debugging Without Switching Loggers: Temporarily replace the silent logger with a file logger for debugging:
$payone->setLogger(new Monolog\Logger('debug', [new Monolog\Handler\StreamHandler('payone_debug.log')]));
Configuration Management:
Store logger configuration in Laravel’s config/payone.php:
'logger' => env('APP_ENV') === 'production'
? \Andrepayone\PayoneSdk\SilentLogger::class
: \Monolog\Logger::class,
Then resolve it dynamically:
$loggerClass = config('payone.logger');
$payone = new Payone([
'logger' => new $loggerClass('payone'),
]);
Logging in Tests:
Use the silent logger in phpunit.xml to suppress SDK logs:
<env name="LOGGER" value="\Andrepayone\PayoneSdk\SilentLogger"/>
Then resolve it in tests:
$logger = new $this->getLoggerClass();
How can I help you explore Laravel packages today?