Need to configure your backend?See Build a Backend →
ユーザーのみを許可リストとして設定する
Amplify認証済みユーザーごとに、独自のロギング設定を構成できます。これにより、ユーザーごとにより細かくデバッグの問題を有効にするのに役立ちます。
Amplify Authを使用してuserIDを取得する
必要に応じて、Amplify Authカテゴリを使用して、特定のユーザーのuserIdを取得できます。Amazon Cognitoコンソールにアクセスしてユーザープール内のUser IDを検査することで、userIdを取得することもできます。
Amplify.Auth.getCurrentUser().userIdユーザーのみを許可リストとして設定する
以下は、認証されたユーザーに対して異なるデフォルトおよびカテゴリログレベルを設定する例です。
userLogLevelセクションを追加し、各ユーザー識別子に対してdefaultLogLevelとcategoryLogLevelを追加します。
{ "awsCloudWatchLoggingPlugin": { "enable": true, "logGroupName": "<log-group-name>", "region": "<region>", "localStoreMaxSizeInMB": 1, "flushIntervalInSeconds": 60, "loggingConstraints": { "defaultLogLevel": "ERROR", "userLogLevel": { "xyz-123": { "defaultLogLevel": "DEBUG", "categoryLogLevel": { "Storage": "VERBOSE", "Api": "VERBOSE" } } } } }}AWSCloudWatchLoggingPluginの初期化と設定時に、UserLogLevelの辞書を提供します。
do { let categoryLogLevels: [String: LogLevel] = ["Storage": .verbose, "API": .verbose] let userLogLevel = UserLogLevel(defaultLogLevel: .debug, categoryLogLevel: categoryLogLevels) let userLogLevels: [String: UserLogLevel] = ["xyz-123": userLogLevel] let loggingConstraints = LoggingConstraints(defaultLogLevel: .warn, userLogLevel: userLogLevels) let loggingConfiguration = AWSCloudWatchLoggingPluginConfiguration(logGroupName: "<log-group-name>", region: "<region>", loggingConstraints: loggingConstraints) let loggingPlugin = AWSCloudWatchLoggingPlugin(loggingPluginConfiguration: loggingConfiguration) try Amplify.add(plugin: loggingPlugin)} catch { assert(false, "Error initializing Amplify: \(error)")}