Skip to content

Commit

Permalink
feat: implement _isLoggable and corrected categoryLogLevel in UserLog…
Browse files Browse the repository at this point in the history
…Level class
  • Loading branch information
khatruong2009 committed Oct 4, 2023
1 parent 6640039 commit 0cc7564
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class UserLogLevel
_$UserLogLevelFromJson(json);

final LogLevel defaultLogLevel;
final Map<String, String> categoryLogLevel;
final Map<String, LogLevel> categoryLogLevel;

@override
List<Object?> get props => [defaultLogLevel, categoryLogLevel];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,38 @@ class CloudWatchLoggerPlugin extends AWSLoggerPlugin
if (!_enabled) {
return false;
}

final loggingConstraint = _getLoggingConstraint();

String? userId;

Amplify.Hub.listen(HubChannel.Auth, (AuthHubEvent event) async {
if (event.type == AuthHubEventType.signedOut ||
event.type == AuthHubEventType.userDeleted ||
event.type == AuthHubEventType.sessionExpired) {
userId = null;
}
if (event.type == AuthHubEventType.signedIn) {
userId = event.payload?.userId;
}
});

if (loggingConstraint.userLogLevel.containsKey(userId)) {
final userLevel = loggingConstraint.userLogLevel[userId]!;

if (userLevel.categoryLogLevel.containsKey(logEntry.loggerName)) {
return logEntry.level >=
userLevel.categoryLogLevel[logEntry.loggerName]!;
}

return logEntry.level >= userLevel.defaultLogLevel;
}

if (loggingConstraint.categoryLogLevel.containsKey(logEntry.loggerName)) {
return logEntry.level >=
loggingConstraint.categoryLogLevel[logEntry.loggerName]!;
}

return logEntry.level >= loggingConstraint.defaultLogLevel;
}

Expand Down

0 comments on commit 0cc7564

Please sign in to comment.