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

Optionally allow specifying a log level map in the constructor. #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wimleers
Copy link
Owner

Copy link

@colinodell colinodell left a comment

Choose a reason for hiding this comment

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

The general approach of using a level map somewhere makes sense to me, because any methods that don't take an explicit level value (like debug() or hasDebugThatContains()) needs some way to know the values being used. I think my two biggest questions right now are:

  1. Is hasRecordThatPasses() truly the best place to perform that translation with the mapping? (Should we do it when the record is logged instead? Somewhere else? I don't know)
  2. Should we modify the string $level method params to accept ints too?

See my other thoughts in colinodell#2 (comment) - I'd love your feedback on them!

Given my comments in colinodell#2 (comment), I wonder if maybe we should just change `string $level

Comment on lines +150 to +152
$mappedLevel = $this->levelMap && array_key_exists($level, $this->levelMap)
? $this->levelMap[$level]
: $level;

Choose a reason for hiding this comment

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

I think this could be simplified to $mappedLevel = $this->levelMap[$level] ?? $level;

Comment on lines +71 to +78
/**
* @param null|array<string, mixed> $levelMap
* Keys are LogLevel::*, values are anything that can be an array key.
*/
public function __construct(?array $levelMap = NULL)
{
$this->levelMap = $levelMap;
}

Choose a reason for hiding this comment

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

I'd be okay with making this non-nullable. We could also change string in the docblock to LogLevel::* so that phpstan and psalm can help ensure the right keys are set by callers.

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