Skip to content

Commit

Permalink
chore: added DartAppPathProvider and changed logger plugin constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
khatruong2009 committed Nov 8, 2023
1 parent 4aecab2 commit edece6d
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:amplify_logging_cloudwatch/src/amplify_log_stream_name_provider.dart';
import 'package:amplify_logging_cloudwatch/src/path_provider/flutter_path_provider.dart';
import 'package:aws_logging_cloudwatch/aws_logging_cloudwatch.dart';
import 'package:aws_logging_cloudwatch/src/queued_item_store/dart_queued_item_store.dart';

/// {@macro aws_logging_cloudwatch.cloudwatch_logger_plugin}
class AmplifyCloudWatchLoggerPlugin extends CloudWatchLoggerPlugin {
Expand All @@ -17,7 +16,6 @@ class AmplifyCloudWatchLoggerPlugin extends CloudWatchLoggerPlugin {
defaultLogStreamNameProvider:
AmplifyLogStreamNameProvider().defaultLogStreamName,
),
logStore: DartQueuedItemStore(FlutterPathProvider()),
remoteLoggingConstraintProvider:
pluginConfig.defaultRemoteConfiguration == null
? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import 'package:amplify_core/amplify_core.dart';
// ignore: invalid_use_of_internal_member, implementation_imports
import 'package:amplify_core/src/http/amplify_category_method.dart';
import 'package:aws_logging_cloudwatch/aws_logging_cloudwatch.dart';
import 'package:aws_logging_cloudwatch/src/queued_item_store/in_memory_queued_item_store.dart';
import 'package:aws_logging_cloudwatch/src/path_provider/app_path_provider.dart';
import 'package:aws_logging_cloudwatch/src/queued_item_store/dart_queued_item_store.dart';
import 'package:aws_logging_cloudwatch/src/queued_item_store/queued_item_store.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 @@ -54,8 +55,6 @@ class CloudWatchLoggerPlugin extends AWSLoggerPlugin
required CloudWatchPluginConfig pluginConfig,
RemoteLoggingConstraintProvider? remoteLoggingConstraintProvider,
CloudWatchLogStreamProvider? logStreamProvider,
// TODO(nikahsn): remove after moving queued item store implementation from
// amplify_logging_cloudwath to aws_logging_cloudwatch
@protected QueuedItemStore? logStore,
}) : _enabled = pluginConfig.enable,
_pluginConfig = pluginConfig,
Expand All @@ -71,10 +70,7 @@ class CloudWatchLoggerPlugin extends AWSLoggerPlugin
region: pluginConfig.region,
credentialsProvider: credentialsProvider,
),
// TODO(nikahsn): move queued item store implementation from
// amplify_logging_cloudwath to aws_logging_cloudwatch and use
// DartQueueItemStore instead of InMemoryQueuedItemStore
_logStore = logStore ?? InMemoryQueuedItemStore(),
_logStore = logStore ?? DartQueuedItemStore(const DartAppPathProvider()),
_logStreamProvider = logStreamProvider ??
DefaultCloudWatchLogStreamProvider(
logGroupName: pluginConfig.logGroupName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

export 'app_path_provider_stub.dart'
if (dart.library.html) 'app_path_provider_html.dart'
if (dart.library.io) 'app_path_provider_io.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';

/// {@template aws_logging_cloudwatch.app_path_provider}
/// Provides App paths for amplify_storage_s3_dart package.
/// {@endtemplate}
class DartAppPathProvider implements AppPathProvider {
/// {@macro aws_logging_cloudwatch.app_path_provider}
const DartAppPathProvider();

@override
Future<String> getApplicationSupportPath() async {
return '';
}

@override
Future<String> getTemporaryPath() async {
return '';
}
}
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 'dart:io';

import 'package:amplify_core/amplify_core.dart';

/// {@template aws_logging_cloudwatch.app_path_provider}
/// Provides App paths for amplify_storage_s3_dart package.
/// {@endtemplate}
class DartAppPathProvider implements AppPathProvider {
/// {@macro aws_logging_cloudwatch.app_path_provider}
const DartAppPathProvider();

@override
Future<String> getApplicationSupportPath() async {
return Directory.current.path;
}

@override
Future<String> getTemporaryPath() async {
return Directory.systemTemp.path;
}
}
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 'package:amplify_core/amplify_core.dart';

/// {@template aws_logging_cloudwatch.app_path_provider}
/// Provides App paths for amplify_storage_s3_dart package.
/// {@endtemplate}
class DartAppPathProvider implements AppPathProvider {
/// {@macro aws_logging_cloudwatch.app_path_provider}
const DartAppPathProvider();

@override
Future<String> getApplicationSupportPath() async {
throw UnimplementedError(
'getApplicationSupportPath() has not been implemented in the current platform.',
);
}

@override
Future<String> getTemporaryPath() async {
throw UnimplementedError(
'getTemporaryPath() has not been implemented in the current platform.',
);
}
}

0 comments on commit edece6d

Please sign in to comment.