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

Add logging to Hub on update publish #110

Closed
wants to merge 1 commit into from

Conversation

tostiheld
Copy link

@tostiheld tostiheld commented Dec 9, 2023

In favour of #86 #SymfonyHackday

@tostiheld tostiheld force-pushed the hub-logging branch 2 times, most recently from a7c6abb to 21fb2fa Compare December 9, 2023 11:02
@tostiheld
Copy link
Author

@dunglas CI is failing because of a coding standards check (inheritDoc should be removed from the Hub). Do you want me to ignore it or fix in a different PR?

@@ -46,6 +46,7 @@
},
"require-dev": {
"lcobucci/jwt": "^3.4|^4.0|^5.0",
"psr/log": "^1.0",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"psr/log": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",

@dunglas
Copy link
Member

dunglas commented Dec 9, 2023

Thanks! PR to fix the the CS is welcome.

'auth_bearer' => $jwt,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
],
'body' => Internal\QueryBuilder::build($postData),
])->getContent();

$this->logUpdate($update);
Copy link
Member

Choose a reason for hiding this comment

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

I would move the null check here to prevent a useless function call in case the logger isn't injected (this code may be in the hot path if the app sends a lof of updates):

Suggested change
$this->logUpdate($update);
if (null !== $this->logger) {
$this->logUpdate($update);
}

Comment on lines +129 to +145
$this->logger->info(
sprintf(
'Published update with ID \'%s\' on topic(s) [%s]',
$update->getId(),
implode(', ', $update->getTopics())
),
[
'id' => $update->getId(),
'topic' => $update->getTopics(),
]
);

$this->logger->debug(
sprintf('Debug details for update \'%s\'', $update->getId()),
$this->updateToArray($update)
);
}
Copy link
Member

@dunglas dunglas Dec 9, 2023

Choose a reason for hiding this comment

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

IMHO it would be better to have only one entry in the logs instead of two, even in debug mode. What do you think about like that:

Suggested change
$this->logger->info(
sprintf(
'Published update with ID \'%s\' on topic(s) [%s]',
$update->getId(),
implode(', ', $update->getTopics())
),
[
'id' => $update->getId(),
'topic' => $update->getTopics(),
]
);
$this->logger->debug(
sprintf('Debug details for update \'%s\'', $update->getId()),
$this->updateToArray($update)
);
}
$this->logger->info(
sprintf(
'Published update with ID "%s" on topic(s) [%s]',
$update->getId(),
implode(', ', $update->getTopics())
),
$this->debug ? $this->updateToArray($update) : [
'id' => $update->getId(),
'topic' => $update->getTopics(),
] :
);
}

$this->debug will be a new promoted property defaulting to false in the component, and set to %kernel.debug% by the bundle.

This approach would also save 2 function calls in non-debug mode.

@tostiheld tostiheld closed this Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants