本文整理汇总了Java中com.facebook.internal.Logger.appendKeyValue方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.appendKeyValue方法的具体用法?Java Logger.appendKeyValue怎么用?Java Logger.appendKeyValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.internal.Logger
的用法示例。
在下文中一共展示了Logger.appendKeyValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializeToUrlConnection
import com.facebook.internal.Logger; //导入方法依赖的package包/类
final static void serializeToUrlConnection(RequestBatch requests, HttpURLConnection connection)
throws IOException, JSONException {
Logger logger = new Logger(LoggingBehavior.REQUESTS, "Request");
int numRequests = requests.size();
HttpMethod connectionHttpMethod = (numRequests == 1) ? requests.get(0).httpMethod : HttpMethod.POST;
connection.setRequestMethod(connectionHttpMethod.name());
URL url = connection.getURL();
logger.append("Request:\n");
logger.appendKeyValue("Id", requests.getId());
logger.appendKeyValue("URL", url);
logger.appendKeyValue("Method", connection.getRequestMethod());
logger.appendKeyValue("User-Agent", connection.getRequestProperty("User-Agent"));
logger.appendKeyValue("Content-Type", connection.getRequestProperty("Content-Type"));
connection.setConnectTimeout(requests.getTimeout());
connection.setReadTimeout(requests.getTimeout());
// If we have a single non-POST request, don't try to serialize anything or HttpURLConnection will
// turn it into a POST.
boolean isPost = (connectionHttpMethod == HttpMethod.POST);
if (!isPost) {
logger.log();
return;
}
connection.setDoOutput(true);
BufferedOutputStream outputStream = new BufferedOutputStream(connection.getOutputStream());
try {
Serializer serializer = new Serializer(outputStream, logger);
if (numRequests == 1) {
Request request = requests.get(0);
logger.append(" Parameters:\n");
serializeParameters(request.parameters, serializer);
logger.append(" Attachments:\n");
serializeAttachments(request.parameters, serializer);
if (request.graphObject != null) {
processGraphObject(request.graphObject, url.getPath(), serializer);
}
} else {
String batchAppID = getBatchAppId(requests);
if (Utility.isNullOrEmpty(batchAppID)) {
throw new FacebookException("At least one request in a batch must have an open Session, or a "
+ "default app ID must be specified.");
}
serializer.writeString(BATCH_APP_ID_PARAM, batchAppID);
// We write out all the requests as JSON, remembering which file attachments they have, then
// write out the attachments.
Bundle attachments = new Bundle();
serializeRequestsAsJSON(serializer, requests, attachments);
logger.append(" Attachments:\n");
serializeAttachments(attachments, serializer);
}
} finally {
outputStream.close();
}
logger.log();
}