メインコンテンツまでスキップ

ログの出力方法

既定の AIBuds ロガーが記録する最小ログレベルと、使用する 1 つの出力先を選択します。

API Reference

フレームワーク

AIBudsLog.xcframework

宣言

Swift
/// The current log configuration.
static var logConfiguration: LogConfiguration { get }

/// Configures log storage, rotation, and output behavior.
final class LogConfiguration: NSObject {
    /// The severity threshold. Defaults to `.info`.
    var level: LogLevel

    /// The active output destination. Defaults to `.xlfacility`.
    var destination: LogDestination

    /// Relative log directory under Documents. Defaults to `.aibuds/logs`.
    var logsDirectory: String

    /// Maximum single file size. Defaults to 10 MB.
    var maxFileSize: UInt64

    /// Maximum retained age in days. Defaults to 3.
    var logFileMaxAge: Int
}

logConfigurationLogLevelLogDestination を参照してください。

ログレベル

level は記録対象となる最小の重要度です。これより低いレベルのログは破棄されます。

レベル用途
.verbose詳細な実行トレース。
.debug開発時の診断。
.info通常の進捗と動作情報。
.warn確認が必要となる可能性がある状態。
.errorアプリを継続できる可能性がある失敗。
.fatalアプリ終了につながる可能性がある重大な失敗。
.muteすべてのログ出力を無効化。

出力先

出力先出力場所エクスポート
.consoleXcode デバッガーコンソール非対応
.osloggeros_log を利用する Apple 統合ログ非対応
.file設定した Documents 相対ディレクトリ内のファイル対応
.xlfacilityAIBudsXLFacility 永続化プラグインプラグイン導入時に対応

使用例

Swift
import AIBudsLog
import AIBudsXLFacility

let configuration = AIBudsLogSDK.logConfiguration
configuration.level = .debug
configuration.destination = .xlfacility
configuration.logFileMaxAge = 7

AIBudsLogSDK.setXLFacilityPlugin(XLFacilitySDK.shared)

AIBudsLogSDK.logService.info(
    "SDK configured",
    subsystem: "com.example.app",
    category: "startup"
)

注意事項

  • 出力先の選択はプロセス全体に適用され、以前の出力先を置き換えます。複数の出力を同時に有効化する設定ではありません。
  • logsDirectory には Documents からの相対パスを指定します。先頭のスラッシュは SDK が削除します。
  • maxFileSizelogFileMaxAge に 0 以下の値を指定すると無視されます。
  • 公開 SDK は、リモートサーバーへのログ設定やカテゴリ別の有効/無効設定を公開していません。