Skip to content

Commit 3739bf5

Browse files
Dillon Nysdnys1
authored andcommitted
chore(auth): Use logger in example app
commit-id:d59a58c1
1 parent 45d8cf1 commit 3739bf5

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

packages/auth/amplify_auth_cognito/example/lib/main.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import 'package:go_router/go_router.dart';
2929

3030
import 'amplifyconfiguration.dart';
3131

32+
final AmplifyLogger _logger = AmplifyLogger('MyApp');
33+
3234
void main() {
35+
AmplifyLogger().logLevel = LogLevel.debug;
3336
runApp(const MyApp());
3437
}
3538

@@ -106,13 +109,13 @@ class _MyAppState extends State<MyApp> {
106109
// ),
107110
// );
108111
await Amplify.configure(amplifyconfig);
109-
safePrint('Successfully configured Amplify');
112+
_logger.debug('Successfully configured Amplify');
110113

111114
Amplify.Hub.listen(HubChannel.Auth, (event) {
112-
safePrint('Auth Event: $event');
115+
_logger.info('Auth Event: $event');
113116
});
114-
} on Exception catch (e) {
115-
safePrint('Configuring Amplify failed: $e');
117+
} on Exception catch (e, st) {
118+
_logger.error('Configuring Amplify failed', e, st);
116119
}
117120
}
118121

@@ -162,7 +165,9 @@ class _HomeScreenState extends State<HomeScreen> {
162165
final authSession = await Amplify.Auth.fetchAuthSession(
163166
options: const CognitoSessionOptions(getAWSCredentials: true),
164167
) as CognitoAuthSession;
165-
safePrint(authSession);
168+
_logger.info(
169+
prettyPrintJson(authSession.toJson()),
170+
);
166171
}
167172

168173
Future<void> _requestGreeting() async {

packages/auth/amplify_auth_cognito_dart/example/bin/example.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import 'package:cognito_example/amplifyconfiguration.dart';
2222
import 'package:cognito_example/common.dart';
2323

2424
Future<void> main() async {
25+
AWSLogger().logLevel = LogLevel.debug;
2526
try {
2627
await Amplify.addPlugin(
2728
AmplifyAuthCognitoDart(

packages/auth/amplify_auth_cognito_dart/example/web/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import 'package:amplify_core/amplify_core.dart';
1516
import 'package:example_common/example_common.dart';
1617

1718
import 'components/app_component.dart';
1819

1920
Future<void> main() async {
21+
AWSLogger().logLevel = LogLevel.debug;
2022
renderApp(AppComponent());
2123
}

0 commit comments

Comments
 (0)