Need to configure your backend?See Build a Backend →
ユーザーのみを許可リストとして設定する
Amplify認証済みユーザーごとに、独自のロギング設定を構成できます。これにより、ユーザーごとにより細かくデバッグの問題を有効にするのに役立ちます。
Amplify Authを使用してuserIDを取得する
必要に応じて、Amplify Authカテゴリを使用して、特定のユーザーのuserIdを取得できます。Amazon Cognitoコンソールにアクセスしてユーザープール内のUser IDを検査することで、userIdを取得することもできます。
Amplify.Auth.getCurrentUser( user.userId, error -> // failed to fetch user);Amplify.Auth.getCurrentUser({ user -> user.userId,{ // failed to get user})RxAmplify.Auth.getCurrentUser().subscribe( result -> result.userId, error -> // failed to get user );ユーザーのみを許可リストとして設定する
以下は、認証されたユーザーに対して異なるデフォルトおよびカテゴリログレベルを設定する例です。
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のマップを提供します。
Map<CategoryType, LogLevel> categoryOverrides = new HashMap<>();categoryOverrides.put(CategoryType.AUTH, LogLevel.VERBOSE);categoryOverrides.put(CategoryType.STORAGE, LogLevel.DEBUG);
UserLogLevel userLogLevel = new UserLogLevel(LogLevel.WARN, categoryOverrides);
Map<String, UserLogLevel> userOverrides = new HashMap<>();userOverrides.put("USER_ID", userLogLevel);
LoggingConstraints loggingConstraints = new LoggingConstraints(LogLevel.WARN, categoryOverrides, userOverrides);
AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (<log-group-name>, <region>, loggingConstraints);Amplify.addPlugin(new AWSCloudWatchLoggingPlugin(config));val categoryOverrides = mapOf(CategoryType.AUTH to LogLevel.VERBOSE, CategoryType.STORAGE to LogLevel.DEBUG)val userOverrides = mapOf("USER_ID" to UserLogLevel(LogLevel.WARN, categoryOverrides))
val loggingConstraints = LoggingConstraints(defaultLogLevel = LogLevel.WARN, userLogLevel = userOverrides)
val config = AWSCloudWatchLoggingPluginConfiguration(logGroupName = <log-group-name>, region = <region>, loggingConstraints = loggingConstraints)Amplify.addPlugin(AWSCloudWatchLoggingPlugin(config))Map<CategoryType, LogLevel> categoryOverrides = new HashMap<>();categoryOverrides.put(CategoryType.AUTH, LogLevel.VERBOSE);categoryOverrides.put(CategoryType.STORAGE, LogLevel.DEBUG);
UserLogLevel userLogLevel = new UserLogLevel(LogLevel.WARN, categoryOverrides);
Map<String, UserLogLevel> userOverrides = new HashMap<>();userOverrides.put("USER_ID", userLogLevel);
LoggingConstraints loggingConstraints = new LoggingConstraints(LogLevel.WARN, categoryOverrides, userOverrides);
AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (<log-group-name>, <region>, loggingConstraints);Amplify.addPlugin(new AWSCloudWatchLoggingPlugin(config));