Skip to content

Commit

Permalink
TASK: Refactor instances of logger to psrLogger
Browse files Browse the repository at this point in the history
Refactor usages of the deprecated systemLogger to
the PSR system logger.
Fix some code style issues along the way.
  • Loading branch information
daniellienert committed Nov 5, 2018
1 parent 985c4d8 commit bc68159
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\Log\PsrSystemLoggerInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Persistence\QueryInterface;
use Neos\Flow\Persistence\Repository;
use Neos\Utility\Arrays;
Expand Down Expand Up @@ -84,7 +85,7 @@ class NodeDataRepository extends Repository

/**
* @Flow\Inject
* @var SystemLoggerInterface
* @var PsrSystemLoggerInterface
*/
protected $systemLogger;

Expand Down Expand Up @@ -730,7 +731,7 @@ public function countByParentAndNodeType($parentPath, $nodeTypeFilter, Workspace
*/
protected function openIndexSpace($parentPath, $referenceIndex)
{
$this->systemLogger->log(sprintf('Opening sortindex space after index %s at path %s.', $referenceIndex, $parentPath), LOG_INFO);
$this->systemLogger->info(sprintf('Opening sortindex space after index %s at path %s.', $referenceIndex, $parentPath), LogEnvironment::fromMethodName(__METHOD__));

/** @var Query $query */
$query = $this->entityManager->createQuery('SELECT n.Persistence_Object_Identifier identifier, n.index, n.path FROM Neos\ContentRepository\Domain\Model\NodeData n WHERE n.parentPathHash = :parentPathHash ORDER BY n.index ASC');
Expand Down
9 changes: 6 additions & 3 deletions Neos.ContentRepository/Classes/Domain/Service/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\Log\PsrSystemLoggerInterface;
use Neos\ContentRepository\Domain\Factory\NodeFactory;
use Neos\ContentRepository\Domain\Model\NodeData;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
use Neos\ContentRepository\Domain\Service\Cache\FirstLevelNodeCache;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Persistence\Exception\IllegalObjectTypeException;

/**
* Context
Expand Down Expand Up @@ -54,7 +56,7 @@ class Context

/**
* @Flow\Inject
* @var SystemLoggerInterface
* @var PsrSystemLoggerInterface
*/
protected $systemLogger;

Expand Down Expand Up @@ -143,6 +145,7 @@ public function __construct($workspaceName, \DateTimeInterface $currentDateTime,
* @param boolean $createWorkspaceIfNecessary DEPRECATED: If enabled, creates a workspace with the configured name if it doesn't exist already. This option is DEPRECATED, create workspace explicitly instead.
* @return Workspace The workspace or NULL
* @api
* @throws IllegalObjectTypeException
*/
public function getWorkspace($createWorkspaceIfNecessary = true)
{
Expand All @@ -155,7 +158,7 @@ public function getWorkspace($createWorkspaceIfNecessary = true)
$liveWorkspace = $this->workspaceRepository->findByIdentifier('live');
$this->workspace = new Workspace($this->workspaceName, $liveWorkspace);
$this->workspaceRepository->add($this->workspace);
$this->systemLogger->log(sprintf('Notice: %s::getWorkspace() implicitly created the new workspace "%s". This behaviour is discouraged and will be removed in future versions. Make sure to create workspaces explicitly by adding a new workspace to the Workspace Repository.', __CLASS__, $this->workspaceName), LOG_NOTICE);
$this->systemLogger->notice(sprintf('Notice: %s::getWorkspace() implicitly created the new workspace "%s". This behaviour is discouraged and will be removed in future versions. Make sure to create workspaces explicitly by adding a new workspace to the Workspace Repository.', __CLASS__, $this->workspaceName), LogEnvironment::fromMethodName(__METHOD__));
}

if ($this->workspace !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\PsrSystemLoggerInterface;

/**
* Renders the element as an empty string
Expand All @@ -20,7 +21,7 @@ class AbsorbingHandler extends AbstractRenderingExceptionHandler
{
/**
* @Flow\Inject
* @var \Neos\Flow\Log\SystemLoggerInterface
* @var PsrSystemLoggerInterface
*/
protected $systemLogger;

Expand All @@ -34,7 +35,7 @@ class AbsorbingHandler extends AbstractRenderingExceptionHandler
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode)
{
$this->systemLogger->log('Absorbed Exception: ' . $exception->getMessage(), LOG_DEBUG, ['fusionPath' => $fusionPath, 'referenceCode' => $referenceCode], 'Neos.Fusion', \Neos\Fusion\Core\ExceptionHandlers\AbsorbingHandler::class);
$this->systemLogger->debug('Absorbed Exception: ' . $exception->getMessage(), ['fusionPath' => $fusionPath, 'referenceCode' => $referenceCode, 'FLOW_LOG_ENVIRONMENT' => ['packageKey' => 'Neos.Fusion', 'className' => self::class, 'methodName' => 'handle']]);
return '';
}

Expand Down
5 changes: 3 additions & 2 deletions Neos.Media/Classes/Domain/Service/AssetSourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\PsrSystemLoggerInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Flow\ResourceManagement\Exception;
use Neos\Flow\ResourceManagement\ResourceManager;
Expand Down Expand Up @@ -118,7 +119,7 @@ public function importAsset(string $assetSourceIdentifier, string $assetIdentifi
$assetProxy = $assetProxyRepository->getAssetProxy($assetIdentifier);

if (!$assetProxy instanceof HasRemoteOriginalInterface) {
$this->systemLogger->log(LOG_ERR, sprintf('Failed importing an the asset %s from asset source %s because it does not have a remote original.', $assetProxy->getFilename(), $assetSourceIdentifier));
$this->systemLogger->error(sprintf('Failed importing an the asset %s from asset source %s because it does not have a remote original.', $assetProxy->getFilename(), $assetSourceIdentifier), LogEnvironment::fromMethodName(__METHOD__));
throw new AssetSourceServiceException(sprintf('Failed importing an the asset %s from asset source %s because it does not have a remote original.', $assetProxy->getFilename(), $assetSourceIdentifier), 1538754066);
}

Expand All @@ -128,7 +129,7 @@ public function importAsset(string $assetSourceIdentifier, string $assetIdentifi
$assetResource = $this->resourceManager->importResource($assetProxy->getImportStream());
$assetResource->setFilename($assetProxy->getFilename());
} catch (Exception $exception) {
$this->systemLogger->log(LOG_ERR, sprintf('Failed importing an the asset %s from asset source %s. Original URI: %s. Error: %s', $assetProxy->getFilename(), $assetSourceIdentifier, $assetProxy->getImportStream(), $exception->getMessage()));
$this->systemLogger->error(sprintf('Failed importing an the asset %s from asset source %s. Original URI: %s. Error: %s', $assetProxy->getFilename(), $assetSourceIdentifier, $assetProxy->getImportStream(), $exception->getMessage()), LogEnvironment::fromMethodName(__METHOD__));
throw $exception;
}

Expand Down
18 changes: 11 additions & 7 deletions Neos.Neos/Classes/Domain/Service/ContentContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Persistence\Exception\IllegalObjectTypeException;
use Neos\Flow\Security\Authorization\PrivilegeManagerInterface;
use Neos\Flow\Security\Exception;
use Neos\Neos\Domain\Model\Domain;
Expand Down Expand Up @@ -112,7 +114,7 @@ public function getCurrentSiteNode()
$siteNodePath = NodePaths::addNodePathSegment(SiteService::SITES_ROOT_PATH, $this->currentSite->getNodeName());
$this->currentSiteNode = $this->getNode($siteNodePath);
if (!($this->currentSiteNode instanceof NodeInterface)) {
$this->systemLogger->log(sprintf('Warning: %s::getCurrentSiteNode() couldn\'t load the site node for path "%s" in workspace "%s". This is probably due to a missing baseworkspace for the workspace of the current user.', __CLASS__, $siteNodePath, $this->workspaceName), LOG_WARNING);
$this->systemLogger->warning(sprintf('Couldn\'t load the site node for path "%s" in workspace "%s". This is probably due to a missing baseworkspace for the workspace of the current user.', $siteNodePath, $this->workspaceName), LogEnvironment::fromMethodName(__METHOD__));
}
}
return $this->currentSiteNode;
Expand Down Expand Up @@ -141,9 +143,10 @@ public function getProperties()
/**
* Returns true if current context is live workspace, false otherwise
*
* @return boolean
* @return bool
* @throws IllegalObjectTypeException
*/
public function isLive()
public function isLive(): bool
{
return ($this->getWorkspace()->getBaseWorkspace() === null);
}
Expand All @@ -152,26 +155,27 @@ public function isLive()
* Returns true while rendering backend (not live workspace and access to backend granted), false otherwise
*
* @return boolean
* @throws IllegalObjectTypeException
*/
public function isInBackend()
public function isInBackend(): bool
{
return (!$this->isLive() && $this->hasAccessToBackend());
}

/**
* @return UserInterfaceMode
*/
public function getCurrentRenderingMode()
public function getCurrentRenderingMode(): UserInterfaceMode
{
return $this->interfaceRenderModeService->findModeByCurrentUser();
}

/**
* Is access to the neos backend granted by current authentications.
*
* @return boolean
* @return bool
*/
protected function hasAccessToBackend()
protected function hasAccessToBackend(): bool
{
try {
return $this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess');
Expand Down
6 changes: 3 additions & 3 deletions Neos.Neos/Classes/Routing/FrontendNodeRoutePartHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\Log\PsrSystemLoggerInterface;
use Neos\Flow\Mvc\Routing\DynamicRoutePart;
use Neos\Flow\Security\Context;
use Neos\Neos\Domain\Repository\DomainRepository;
Expand All @@ -35,7 +35,7 @@ class FrontendNodeRoutePartHandler extends DynamicRoutePart implements FrontendN

/**
* @Flow\Inject
* @var SystemLoggerInterface
* @var PsrSystemLoggerInterface
*/
protected $systemLogger;

Expand Down Expand Up @@ -128,7 +128,7 @@ protected function matchValue($requestPath)
$node = $this->convertRequestPathToNode($requestPath);
});
} catch (Exception $exception) {
$this->systemLogger->log('FrontendNodeRoutePartHandler matchValue(): ' . $exception->getMessage(), LOG_DEBUG);
$this->systemLogger->debug('FrontendNodeRoutePartHandler matchValue(): ' . $exception->getMessage());
if ($requestPath === '') {
throw new Exception\NoHomepageException('Homepage could not be loaded. Probably you haven\'t imported a site yet', 1346950755, $exception);
}
Expand Down
14 changes: 8 additions & 6 deletions Neos.Neos/Classes/Service/LinkingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\Uri;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\Log\PsrSystemLoggerInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Flow\Property\PropertyMapper;
Expand Down Expand Up @@ -97,7 +98,7 @@ class LinkingService

/**
* @Flow\Inject
* @var SystemLoggerInterface
* @var PsrSystemLoggerInterface
*/
protected $systemLogger;

Expand Down Expand Up @@ -150,12 +151,13 @@ public function getScheme($uri)
* @param ControllerContext $controllerContext
* @param bool $absolute
* @return string
* @throws NeosException
*/
public function resolveNodeUri($uri, NodeInterface $contextNode, ControllerContext $controllerContext, $absolute = false)
public function resolveNodeUri(string $uri, NodeInterface $contextNode, ControllerContext $controllerContext, bool $absolute = false): string
{
$targetObject = $this->convertUriToObject($uri, $contextNode);
if ($targetObject === null) {
$this->systemLogger->log(sprintf('Could not resolve "%s" to an existing node; The node was probably deleted.', $uri));
$this->systemLogger->info(sprintf('Could not resolve "%s" to an existing node; The node was probably deleted.', $uri), LogEnvironment::fromMethodName(__METHOD__));
return null;
}
return $this->createNodeUri($controllerContext, $targetObject, null, null, $absolute);
Expand All @@ -167,11 +169,11 @@ public function resolveNodeUri($uri, NodeInterface $contextNode, ControllerConte
* @param string|Uri $uri
* @return string
*/
public function resolveAssetUri($uri)
public function resolveAssetUri(string $uri): ?string
{
$targetObject = $this->convertUriToObject($uri);
if ($targetObject === null) {
$this->systemLogger->log(sprintf('Could not resolve "%s" to an existing asset; The asset was probably deleted.', $uri));
$this->systemLogger->info(sprintf('Could not resolve "%s" to an existing asset; The asset was probably deleted.', $uri), LogEnvironment::fromMethodName(__METHOD__));
return null;
}
return $this->resourceManager->getPublicPersistentResourceUri($targetObject->getResource());
Expand Down
14 changes: 8 additions & 6 deletions Neos.Neos/Classes/Service/View/NodeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

use Neos\Flow\Annotations as Flow;
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\Log\PsrSystemLoggerInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Mvc\View\JsonView;
use Neos\Flow\Security\Authorization\PrivilegeManagerInterface;
use Neos\Neos\Security\Authorization\Privilege\NodeTreePrivilege;
Expand Down Expand Up @@ -44,7 +45,7 @@ class NodeView extends JsonView

/**
* @Flow\Inject
* @var SystemLoggerInterface
* @var PsrSystemLoggerInterface
*/
protected $systemLogger;

Expand Down Expand Up @@ -77,9 +78,10 @@ public function assignNode(NodeInterface $node, array $propertyNames = ['name',
}

/**
* @param array $nodes
* @param NodeInterface[] $nodes
* @throws \Neos\Eel\Exception
*/
public function assignNodes(array $nodes)
public function assignNodes(array $nodes): void
{
$data = [];
foreach ($nodes as $node) {
Expand All @@ -92,7 +94,7 @@ public function assignNodes(array $nodes)
'documentNodeContextPath' => $closestDocumentNode->getContextPath(),
];
} else {
$this->systemLogger->log('You have a node that is no longer connected to a parent. Path: ' . $node->getPath() . ' (Identifier: ' . $node->getIdentifier() . ')');
$this->systemLogger->info(sprintf('You have a node that is no longer connected to a parent. Path: %s (Identifier: %s)', $node->getPath(), $node->getIdentifier()), LogEnvironment::fromMethodName(__METHOD__));
}
}
}
Expand Down Expand Up @@ -200,7 +202,7 @@ protected function collectChildNodeData(array &$nodes, NodeInterface $node, $nod
if ($expand) {
$this->collectChildNodeData($nodes, $childNode, $nodeTypeFilter, $depth, $untilNode, ($recursionPointer + 1));
}
break;
break;
case self::STYLE_TREE:
$children = [];
$hasChildNodes = $childNode->hasChildNodes($nodeTypeFilter) === true;
Expand Down

0 comments on commit bc68159

Please sign in to comment.