Skip to content

Latest commit

 

History

History
46 lines (39 loc) · 1.41 KB

debugging.md

File metadata and controls

46 lines (39 loc) · 1.41 KB

Debugging

The MFA module ships with a PSR-3 logger configured by default (a Monolog implementation), however no Monolog handlers are attached by default. To enable developer logging, you can attach a handler. An example that will log to a mfa.log file in the project root:

SilverStripe\Core\Injector\Injector:
  Psr\Log\LoggerInterface.mfa:
    calls:
      pushFileLogHandler: [ pushHandler, [ '%$MFAFileLogHandler' ] ]
  MFAFileLogHandler:
    class: Monolog\Handler\StreamHandler
    constructor:
      - '../mfa.log'
      - 'debug'

You can inject this logger into any MFA authenticator module, or custom app code, by using dependency injection:

class MyCustomLoginHandler implements LoginHandlerInterface
{
    private static $dependencies = [
        'Logger' => '%$' . \Psr\Log\LoggerInterface::class . '.mfa',
    ];

    protected $logger;

    public function setLogger(LoggerInterface $logger): self
    {
        $this->logger = $logger;
        return $this;
    }

    public function start(StoreInterface $store, RegisteredMethod $method): array
    {
        try {
            $method->doSomething();
        } catch (\Exception $ex) {
            $this->logger->debug('Something went wrong! ' . $ex->getMessage(), $ex->getTrace());
        }
    }
}