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

Request an example of how to add logging on exceptions found #286

Open
Guyverix opened this issue May 12, 2023 · 0 comments
Open

Request an example of how to add logging on exceptions found #286

Guyverix opened this issue May 12, 2023 · 0 comments

Comments

@Guyverix
Copy link

I have been using assert in my application and it works great! Thank you!

Where I have been running into trouble however is that I want to add logging so when an exception is thrown I can log it properly. I currently can log when a success happens inside the class, but I cannot get a log to be generated in the catch block.

I believe the issue is I simply do not know PHP well enough to do what I am attempting. Any guidance that can be given would be appreciated..

Here is what I am currently working with:

    public function test($data): void {
      try {
          $this->logger->info("TESTING INFO LOG " );
          Assert::isArray($data, 'POST `data` is not an array.');
          Assert::keyExists($data, "id", "POST `id=#` is mandatory to pass this test");
      }
      catch (InvalidArgumentException $exception) {
            $this->logger->critical("TESTING CRITICAL ERROR " );
            throw new ValidationException($exception->getMessage());
      }
    }

Is this actually possible to do without changing the code within the assert class itself? I would rather not mess with the class as I am still learning PHP and all of the gotchas..

I have tested this in PHP 7.4 with Ubuntu 20.04..

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

No branches or pull requests

1 participant