Java 用 Azure Storage クライアント ライブラリを使用したクライアント側のログ記録

Java プロジェクトに Azure Storage クライアント ライブラリのバイナリをインストールする方法については、GitHub の https://github.com/Azure/azure-storage-javaプロジェクトの readme ファイルを参照してください。 インストールが必要な付加的依存関係があれば、このファイルに記録されています。

クライアント側のログ記録を使用する場合、オプションの SLF4J 依存関係をインストールする必要があります。 SLF4Jは、クライアントアプリケーションから多くの一般的なJavaログフレームワークを簡単に使用できるようにするログファサードです。SLF4Jの詳細については、 SLF4Jのユーザーマニュアルを参照してください。 ストレージ SDK で SLF4J を使用する方法を簡単にテストするには、ストレージ クライアント プロジェクトのビルド パスに slf4j-api ファイルと slf4j-simple JAR ファイルを配置します。 その後、すべてのストレージ ログ メッセージがコンソールに送信されます。

次のサンプル Java コードは、ストレージ クライアント ログを既定でオフにする方法を示しています。静的メソッドの setLoggingEnabledByDefault を呼び出し、OperationContext オブジェクトを使用して特定の要求のログを有効にします。

// Set logging off by default.  
OperationContext.setLoggingEnabledByDefault(false);  
OperationContext ctx = new OperationContext();  
ctx.setLoggingEnabled(true);  
  
// Create an operation to add a new customer to the people table.  
TableOperation insertCustomer1 = TableOperation.insertOrReplace(customer1);  
  
// Submit the operation to the table service.  
table.execute(insertCustomer1, null, ctx);  
  

次の例は、slf4j-simple がコンソールに書き込むログ メッセージを示しています。

[main] INFO ROOT - {ceba5ec6...}: {Starting operation.}  
[main] INFO ROOT - {ceba5ec6...}: {Starting operation with location 'PRIMARY' per location mode 'PRIMARY_ONLY'.}  
[main] INFO ROOT - {ceba5ec6...}: {Starting request to 'http://storageaccountname2.table.core.windows.net/people(PartitionKey='Harp',RowKey='Walter')' at 'Tue, 08 Jul 2014 15:07:43 GMT'.}  
[main] INFO ROOT - {ceba5ec6...}: {Writing request data.}  
[main] INFO ROOT - {ceba5ec6...}: {Request data was written successfully.}  
[main] INFO ROOT - {ceba5ec6...}: {Waiting for response.}  
[main] INFO ROOT - {ceba5ec6...}: {Response received. Status code = '204', Request ID = '8f6ce566-3760-4733-a8da-a090e642286a', Content-MD5 = 'null', ETag = 'W/"datetime'2014-07-08T15%3A07%3A41.1177234Z'"'.}  
[main] INFO ROOT - {ceba5ec6...}: {Processing response headers.}  
[main] INFO ROOT - {ceba5ec6...}: {Response headers were processed successfully.}  
[main] INFO ROOT - {ceba5ec6...}: {Processing response body.}  
[main] INFO ROOT - {ceba5ec6...}: {Response body was parsed successfully.}  
[main] INFO ROOT - {ceba5ec6...}: {Operation completed.}  
  

GUID (ceba5ec6...は、クライアント側ストレージ ライブラリによってストレージ操作に割り当てられたクライアント要求 ID です。