ログ記録と診断

Client SDK には、統合、デバッグ、および本番環境の監視に役立つ、設定可能なロギング機能が備わっています。ログ出力には、内部 HTTP トラフィック、API 呼び出し、WebRTC イベント、およびセッションのライフサイクルが含まれます。

ログレベル

クライアントの作成時に、ロギングレベルを設定します。利用可能なレベルは、詳細度の高い順から低い順に以下の通りです:

レベル 使用例
Verbose 完全なトレース出力 — 初期の統合作業中に役立つ
Debug 詳細な診断情報
Info 一般的な運用に関するお知らせ
Warn 動作を妨げない可能性のある問題
Error 失敗のみ
None ログ記録が無効になっています

構成

ログレベルを直接設定したり、内部ロガーを完全に無効にしたり、SDKの出力を独自のロギングインフラストラクチャに転送するカスタムロガー実装を提供したりすることができます。

const clientA = new VonageClient({
  loggingLevel: LoggingLevel.Error
});
// or setup custom loggers
const clientB = new VonageClient({
  disableInternalLogger: true,
  customLoggers: [
    {
      name: 'CustomLoggerOne',
      minLogLevel: LoggingLevel.Debug,
      topics: ['HTTP', Topics.API],
      onLog: (level, topic, message) => {
        console.log(`${level} ${topic.name} ${topic.tag} ${message}`);
      }
    },
    createVonageLogger('CustomLoggerTwo', (level, topic, message) => {
      console.log(`${level} ${topic.name} ${topic.tag} ${message}`);
    })
  ]
});

 val config = VGClientInitConfig(LoggingLevel.Verbose)
 val clientA = VonageClient(ctx, config)
 // or
 val clientB = VonageClient(
     ctx,
     VGClientInitConfig().apply {
         loggingLevel = LoggingLevel.Error
     }
 )
 // or setup custom loggers
 val clientC = VonageClient(
     ctx,
     VGClientInitConfig(
         disableInternalLogger = true,
         customLoggers = listOf(
             object : VonageLogger {
                 override val name: String = "CustomLoggerOne"
                 override val minLogLevel: LoggingLevel = LoggingLevel.Debug
                 override val topics: List<Topic> = listOf(Topic.HTTP, Topic.API).flatten()
                 override fun onLog(logLevel: LoggingLevel, topic: Topic, message: String, throwable: Throwable?) {
                     println("$logLevel ${topic.name} ${topic.tag} $message")
                 }
             },
             createVonageLogger("CustomLoggerTwo"){ logLevel, topic, message, _ ->
                 println("$logLevel ${topic.name} ${topic.tag} $message")
             }
         )
     )
 )
 LoggingLevel logLevelA = LoggingLevel.Verbose;
 VGClientInitConfig configA = new VGClientInitConfig(logLevelA);
 VonageClient clientA = VonageClient.createClient(ctx, configA);
 // or
 VGClientInitConfig configB = new VGClientInitConfig();
 configB.setLoggingLevel(LoggingLevel.Error);
 VonageClient clientB = VonageClient.createClient(ctx, configB);
 // or setup custom loggers
 VGClientInitConfig configC = new VGClientInitConfig();
 configC.setDisableInternalLogger(true);
 configC.setCustomLoggers(Arrays.asList(
         new VonageLogger() {
             @NotNull
             @Override
             public String getName() {
                 return "CustomLoggerOne";
             }

             @NotNull
             @Override
             public LoggingLevel getMinLogLevel() {
                 return LoggingLevel.Debug;
             }

             @NotNull
             @Override
             public List<Topic> getTopics() {
                 List<Topic> flattenedList = new ArrayList<>();
                 for (List<? extends Topic> subList : Arrays.asList(Topic.Companion.getHTTP(), Topic.Companion.getAPI())) {
                     flattenedList.addAll(subList);
                 }
                 return flattenedList;
             }

             @Override
             public void onLog(@NotNull LoggingLevel logLevel, @NotNull Topic topic, @NotNull String message, Throwable throwable) {
                 System.out.println(logLevel + " " + topic.getName() + " " + topic.getTag() + " " + message);
             }
         },
         createVonageLogger(
                 "CustomLoggerTwo",
                 null, null,
                 (logLevel, topic, message, throwable) -> {
                     System.out.println(logLevel + " " + topic.getName() + " " + topic.getTag() + " " + message);
                     return null;
                 }
         )
 ));
 VonageClient clientC = VonageClient.createClient(ctx, configC);

 let configA = VGClientInitConfig(loggingLevel: .verbose)
 let clientA = VGVonageClient(configA)
 // or
 let configB = VGClientInitConfig()
 configB.loggingLevel = .error
 let clientB = VGVonageClient(configB)
 // or setup custom loggers
 class MyLogger : NSObject, VGLogger {
     let name: String = "CustomLoggerOne"

     let minLogLevel: VGLoggingLevel = .debug

     let topics: [VGTopicGroup] = [VGTopic.HTTP, VGTopic.API]

     func didReceiveLog(logLevel: VGLoggingLevel, topic: VGTopic, message: String) {
         print("\(logLevel) \(topic.name) \(topic.tag) \(message)")
     }
 }
 let clientC = VGVonageClient(
     VGClientInitConfig(
         disableInternalLogger: true,
         customLoggers: [
             MyLogger(),
             VGCustomLogger("CustomLoggerTwo"){ logLevel,topic, message in
                 print("\(logLevel) \(topic.name) \(topic.tag) \(message)")
             }
         ]
     )
 )
 VGClientInitConfig *configA = [[VGClientInitConfig alloc]
                                initWithLoggingLevel:VGLoggingLevelVerbose
                                disableInternalLogger:VGDefaultDisableInternalLogger
                                customLoggers:[NSArray array]
                                region:VGDefaultRegion
                                apiUrl:nil
                                websocketUrl:nil
                                websocketPath:nil
                                enableWebSocketInvites:VGDefaultEnableWebsocketInvites
                                rtcStatsTelemetry:VGDefaultRtcStatsTelemetry
                                autoReconnectMedia:VGDefaultAutoReconnectMedia
                                enableNoiseSuppression:VGDefaultEnableNoiseSuppression
                                emergencyPrimaryRegion:nil
                                emergencySecondaryRegion:nil];
 VGVonageClient* clientA = [[VGVonageClient alloc] initWithConfig:configA];
 // or
 VGClientInitConfig *configB = [[VGClientInitConfig alloc] init];
 configB.loggingLevel = VGLoggingLevelError;
 VGVonageClient* clientB = [[VGVonageClient alloc] initWithConfig:configB];
 // or setup custom loggers
 // 1. Implement the VGLogger protocol
 id<VGLogger> customLoggerOne;
 // 2. Use the VGCustomLogger class
 VGCustomLogger *customLoggerTwo = [[VGCustomLogger alloc]
                                    initWithName:@"CustomLoggerTwo"
                                    minLogLevel:VGDefaultLoggingLevel()
                                    topics:VGDefaultTopics()
                                    onLog:^(VGLoggingLevel logLevel, VGTopic * _Nonnull topic, NSString * _Nonnull message) {
     NSLog(@"%ld %@ %@ %@", logLevel, topic.name, topic.tag, message);
 }];
 VGClientInitConfig *configC = [[VGClientInitConfig alloc] init];
 configC.disableInternalLogger = true;
 configC.customLoggers = [NSArray arrayWithObjects:customLoggerOne, customLoggerTwo, nil];
 VGVonageClient *clientC = [[VGVonageClient alloc] initWithConfig:configC];

カスタムロガー

カスタムロガーは、以下の情報を含む構造化されたログイベントを受け取ります:

  • レベル — ログエントリの重要度
  • トピック — ログソースを分類します(例: HTTP, API, WebRTC)
  • メッセージ — ログの内容

カスタムロガーを使用して、SDKの診断情報を既存のロギングツールやクラッシュレポートツール(Sentry、Datadog、Crashlyticsなど)と統合します。

トピックのフィルタリング

各ロガーは、ノイズを減らすために特定のトピックを購読することができます。利用可能なトピックグループには、以下のものがあります。 HTTP, API、など。トピックによるフィルタリングは、詳細な内部状態のログ記録を省き、ネットワークレベルのイベントのみを捕捉したいような本番環境において有用です。

推奨事項

  • 用途 Verbose 開発および初期の統合段階において、コールフローとイベントの順序を把握するため。
  • 用途 Error または Warn パフォーマンス上のオーバーヘッドを最小限に抑えるため、本番ビルドでは。
  • 詳細なログ出力は不要で、運用診断のみが必要な場合は、特定のトピックにフィルタリングされたカスタムロガーを使用してください。