Symfony Profiler 的日志数据

Log data for Symfony Profiler

我创建了一个调用第三方的 Bundle api。

现在我想在 Symfony Profiler 中显示接收到的数据。

我创建了一个 CustomDataCollector (http://symfony.com/doc/current/profiler/data_collector.html)。一切正常。但是我怎样才能得到或 "save" 收到的 api 的响应?

我创建了一个使用 curl 调用 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' ];
    }

我建议您将 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