Problem/Motivation

Currently the .module file still contains linkchecker_watchdog_log.

Proposed resolution

Remove linkchecker_watchdog_log to a dedicated service.

Comments

JeroenT created an issue. See original summary.

jeroent’s picture

StatusFileSize
new9.35 KB

Patch attached removes the function linkchecker_watchdog_log and replaces it with a dedicated service.

jeroent’s picture

Status: Active » Needs review
jeroent’s picture

StatusFileSize
new9.68 KB
new2.76 KB

Fixed some coding standards.

dsdeiz’s picture

Oh nice, yeah this does seem way better. I tested this manually and seems like I'm not getting the messages on watchdog or perhaps is it logging somewhere else? Changing the service to this seem to do the trick:

  logger.channel.linkchecker:
    class: drupal\linkchecker\logger\linkcheckerlogger
    factory: logger.factory:get
    arguments: ['linkchecker', '@config.factory']

Also changing the link context to this:

$this->logger->notice('Link %link has changed and needs to be updated.', [
  '%link' => $link->getUrl(),
  'link' => $this->getReportLink()->toString(),
]);

Would tests also help? I can work on it if necessary but probably just basing it on RulesLoggerChannelTest (seems to be the only basis I can find which provides a custom LoggerChannel).

dsdeiz’s picture

Status: Needs review » Needs work
jeroent’s picture

@dsdeiz,

The reason I removed the factory is \Drupal\Core\Logger\LoggerChannelFactory line 34.:

$instance = new LoggerChannel($channel);

When you add that line, the service won't use our \Drupal\linkchecker\Logger\LinkCheckerLogger. but will use the LoggerChannel we want to extend. Also which messages that should be logged are configurable:

+++ b/src/Logger/LinkCheckerLogger.php
@@ -0,0 +1,43 @@
+    if ($this->levelTranslation[$level] <= $this->linkCheckerSettings->get('logging.level')) {
+      parent::log($level, $message, $context);
+    }

If you could add testing, that would benefit this issue a lot!

dsdeiz’s picture

When you add that line, the service won't use our \Drupal\linkchecker\Logger\LinkCheckerLogger. but will use the LoggerChannel we want to extend. Also which messages that should be logged are configurable:

Oh right, yeah. It doesn't seem to log to watchdog though even if I have set it to log all messages. I think the logs are created but are just not sent to watchdog or perhaps there needs to be a way to render the sent logs similar to #3104109: Implement rendering of debug logs to screen and database. Or perhaps I'm just missing something.

If you could add testing, that would benefit this issue a lot!

Yeah, will see if I am able to implement this.

dsdeiz’s picture

Status: Needs work » Needs review

Yeah, will see if I am able to implement this.

Yeah, sorry, guess I'm not sure how to do this. Tried to base it here but can't get it to work.

Putting it back to "Needs review" for others more familiar on how to test this.

c-logemann’s picture

Status: Needs review » Needs work

The patch doesn't apply anymore. I think this is just because of last changes with othe huge code cleanups. So patch needs to be fixed in the next step.

tomefa’s picture

StatusFileSize
new9.65 KB

Update Patch for the last dev branch code.

tomefa’s picture

Status: Needs work » Needs review
jeroent’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
jeroent’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new9.67 KB
joelpittet’s picture

c-logemann’s picture

The patch applies and I set setting Log level to "Debug messages" but there no messages in my test system after I retriggered link extraction etc. Di I miss something or is there is something missed in the new strategy?

jeroent’s picture

StatusFileSize
new11.29 KB
new7.64 KB

@C_Loggeman,

You're right, there seems something wrong with patch #14. I created a new one.

eiriksm’s picture

Status: Needs review » Needs work

Can we get the type hint and argument type to be Psr\Log\LoggerInterface instead? This patch will break sites if you use another library for logging (for example monolog).

Also, would be nice to have a test or two?😉️ I am thinking a test that proves that the log level chosen logs, and run that with and without the function removed?

jeroent’s picture

Issue tags: +Needs tests