Phalcon Framework 上记录的异常在哪里?
Where are exceptions logged on Phalcon Framework?
我有一个基于 Phalcon 框架的现有应用程序,我的问题是没有在任何地方记录异常。
当发生某些致命错误时,我可以在 php 错误中看到它,但在异常中看不到。
默认日志写在哪里?我可以为日志定义自定义路径吗?
感谢您的帮助!
Phalcon PHP 异常记录
您在 try...catch
循环中处理异常:
try { ...run application here } catch ( \Exception $e ) { ...do logging here }
实例化内置的 Phalcon 记录器(注意:我正在使用文件适配器):
$logger = new \Phalcon\Logger\Adapter\File("../app/logs/exceptions.log");
记录异常消息:
$logger->log($e->getMessage());
解决方案总结
$logger = new \Phalcon\Logger\Adapter\File("../app/logs/test.log");
try { ...run application here } catch ( \Exception $e ) {
$logger->log($e->getMessage());
}
我的代码中有以下异常处理程序:
// We register the events manager
$di->set('dispatcher', function () {
// Create an event manager
$eventsManager = new EventsManager();
// Attach a listener
$eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
// Alternative way, controller or action doesn't exist
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
$strUrlRelocate = "http://" . $_SERVER['SERVER_NAME'] . "/";
header("Location:" . $strUrlRelocate);
break;
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
error_log($exception);
break;
}
});
$dispatcher = new MvcDispatcher();
// Bind the eventsManager to the view component
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}, true);
也许一个工作示例会对您有所帮助。
我有一个基于 Phalcon 框架的现有应用程序,我的问题是没有在任何地方记录异常。
当发生某些致命错误时,我可以在 php 错误中看到它,但在异常中看不到。
默认日志写在哪里?我可以为日志定义自定义路径吗?
感谢您的帮助!
Phalcon PHP 异常记录
您在 try...catch
循环中处理异常:
try { ...run application here } catch ( \Exception $e ) { ...do logging here }
实例化内置的 Phalcon 记录器(注意:我正在使用文件适配器):
$logger = new \Phalcon\Logger\Adapter\File("../app/logs/exceptions.log");
记录异常消息:
$logger->log($e->getMessage());
解决方案总结
$logger = new \Phalcon\Logger\Adapter\File("../app/logs/test.log");
try { ...run application here } catch ( \Exception $e ) {
$logger->log($e->getMessage());
}
我的代码中有以下异常处理程序:
// We register the events manager $di->set('dispatcher', function () { // Create an event manager $eventsManager = new EventsManager(); // Attach a listener $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) { // Alternative way, controller or action doesn't exist switch ($exception->getCode()) { case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND: $strUrlRelocate = "http://" . $_SERVER['SERVER_NAME'] . "/"; header("Location:" . $strUrlRelocate); break; case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND: error_log($exception); break; } }); $dispatcher = new MvcDispatcher(); // Bind the eventsManager to the view component $dispatcher->setEventsManager($eventsManager); return $dispatcher; }, true);
也许一个工作示例会对您有所帮助。