Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(logging): add LoggingConfig to AmplifyConfig #3770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/amplify_core/lib/amplify_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export 'src/config/analytics/analytics_config.dart';
export 'src/config/api/api_config.dart';
export 'src/config/auth/auth_config.dart';
export 'src/config/config_map.dart';
export 'src/config/logging/logging_config.dart';
export 'src/config/notifications/notifications_config.dart';
export 'src/config/storage/storage_config.dart';

Expand Down
7 changes: 7 additions & 0 deletions packages/amplify_core/lib/src/config/amplify_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AmplifyConfig with AWSEquatable<AmplifyConfig>, AWSSerializable {
this.api,
this.analytics,
this.auth,
this.logging,
this.notifications,
this.storage,
});
Expand All @@ -39,6 +40,9 @@ class AmplifyConfig with AWSEquatable<AmplifyConfig>, AWSSerializable {
/// The Auth category configuration, if available.
final AuthConfig? auth;

/// The Logging configuration, if available.
final LoggingConfig? logging;

/// The Notifications category configuration, if available.
final NotificationsConfig? notifications;

Expand All @@ -52,6 +56,7 @@ class AmplifyConfig with AWSEquatable<AmplifyConfig>, AWSSerializable {
api,
analytics,
auth,
logging,
notifications,
storage,
];
Expand All @@ -60,6 +65,7 @@ class AmplifyConfig with AWSEquatable<AmplifyConfig>, AWSSerializable {
ApiConfig? api,
AnalyticsConfig? analytics,
AuthConfig? auth,
LoggingConfig? logging,
NotificationsConfig? notifications,
StorageConfig? storage,
}) {
Expand All @@ -69,6 +75,7 @@ class AmplifyConfig with AWSEquatable<AmplifyConfig>, AWSSerializable {
api: api ?? this.api,
analytics: analytics ?? this.analytics,
auth: auth ?? this.auth,
logging: logging ?? this.logging,
notifications: notifications ?? this.notifications,
storage: storage ?? this.storage,
);
Expand Down
4 changes: 4 additions & 0 deletions packages/amplify_core/lib/src/config/amplify_config.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:amplify_core/src/config/amplify_plugin_config.dart';
import 'package:amplify_core/src/config/analytics/pinpoint_config.dart';
import 'package:amplify_core/src/config/api/aws_api_config.dart';
import 'package:amplify_core/src/config/auth/cognito_config.dart';
import 'package:amplify_core/src/config/logging/cloudwatch_logging_config.dart';
import 'package:amplify_core/src/config/notifications/notifications_pinpoint_config.dart';
import 'package:amplify_core/src/config/storage/s3_config.dart';

Expand All @@ -25,6 +26,9 @@ const _defaultPlugins = <AmplifyPluginConfigFactory>[

// Storage
S3PluginConfigFactory(),

// Logging
CloudWatchPluginConfigFactory(),
];

/// {@template amplify_core.amplify_plugin_config_factory}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
import 'package:meta/meta.dart';

part 'cloudwatch_logging_config.g.dart';

/// {@template amplify_core.cloudwatch_plugin_config_factory}
/// Configuration factory for [CloudWatchPluginConfig].
/// {@endtemplate}
@internal
class CloudWatchPluginConfigFactory
extends AmplifyPluginConfigFactory<CloudWatchPluginConfig> {
/// {@macro amplify_core.cloudwatch_plugin_config_factory}
const CloudWatchPluginConfigFactory();

@override
CloudWatchPluginConfig build(Map<String, Object?> json) {
return CloudWatchPluginConfig.fromJson(json);
}

@override
String get name => CloudWatchPluginConfig.pluginKey;
}

/// {@template amplify_core.cloudwatch_plugin_config}
/// The AWS CloudWatch plugin configuration.
/// {@endtemplate}
@zAmplifySerializable
class CloudWatchPluginConfig
with AWSEquatable<CloudWatchPluginConfig>, AWSSerializable
implements AmplifyPluginConfig {
/// {@macro amplify_core.cloudwatch_plugin_config}
const CloudWatchPluginConfig({
this.enable = true,
required this.logGroupName,
required this.region,
this.localStoreMaxSizeInMB = 5,
this.flushIntervalInSeconds = 60,
this.defaultRemoteConfiguration,
this.loggingConstraints = const LoggingConstraints(),
});

factory CloudWatchPluginConfig.fromJson(Map<String, Object?> json) =>
_$CloudWatchPluginConfigFromJson(json);

/// The plugin's configuration key.
static const pluginKey = 'cloudWatchLoggerPluginConfiguration';

final bool enable;
final String logGroupName;
final String region;
final int localStoreMaxSizeInMB;
final int flushIntervalInSeconds;
final DefaultRemoteConfiguration? defaultRemoteConfiguration;
final LoggingConstraints loggingConstraints;

@override
String get name => pluginKey;

@override
List<Object?> get props => [
enable,
logGroupName,
region,
localStoreMaxSizeInMB,
flushIntervalInSeconds,
defaultRemoteConfiguration,
loggingConstraints,
];

CloudWatchPluginConfig copyWith({
bool? enable,
String? logGroupName,
String? region,
int? localStoreMaxSizeInMB,
int? flushIntervalInSeconds,
DefaultRemoteConfiguration? defaultRemoteConfiguration,
LoggingConstraints? loggingConstraints,
}) {
return CloudWatchPluginConfig(
enable: enable ?? this.enable,
logGroupName: logGroupName ?? this.logGroupName,
region: region ?? this.region,
localStoreMaxSizeInMB:
localStoreMaxSizeInMB ?? this.localStoreMaxSizeInMB,
flushIntervalInSeconds:
flushIntervalInSeconds ?? this.flushIntervalInSeconds,
defaultRemoteConfiguration:
defaultRemoteConfiguration ?? this.defaultRemoteConfiguration,
loggingConstraints: loggingConstraints ?? this.loggingConstraints,
);
}

@override
Map<String, Object?> toJson() => _$CloudWatchPluginConfigToJson(this);
}

@zAmplifySerializable
class DefaultRemoteConfiguration
with
AWSEquatable<DefaultRemoteConfiguration>,
AWSSerializable<Map<String, Object?>> {
const DefaultRemoteConfiguration({
required this.endpoint,
this.refreshIntervalInSeconds = 1200,
});

factory DefaultRemoteConfiguration.fromJson(Map<String, Object?> json) =>
_$DefaultRemoteConfigurationFromJson(json);

final String endpoint;
final int refreshIntervalInSeconds;

@override
List<Object?> get props => [endpoint, refreshIntervalInSeconds];

@override
Map<String, Object?> toJson() => _$DefaultRemoteConfigurationToJson(this);
}

@zAmplifySerializable
class LoggingConstraints
with
AWSEquatable<LoggingConstraints>,
AWSSerializable<Map<String, Object?>> {
const LoggingConstraints({
this.defaultLogLevel = LogLevel.error,
this.categoryLogLevel = const {},
this.userLogLevel = const {},
});

factory LoggingConstraints.fromJson(Map<String, Object?> json) =>
_$LoggingConstraintsFromJson(json);

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

@override
List<Object?> get props => [
defaultLogLevel,
categoryLogLevel,
userLogLevel,
];

@override
Map<String, Object?> toJson() => _$LoggingConstraintsToJson(this);
}

@zAmplifySerializable
class UserLogLevel
with AWSEquatable<UserLogLevel>, AWSSerializable<Map<String, Object?>> {
const UserLogLevel({
this.defaultLogLevel = LogLevel.error,
this.categoryLogLevel = const {},
});

factory UserLogLevel.fromJson(Map<String, Object?> json) =>
_$UserLogLevelFromJson(json);

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

@override
List<Object?> get props => [defaultLogLevel, categoryLogLevel];

@override
Map<String, Object?> toJson() => _$UserLogLevelToJson(this);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading