1
我有一個基於Phalcon框架的現有應用程序,我的問題是Exceptions沒有被記錄到任何地方。Phalcon Framework上的異常記錄在哪裏?
當發生一些致命錯誤時,我可以在php erros上看到它,但不是例外。
默認日誌寫在哪裏?我可以爲日誌定義一個自定義路徑嗎?
感謝您的幫助!
我有一個基於Phalcon框架的現有應用程序,我的問題是Exceptions沒有被記錄到任何地方。Phalcon Framework上的異常記錄在哪裏?
當發生一些致命錯誤時,我可以在php erros上看到它,但不是例外。
默認日誌寫在哪裏?我可以爲日誌定義一個自定義路徑嗎?
感謝您的幫助!
您處理在try...catch
環例外:
try { ...run application here } catch (\Exception $e) { ...do logging here }
實例化建爾康記錄(注:我使用的文件適配器):
$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);
也許一個工作示例會幫助你。
似乎是一個很好的解決方案!謝謝! – viniciuswebdev