Repository navigation
Conversation
Add LogContext and LogContextProcessor to attach tracked context to every log record. Each key holds a single value managed via set()/unset()/clear(), and the processor merges them into the record context unless overridden explicitly. Includes tests and README docs.
Member
|
Not really what I had in mind I was more thinking of like this And there should probably be a log context contract that can be implemented so that we can create scoped log contexts and so forth. |
Member
|
An other option would be class DoSomethingHandler {
public function __construct(
#[LogContextScope('request')]
private LogContext $logContecxt,
) {}
public function __invoke($command) {
$this->logContext->add('plate', $command->plate);
.....
}
}
class DoSomethingCronHandler {
public function __construct(
#[LogContextScope('cron')]
private LogContext $logContecxt,
) {}
public function __invoke($command) {
$this->logContext->add('job', 'processing xxx');
.....
$this->logContext->remove('job', 'processing xxx');
}
}
class AuthMiddleware {
public function __construct(
#[LogContextScope('request')]
private LogContext $logContecxt,
) {}
public function handle(Request $request) {
if (authenticated()) {
$this->logContext->add('account', $account->id);
}
....
}
} |
Author
|
Of the two suggestions, I absolutely prefer the attribute variant. Seems both more robust and flexible, but also cleaner. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add LogContext and LogContextProcessor to attach tracked context to every log record. Each key holds a single value managed via set()/unset()/clear(), and the processor merges them into the record context unless overridden explicitly. Includes tests and README docs.