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): default remote config #3643

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5ad91cf
feat(logging): add cloudwatch logger plugin
Aug 16, 2023
53ef002
feat(logging): default remote config
khatruong2009 Aug 28, 2023
0506c77
chore: dart FileStorage refactor and unit tests added
khatruong2009 Sep 13, 2023
f379e7c
chore: made the Future.delayed more explicit
khatruong2009 Sep 13, 2023
8de0309
chore: added flutter path provider to amplify_logging_cloudwatch
khatruong2009 Sep 14, 2023
55dfab9
chore: removed fluter dependency
khatruong2009 Sep 15, 2023
0ef2b3d
chore: remove flutter plugin files from git ignore now that flutter d…
khatruong2009 Sep 15, 2023
53c66a3
chore: changed names of file storage functions, logger level, and rem…
khatruong2009 Sep 15, 2023
507d086
chore: remove flutter plugin .gitignore
khatruong2009 Sep 15, 2023
bc635d8
chore: Added completer, removed conditional import, added closeable, …
khatruong2009 Sep 15, 2023
1e3c6ae
chore: updated aft workflows
khatruong2009 Sep 15, 2023
6c03448
Update packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/plu…
khatruong2009 Sep 15, 2023
03a8455
Update packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/plu…
khatruong2009 Sep 15, 2023
05391d8
chore: removed manual toJson and replace jsonSerializable with zAmpli…
khatruong2009 Sep 15, 2023
009b0d8
Update packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/fil…
khatruong2009 Sep 15, 2023
9ecffbf
Update packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/fil…
khatruong2009 Sep 15, 2023
8750486
chore: use factory constructor and _fileStorage might be null in remo…
khatruong2009 Sep 15, 2023
f513d0e
chore: fixed local storage variable and method name and also added an…
khatruong2009 Sep 19, 2023
c12af97
Update packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/rem…
khatruong2009 Sep 19, 2023
2cbb9b7
Update packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/rem…
khatruong2009 Sep 19, 2023
cad71d6
Update packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/rem…
khatruong2009 Sep 19, 2023
5f185c4
Update packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/rem…
khatruong2009 Sep 19, 2023
b77c8ae
chore: add AWSSerializable and added comment to test to address Futur…
khatruong2009 Sep 19, 2023
da94fe3
chore: fixed some formatting and removed todo comment
khatruong2009 Sep 19, 2023
0f3bae3
chore: removed unnecessary comments
khatruong2009 Sep 20, 2023
04b78d4
Update packages/logging_cloudwatch/aws_logging_cloudwatch/test/remote…
khatruong2009 Sep 20, 2023
0cba479
Update packages/logging_cloudwatch/aws_logging_cloudwatch/test/remote…
khatruong2009 Sep 20, 2023
3c2b666
Update packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/fil…
khatruong2009 Sep 20, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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:path_provider/path_provider.dart';

