2016-09-26 97 views
3

我創建了一個調用第三方api的Bundle。Symfony Profiler的日誌數據

現在我想在Symfony Profiler中顯示接收到的數據。

我創建了一個CustomDataCollector(http://symfony.com/doc/current/profiler/data_collector.html)。這一切都很好。但是,我如何獲得或「保存」接收到的API響應?

我創建了以這樣的捲曲調用API服務:

$raw_response = curl_exec($ch); 

    $response = json_decode($raw_response); 

    if (property_exists($response, 'error') && $response->errors) { 
     return ['status'=>false, 'msg'=> (string)$response->errors[0]->description ] ; 
    } else { 
     return ['status'=>true, 'msg' =>'Send Successfully' ]; 
    } 

回答

4

我建議你使用不需要一個特定的收集器簡單的用例的logger服務。您可以到日誌提供額外的背景:

/** LoggerInterface */ 
$container->get('logger')->error('There was an error on the API call.', array(
    'description' => $response->errors[0]->description 
); 

logger數據保存到默認的配置文件。對於更高級的用例,您可能正在尋找處理器:http://symfony.com/doc/current/logging/processors.html