PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

[FIXED] Don't log some kind of exceptions

 February 20, 2022     cakephp, cakephp-3.0, exception, logging     No comments   

Issue

I am running a pretty big application, with a few thousand users and I like to check the log files (almost) daily, to see if something has gone wrong.

Fortunately the system is quite stable, but I am having a lot of Invalid CSRF token, Record not found in table X with primary key [NULL], (and so on) errors. I usually ignore that kind of errors, since there is not much that I can do to avoid them.

Is there a way to tell the logger not to save those kind of exceptions in my log files?


Solution

Check the Error section of your applications app.php configuration file, specifically the explanation for the skipLog option.

[...]

skipLog - array - List of exceptions to skip for logging. Exceptions that extend one of the listed exceptions will also be skipped for logging. E.g.:

'skipLog' => ['Cake\Network\Exception\NotFoundException', 'Cake\Network\Exception\UnauthorizedException']

[...]

You'd want to skip \Cake\Network\Exception\NotFoundException and \Cake\Network\Exception\InvalidCsrfTokenException.

If you need more fine-grained control, then you'd have to create a custom error handler and override for example BaseErrorHandler::_logException() where you could inspect the exception and act accordingly.

See also

  • Cookbook > Error & Exception Handling > Error & Exception Configuration
  • Cookbook > Error & Exception Handling > Creating your Own Error Handler


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing