Java용 Azure Storage 클라이언트 라이브러리를 사용하여 클라이언트 쪽 로깅

Java 프로젝트에서 Azure Storage 클라이언트 라이브러리에 대한 이진 파일을 설치하는 방법에 대한 지침은 GitHub https://github.com/Azure/azure-storage-java의 프로젝트에 대한 추가 정보 파일을 참조하세요. 이 파일에서는 설치해야 하는 추가 종속성을 설명합니다.

클라이언트 쪽 로깅을 사용하려는 경우 선택적 SLF4J 종속성을 설치해야 합니다. SLF4J는 클라이언트 애플리케이션에서 많은 일반적인 Java 로깅 프레임워크를 쉽게 사용할 수 있는 로깅 외관입니다. SLF4J에 대한 자세한 내용은 SLF4J 사용자 설명서를 참조하세요. 스토리지 SDK에서 SLF4J를 사용하는 방법에 대한 간단한 테스트를 위해 slf4j-apislf4j-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입니다.