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 compatibility with monolog 3.0 #1

Merged
merged 1 commit into from
Apr 5, 2023

Conversation

BernhardK91
Copy link
Collaborator

This PR adds compatibility with monolog 3.0.

I would recommend releasing this change as version 3.0.0. By that, all the "old" users that have "^1.1" in their composer.json will not be affected. User who want to use the monolog 3 version can do so, by adding "^3.0" to their composer.json. We could also use version 2.0.0 for that, but with version 3.0.0 we would show the compatibility with monolog 3 and can orient the versioning on the major and minor version of monolog.

Because the package does not have any tests yet, I was unable to test it by myself. I would test the 3.0 version as soon as it is released in one of our internal projects.

* Map Monolog\Logger levels to Datadog's default status type
*/
private const DATADOG_LEVEL_MAP = [
Logger::DEBUG => 'info',
Copy link
Collaborator Author

@BernhardK91 BernhardK91 Apr 4, 2023

Choose a reason for hiding this comment

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

Logger::DEBUG and the other constants are deprecated. Monolog now uses the Level enum. For PHP 8.0 compatibility, we are unable to use enum cases as array keys. This is only supported with PHP 8.2.

For that reason, I have removed the DATADOG_LEVEL_MAP and implemented the Monolog to Datadog level conversion directly in the method below as a match clause.

public function format(array $record): string
protected bool $includeStacktraces = true;

public function format(LogRecord $record): string
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Monolog changed the array to a class called LogRecord that implements ArrayAccess. So, it can be easily changed and still used as an array, at least for accessing the values.

Level::Debug, Level::Info => 'info',
Level::Notice, Level::Warning => 'warning',
Level::Error, Level::Alert, Level::Critical, Level::Emergency => 'error',
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the new implementation of the level converter from Monolog levels to Datadog levels.

In the last version, we also only provided 3 Datadog levels. I think more differentiated levels are possible, but for now, I kept it as it was before. We can add more Datadog levels later.

@sgoettsch sgoettsch merged commit 7bb1166 into sgoettsch:master Apr 5, 2023
@sgoettsch
Copy link
Owner

Thank you for helping to move this on

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.

2 participants