php - Cakephp 3.0: Turn off or disable Stack Trace runtime for specific controller -
i using cakephp 3.0 framework , need disable/turn off stack trace if exception or error occurs.
i tried solution given on turn on /off debug mode particular controller in cakephp.
if make change in myproject\config\app.php file, stack trace turned off controllers if set trace = false using following code specific controller error.trace set false stack trace not disabled.
<?php namespace app\shell; use cake\core\configure; use cake\console\shell; configure::write('error.trace', false); class myclassshell extends shell { public function main() { echo 'error.trace...' . configure::read('error.trace'); // output false ... } } ?>
its weird see if error.trace false still stack trace printed.
is other way disable stack trace in cakephp 3.0 specific controller/shell file instead of setting app.php ?
error options being read once
like of other options, error
options not runtime changeable via configure
class. while these options not being consumed, error handler reads them once @ bootstrapping time, , changing them @ later point has no effect, see applications config/bootstrap.php
// ... (new consoleerrorhandler(configure::read('error')))->register(); // ...
https://github.com/cakephp/app/blob/3.2.6/config/bootstrap.php#l116-l120
use custom error handler
in order change error handler behavior @ runtime, you'll need use custom/extended error handler supports that, , either change directly, or make read option dynamically. in order former work (which easier approach doesn't require reimplementing bunch of code), you'll have store reference handler can access @ later point.
a basic custom error handler supports changing options (* note untested example code)
namespace app\console; use cake\console\consoleerrorhandler; class appconsoleerrorhandler extends consoleerrorhandler { public function setoption($key, $value) { $this->_options[$key] = $value; } }
a quick , dirty solution store reference via configure
, like
use app\console\appconsoleerrorhandler; // ... if ($iscli) { $handler = new appconsoleerrorhandler(configure::read('error')); $handler->register(); configure::write('error.handler', $handler); } else { (new errorhandler(configure::read('error')))->register(); } // ...
and access , reconfigure in shell, like
$handler = configure::read('error.handler'); $handler->setoption('trace', false);
but don't on file level in example, in constructor or in main()
method.
Comments
Post a Comment