Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a PSR-3 logger #213

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open

Implement a PSR-3 logger #213

wants to merge 1 commit into from

Conversation

Mark-H
Copy link
Collaborator

@Mark-H Mark-H commented Oct 23, 2021

First pass at implementing support for a PSR-3 logger into xPDO.

The basic idea is you pass a LoggerInterface into the container, which will then be set to protected xPDO::$logger (provided by the LoggerAwareTrait).

The new xPDOLogger is a BC layer that provides a PSR-3 implementation for the old behavior. This also deprecates most of the old logger stuff, so that could be removed in v4.

Some to do's:

  • Probably needs some new/updated tests
  • Should xPDO::$logger be public? Kinda risks it getting replaced, but would simplify calls to it.
  • Document usage
  • Perhaps change xPDO::setLogger to also override the logger in the container?

For MODX-usage I'm thinking packages could provide a custom logger through the namespace bootstrap.php with setLogger(). Biggest challenge is that's after a bunch of other initialisation, including xPDO, so that might need some more thought.

For testing so far I used a quick snippet:

<?php
$modx->log(modX::LOG_LEVEL_ERROR, 'This is an error.');
$modx->log(\Psr\Log\LogLevel::ERROR, 'This is also an error.');
$modx->log(modX::LOG_LEVEL_INFO, 'This is not visible.');
$modx->setLogLevel(\Psr\Log\LogLevel::INFO);
$modx->log(modX::LOG_LEVEL_INFO, 'This is visible.');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->log(modX::LOG_LEVEL_INFO, 'This is also visible.');

$modx->setLogTarget('HTML');
$modx->log(modX::LOG_LEVEL_INFO, 'This gets rendered to screen.');


$modx->setLogTarget('FILE');
$modx->getLogger()->error('Hello world');
$modx->getLogger()->log('error', 'Goodbye world');

@cla-bot cla-bot bot added the cla-signed CLA confirmed for all contributors to this PR label Oct 23, 2021
@Mark-H
Copy link
Collaborator Author

Mark-H commented Oct 23, 2021

👀

afbeelding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed CLA confirmed for all contributors to this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant