Skip to content

Commit

Permalink
Make logging Flow 6 / PSR compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlemke committed May 8, 2020
1 parent 685c3a0 commit 5b6a73b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
14 changes: 7 additions & 7 deletions Classes/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

use Neos\Cache\Frontend\VariableFrontend;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Routing\UriBuilder;
use Neos\Flow\Utility\Algorithms;
use Neos\FluidAdaptor\View\StandaloneView;
use Neos\SwiftMailer\Message;
use Neos\Utility\Arrays;
use Psr\Log\LoggerInterface;

/**
* This class allows to easily build a double opt-in mechanism.
Expand Down Expand Up @@ -53,7 +53,7 @@ class Helper

/**
* @Flow\Inject
* @var SystemLoggerInterface
* @var LoggerInterface
*/
protected $logger;

Expand Down Expand Up @@ -99,7 +99,7 @@ public function generateToken($identifier, $presetName = 'default', array $meta
);

$expiryTime = new \DateTime(sprintf('now +%s seconds', $preset['lifetime']));
$this->logger->log(sprintf('Token with hash %s generated for identifier %s (valid until %s) [%s]', $tokenHash, $identifier, $expiryTime->format('Y-m-d H:i:s'), $presetName), LOG_INFO);
$this->logger->info(sprintf('Token with hash %s generated for identifier %s (valid until %s) [%s]', $tokenHash, $identifier, $expiryTime->format('Y-m-d H:i:s'), $presetName));

return new Token($tokenHash, $identifier, $preset, $meta);
}
Expand All @@ -118,7 +118,7 @@ public function validateTokenHash($tokenHash)
$tokenData = $this->tokenCache->get($tokenHash);

if ($tokenData === false) {
$this->logger->log(sprintf('Validation of token hash %s failed', $tokenHash), LOG_INFO);
$this->logger->info(sprintf('Validation of token hash %s failed', $tokenHash));

return null;
}
Expand All @@ -128,7 +128,7 @@ public function validateTokenHash($tokenHash)
$this->tokenCache->remove($tokenHash);
}

$this->logger->log(sprintf('Validated token hash %s for identifier %s', $tokenHash, $tokenData['identifier']), LOG_INFO);
$this->logger->info(sprintf('Validated token hash %s for identifier %s', $tokenHash, $tokenData['identifier']));

return new Token($tokenHash, $tokenData['identifier'], $this->getPreset($tokenData['presetName']), $tokenData['meta']);
}
Expand All @@ -146,7 +146,7 @@ public function invalidateToken(Token $token)
{
$this->tokenCache->remove($token->getHash());

$this->logger->log(sprintf('Deleted token %s.', $token->getIdentifier()), LOG_INFO);
$this->logger->info(sprintf('Deleted token %s.', $token->getIdentifier()));
}

/**
Expand Down Expand Up @@ -182,7 +182,7 @@ public function getActivationLink(Token $token)
throw new \RuntimeException('Building activation link failed, uri configuration is invalid (neither array nor string)', 1434732898);
}

$this->logger->log(sprintf('Activation link built for token with hash %s', $tokenHash, $token->getIdentifier()), LOG_INFO);
$this->logger->info(sprintf('Activation link built for token with hash %s (id: %s)', $tokenHash, $token->getIdentifier()));

return str_replace('-tokenhash-', $tokenHash, $uri);
}
Expand Down
12 changes: 3 additions & 9 deletions Configuration/Objects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ Flownative\DoubleOptIn\Helper:

logger:
object:
factoryObjectName: Neos\Flow\Log\LoggerFactory
factoryMethodName: create
factoryObjectName: Neos\Flow\Log\PsrLoggerFactoryInterface
factoryMethodName: get
arguments:
1:
value: 'Flownative_DoubleOptIn'
2:
value: 'Neos\Flow\Log\Logger'
3:
setting: Flownative.DoubleOptIn.logger.backend
4:
setting: Flownative.DoubleOptIn.logger.backendOptions
value: 'systemLogger'
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"neos/flow": "^4.0 || ^5.0 || ^6.0 || dev-master"
"neos/flow": "^5.0 || ^6.0 || dev-master"
},
"suggest": {
"neos/swiftmailer": "Used to send activation mails"
Expand Down

0 comments on commit 5b6a73b

Please sign in to comment.