/// {@template flutter_path_provider}
/// A [AppPathProvider] that uses the [path_provider](https://pub.dev/packages/path_provider)
/// package to get the application support and temporary paths.
/// {@endtemplate}
class FlutterPathProvider implements AppPathProvider {
@override
Future<String> getApplicationSupportPath() async {
final directory = await getApplicationSupportDirectory();
return directory.path;
}

@override
Future<String> getTemporaryPath() async {
final directory = await getTemporaryDirectory();
return directory.path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import 'dart:async';
import 'dart:math';

import 'package:aws_common/aws_common.dart';
import 'package:amplify_core/amplify_core.dart';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: not sure what this change is for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump^

import 'package:aws_logging_cloudwatch/aws_logging_cloudwatch.dart';
import 'package:aws_logging_cloudwatch/src/sdk/cloud_watch_logs.dart';
import 'package:aws_logging_cloudwatch/src/stoppable_timer.dart';
Expand Down Expand Up @@ -76,9 +76,9 @@ class CloudWatchLoggerPlugin extends AWSLoggerPlugin
region: pluginConfig.region,
credentialsProvider: credentialsProvider,
) {
_timer = pluginConfig.flushIntervalInSeconds > Duration.zero
_timer = pluginConfig.flushInterval > Duration.zero
khatruong2009 marked this conversation as resolved.
Show resolved Hide resolved
? StoppableTimer(
duration: pluginConfig.flushIntervalInSeconds,
duration: pluginConfig.flushInterval,
callback: _startSyncingIfNotInProgress,
onError: _onTimerError,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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:aws_logging_cloudwatch/src/file_storage/file_storage_stub.dart'
if (dart.library.io) 'file_storage_vm.dart'
if (dart.library.html) 'file_storage_web.dart';

/// File storage interface for saving and loading constraint locally
abstract interface class FileStorage {
/// Default Constructor or FileStorage
factory FileStorage(AppPathProvider pathProvider) = FileStorageImpl;

/// Save constraint locally to file
Future<void> save(String fileName, String data);

/// Load constraint from file
Future<String?> load(String fileName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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:aws_logging_cloudwatch/src/file_storage/file_storage.dart';

/// File storage implementation for saving and loading constraint locally
class FileStorageImpl implements FileStorage {
/// File storage implementation for saving and loading constraint locally
FileStorageImpl(this.pathProvider);

/// Path provider to get the application support path
final AppPathProvider pathProvider;

@override
Future<String?> load(String fileName) async {
throw UnimplementedError();
}

@override
Future<void> save(String fileName, String content) async {
throw UnimplementedError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'dart:io';

import 'package:amplify_core/amplify_core.dart';
import 'package:aws_logging_cloudwatch/src/file_storage/file_storage.dart';
import 'package:path/path.dart' as p;

/// File storage implementation for saving and loading constraint locally
class FileStorageImpl implements FileStorage {
/// File storage implementation for saving and loading constraint locally
FileStorageImpl(this.pathProvider);

/// Path provider to get the application support path
final AppPathProvider pathProvider;

@override
Future<String?> load(String fileName) async {
final file =
File(p.join(await pathProvider.getApplicationSupportPath(), fileName));
if (await file.exists()) {
return file.readAsString();
}
return null;
}

@override
Future<void> save(String fileName, String content) async {
final file =
File(p.join(await pathProvider.getApplicationSupportPath(), fileName));
await file.writeAsString(content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'dart:html';

import 'package:amplify_core/amplify_core.dart';
import 'package:aws_logging_cloudwatch/src/file_storage/file_storage.dart';

/// File storage implementation for saving and loading constraint locally
class FileStorageImpl implements FileStorage {
/// File storage implementation for saving and loading constraint locally
// ignore: avoid_unused_constructor_parameters
FileStorageImpl(AppPathProvider pathProvider);

static const _prefix = 'aws.cloudwatch';
khatruong2009 marked this conversation as resolved.
Show resolved Hide resolved

@override
Future<String?> load(String fileName) async {
return window.localStorage['$_prefix.$fileName'];
}

@override
Future<void> save(String fileName, String content) async {
window.localStorage['$_prefix.$fileName'] = content;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:aws_common/aws_common.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:aws_logging_cloudwatch/aws_logging_cloudwatch.dart';

part 'plugin_config.g.dart';

/// {@template aws_logging_cloudwatch.cloudwatch_logger_plugin_configuration}
/// The configuration for `CloudWatchLoggerPlugin`.
/// {@endtemplate}
khatruong2009 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -15,7 +17,7 @@ class CloudWatchLoggerPluginConfiguration with AWSDebuggable {
required this.localLoggingConstraint,
this.enable = true,
this.localStoreMaxSizeInMB = 5,
this.flushIntervalInSeconds = const Duration(seconds: 60),
this.flushInterval = const Duration(seconds: 60),
khatruong2009 marked this conversation as resolved.
Show resolved Hide resolved
this.defaultRemoteConfiguration,
});

Expand All @@ -31,8 +33,8 @@ class CloudWatchLoggerPluginConfiguration with AWSDebuggable {
/// The max size of the local store in MB to be used for storing logs locally.
final int localStoreMaxSizeInMB;

/// The duration in seconds for sending locally stored logs to CloudWatch.
final Duration flushIntervalInSeconds;
/// The duration for sending locally stored logs to CloudWatch.
final Duration flushInterval;

/// {@macro aws_logging_cloudwatch.logging_constraint}
final LoggingConstraint localLoggingConstraint;
Expand All @@ -47,13 +49,59 @@ class CloudWatchLoggerPluginConfiguration with AWSDebuggable {
/// {@template aws_logging_cloudwatch.logging_constraint}
/// The logging constraint for sending logs to CloudWatch.
/// {@endtemplate}
class LoggingConstraint with AWSDebuggable {
@zAmplifySerializable
class LoggingConstraint with AWSDebuggable, AWSSerializable {
/// {@macro aws_logging_cloudwatch.logging_constraint}
const LoggingConstraint({this.defaultLogLevel = LogLevel.error});
const LoggingConstraint({
this.defaultLogLevel = LogLevel.error,
this.categoryLogLevel,
this.userLogLevel,
});

/// Converts a [Map] to an [LoggingConstraint] instance.
khatruong2009 marked this conversation as resolved.
Show resolved Hide resolved
factory LoggingConstraint.fromJson(Map<String, dynamic> json) =>
_$LoggingConstraintFromJson(json);

/// Converts an [LoggingConstraint] instance to a [Map].
@override
Map<String, dynamic> toJson() => _$LoggingConstraintToJson(this);

/// The default [LogLevel] for sending logs to CloudWatch.
final LogLevel defaultLogLevel;

/// The [LogLevel] for different categories.
final Map<String, LogLevel>? categoryLogLevel;

/// The [LogLevel] for different users.
final Map<String, UserLogLevel>? userLogLevel;

@override
String get runtimeTypeName => 'LoggingConstraint';
}

/// The logging constraint for user specific log level.
@zAmplifySerializable
class UserLogLevel with AWSDebuggable, AWSSerializable {
/// The logging constraint for user specific log level.
const UserLogLevel({
this.defaultLogLevel,
this.categoryLogLevel,
});

///Converts a [Map] to a [UserLogLevel] instance.
factory UserLogLevel.fromJson(Map<String, dynamic> json) =>
_$UserLogLevelFromJson(json);

/// Converts a [UserLogLevel] instance to a [Map].
@override
Map<String, dynamic> toJson() => _$UserLogLevelToJson(this);

/// The default [LogLevel] for sending logs to CloudWatch.
final LogLevel? defaultLogLevel;

/// The [LogLevel] for different categories.
final Map<String, LogLevel>? categoryLogLevel;

@override
String get runtimeTypeName => 'UserLogLevel';
}

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

Loading
Loading