Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Payone Sdk Silent Logger Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require andrepayone/payone-sdk-silent-logger
    

    Add to your composer.json under require if not using Composer directly.

  2. 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',
    ]);
    
  3. Where to Look First:


Implementation Patterns

Logger Injection Workflow

  1. 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...
    ]);
    
  2. 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');
    
  3. 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),
    ]);
    
  4. Testing: Use the silent logger in PHPUnit tests to avoid cluttering output:

    public function testPayment()
    {
        $payone = new Payone([
            'logger' => new SilentLogger(),
        ]);
        // Test logic...
    }
    

Gotchas and Tips

Pitfalls

  1. 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.

    • Fix: Use environment-based logger switching (as shown in Conditional Logging).
  2. 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).

    • Tip: Pin the SDK version in composer.json if using this package:
      "require": {
          "cakasim/payone-sdk": "^x.y.z",
          "andrepayone/payone-sdk-silent-logger": "^0.2"
      }
      
  3. 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.

    • Debugging: If logs still appear, check if the SDK is using a different logger instance (e.g., a singleton).
  4. 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.

Tips

  1. 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);
            }
        }
    }
    
  2. 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')]));
    
  3. 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'),
    ]);
    
  4. 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();
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
cadot.eu/make
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky