Skip to content

#126 Inject a LoggerInterface for log->alert #130

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

Closed
wants to merge 3 commits into from

Conversation

alister
Copy link

@alister alister commented Mar 11, 2016

The alert will also append a JSON copy of the check(s) that failed.

If a logger is not given, will default to a NullLogger.

The alert will also append a JSON copy of the check(s) that failed
{
$this->runnerManager = $runnerManager;
$this->pathHelper = $pathHelper;
$this->template = $template;
if ($log === null) {
$log = new NullLogger();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather move this "logic" to the DI layer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll remove the NullLogger, and require a valid logger to be injected. Users can can replace it with another Logger, Null, or otherwise.

@@ -17,6 +17,7 @@
<argument type="service" id="liip_monitor.helper.runner_manager" />
<argument type="service" id="liip_monitor.helper" />
<argument>%liip_monitor.view_template%</argument>
<argument type="service" id="logger" on-invalid="ignore" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this needs to be mandatory .. we just need to ensure we have a logger to inject ..
I am not sure if the core logger service defaults to NullLogger if no logging is enabled .. if not we would need to create our own service which we optionally alias to the core logger via a compiler pass if the logger service is defined

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be fine as mandatory - not having a logger service is a little silly anyhow.

I have tested the symfony-demo app (v2.7.6) with all monolog configs removed, and you still get a valid LoggerInterface (a Symfony\Bridge\Monolog\Logger) - but it has no handlers and so will just try to send to STDERR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear it means we then require that the MonologBundle is active ..

@stof can you confirm this? what is the current best practice here? I seem to remember that we are phasing out if (null !== $this->logger) { type code in core .. and afaik also making NullLogger fallback instances ..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core Symfony appears to only use a NullLogger in testing. Other logging happens within a if (null !== $this->logger) check, 'for performance reasons'.

I think that any tiny reduction of speed within the bundle would be more than offset by the clarity of code with a new NullLogger() in the constructor - but I'd be happy to wrap the logging calls I've written in conditionals anyway if that is the general consensus.

That would also leave the controller.xml as it was originally - allowing the logger to be able to be optional, and so fail-safe if there was no such service (in Yaml, it would be "?@logger"), and so it would default to null from the constructor parameter.

@kbond
Copy link
Collaborator

kbond commented Mar 14, 2016

As it stands now, you are required to be using the controller shipped with this bundle to have logging enabled. What about having the logging logic in a LoggerRunner that could be enabled via config?

@ndench
Copy link

ndench commented Mar 8, 2019

Is this PR likely to be merged anytime soon? Is there anything I can do to help?

@lsmith77
Copy link
Contributor

lsmith77 commented Mar 8, 2019

as the discussion is quite stale .. no there were no immediate plans. do you need this feature? what do you think about @kbond's suggestion?

@ndench
Copy link

ndench commented Mar 8, 2019

I like the suggestion of having logs enabled via config.
Another idea I had was allowing extra default Reporters to be specified. As it stands, I could write my own LoggerReporter, but if I want it to be enabled on my automatic health check I have to pass in ?reporters[]=my_reporter as a query param. It would be nice for users to be able to write their own reporters that are included by default.

@lsmith77
Copy link
Contributor

sounds good to me and would be inline with what @kbond was suggesting.

@stale
Copy link

stale bot commented Jul 8, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 8, 2020
@stale
Copy link

stale bot commented Jul 15, 2020

This pull request has been automatically closed. Feel free to re-create if it is still relevant.

@stale stale bot closed this Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy