本文整理匯總了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();
}