From 1c11bc3a88c3a82019882687a5bef4f755e5c5b4 Mon Sep 17 00:00:00 2001 From: Vasiliy Ditsyak Date: Mon, 17 Jun 2024 15:31:17 +0200 Subject: [PATCH] improve logging --- packages/generator_tests/pubspec.lock | 8 +- .../test/doc/annotateless_test.dart | 40 +++++- .../test/doc/array_nullable_test.dart | 40 +++++- .../test/doc/delivery_list_test.dart | 116 ++++++++++++++--- .../test/doc/freezed_class_output_test.dart | 40 +++++- .../test/doc/freezed_class_test.dart | 40 +++++- .../test/doc/generic_status_list_test.dart | 40 +++++- .../test/doc/generic_test.dart | 40 +++++- .../generator_tests/test/doc/group_test.dart | 76 +++++++++-- .../doc/login_extended_nullable_test.dart | 40 +++++- .../test/doc/login_extended_output_test.dart | 40 +++++- .../test/doc/login_extended_test.dart | 40 +++++- .../test/doc/login_output_test.dart | 40 +++++- .../generator_tests/test/doc/login_test.dart | 42 +++++- .../test/doc/mailing_list_test.dart | 40 +++++- .../test/doc/profile_test.dart | 76 +++++++++-- .../test/doc/renamed_basic_output_test.dart | 40 +++++- .../test/doc/renamed_basic_test.dart | 40 +++++- .../test/doc/url_list_output_test.dart | 52 +++++++- .../test/doc/user_profile_output_test.dart | 52 +++++++- .../test/doc/user_profile_test.dart | 52 +++++++- .../lib/reactive_forms_annotations.dart | 2 + .../reactive_forms_annotations/pubspec.yaml | 3 +- .../lib/docs/animated_url_list/url.gform.dart | 52 +++++++- .../animated_url_list/url_output.gform.dart | 52 +++++++- .../docs/annotateless/annotateless.gform.dart | 40 +++++- .../annotateless_output.gform.dart | 40 +++++- .../array_nullable/array_nullable.gform.dart | 40 +++++- .../delivery_list/delivery_list.gform.dart | 116 ++++++++++++++--- .../lib/docs/freezed/freezed_class.gform.dart | 40 +++++- .../freezed/freezed_class_output.gform.dart | 40 +++++- .../example/lib/docs/freezed2/test.gform.dart | 40 +++++- .../lib/docs/generic/generic.gform.dart | 40 +++++- .../generic_status_list.gform.dart | 40 +++++- .../example/lib/docs/group/group.gform.dart | 76 +++++++++-- .../example/lib/docs/login/login.gform.dart | 40 +++++- .../example/lib/docs/login/login_form.dart | 10 +- .../lib/docs/login/login_output.gform.dart | 40 +++++- .../login_extended/login_extended.gform.dart | 40 +++++- .../login_extended_output.gform.dart | 40 +++++- .../login_extended_nullable.gform.dart | 40 +++++- .../login_extended_nullable_output.gform.dart | 40 +++++- .../docs/mailing_list/mailing_list.gform.dart | 40 +++++- .../model_extends/model_extends.gform.dart | 40 +++++- .../model_implements.gform.dart | 40 +++++- .../example/lib/docs/nested/nested.gform.dart | 120 ++++++++++++++++-- .../lib/docs/profile/profile.gform.dart | 76 +++++++++-- .../renamed_basic/renamed_basic.gform.dart | 40 +++++- .../renamed_basic_output.gform.dart | 40 +++++- .../docs/user_profile/user_profile.gform.dart | 52 +++++++- .../user_profile_output.gform.dart | 52 +++++++- .../lib/src/form_generator.dart | 15 ++- .../reactive_forms/reactive_form_builder.dart | 30 +++++ 53 files changed, 2171 insertions(+), 239 deletions(-) diff --git a/packages/generator_tests/pubspec.lock b/packages/generator_tests/pubspec.lock index 3adc3c52..d2609130 100644 --- a/packages/generator_tests/pubspec.lock +++ b/packages/generator_tests/pubspec.lock @@ -85,10 +85,10 @@ packages: dependency: transitive description: name: build_runner_core - sha256: "6d6ee4276b1c5f34f21fdf39425202712d2be82019983d52f351c94aafbc2c41" + sha256: "30859c90e9ddaccc484f56303931f477b1f1ba2bab74aa32ed5d6ce15870f8cf" url: "https://pub.dev" source: hosted - version: "7.2.10" + version: "7.2.8" build_test: dependency: "direct dev" description: @@ -338,10 +338,10 @@ packages: dependency: "direct dev" description: name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + sha256: "04094f2eb032cbb06c6f6e8d3607edcfcb0455e2bb6cbc010cb01171dcb64e6d" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.1.1" matcher: dependency: transitive description: diff --git a/packages/generator_tests/test/doc/annotateless_test.dart b/packages/generator_tests/test/doc/annotateless_test.dart index 339fdeac..d951955d 100644 --- a/packages/generator_tests/test/doc/annotateless_test.dart +++ b/packages/generator_tests/test/doc/annotateless_test.dart @@ -188,6 +188,34 @@ class _AnnotatelessFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logAnnotatelessForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -225,6 +253,8 @@ class _AnnotatelessFormBuilderState extends State { } } +final _logAnnotatelessForm = Logger('AnnotatelessForm'); + class AnnotatelessForm implements FormModel { AnnotatelessForm( this.form, @@ -378,9 +408,11 @@ class AnnotatelessForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AnnotatelessForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAnnotatelessForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Annotateless(email: _emailValue, password: _passwordValue); } @@ -426,6 +458,8 @@ class AnnotatelessForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAnnotatelessForm.info('Errors'); + _logAnnotatelessForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/array_nullable_test.dart b/packages/generator_tests/test/doc/array_nullable_test.dart index e11a0b2f..fb5888b5 100644 --- a/packages/generator_tests/test/doc/array_nullable_test.dart +++ b/packages/generator_tests/test/doc/array_nullable_test.dart @@ -203,6 +203,34 @@ class _ArrayNullableFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logArrayNullableForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -240,6 +268,8 @@ class _ArrayNullableFormBuilderState extends State { } } +final _logArrayNullableForm = Logger('ArrayNullableForm'); + class ArrayNullableForm implements FormModel { ArrayNullableForm( this.form, @@ -843,9 +873,11 @@ class ArrayNullableForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ArrayNullableForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logArrayNullableForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return ArrayNullable( emailList: _emailListValue, @@ -896,6 +928,8 @@ class ArrayNullableForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logArrayNullableForm.info('Errors'); + _logArrayNullableForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/delivery_list_test.dart b/packages/generator_tests/test/doc/delivery_list_test.dart index bb35d548..40ab7af1 100644 --- a/packages/generator_tests/test/doc/delivery_list_test.dart +++ b/packages/generator_tests/test/doc/delivery_list_test.dart @@ -236,6 +236,34 @@ class _DeliveryListFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logDeliveryListForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -273,6 +301,8 @@ class _DeliveryListFormBuilderState extends State { } } +final _logDeliveryListForm = Logger('DeliveryListForm'); + class DeliveryListForm implements FormModel { DeliveryListForm( this.form, @@ -680,9 +710,11 @@ class DeliveryListForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'DeliveryListForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logDeliveryListForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return DeliveryList( deliveryList: _deliveryListValue, clientList: _clientListValue); @@ -735,6 +767,8 @@ class DeliveryListForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logDeliveryListForm.info('Errors'); + _logDeliveryListForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -790,6 +824,8 @@ class DeliveryListForm implements FormModel { disabled: false); } +final _logDeliveryPointForm = Logger('DeliveryPointForm'); + class DeliveryPointForm implements FormModel { DeliveryPointForm( this.form, @@ -973,9 +1009,11 @@ class DeliveryPointForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'DeliveryPointForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logDeliveryPointForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return DeliveryPoint(name: _nameValue, address: _addressValue); } @@ -1023,6 +1061,8 @@ class DeliveryPointForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logDeliveryPointForm.info('Errors'); + _logDeliveryPointForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1070,6 +1110,8 @@ class DeliveryPointForm implements FormModel { disabled: false); } +final _logAddressForm = Logger('AddressForm'); + class AddressForm implements FormModel { AddressForm( this.form, @@ -1277,9 +1319,11 @@ class AddressForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AddressForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAddressForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Address(street: _streetValue, city: _cityValue); } @@ -1325,6 +1369,8 @@ class AddressForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAddressForm.info('Errors'); + _logAddressForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1378,6 +1424,8 @@ class AddressForm implements FormModel { disabled: false); } +final _logClientForm = Logger('ClientForm'); + class ClientForm implements FormModel { ClientForm( this.form, @@ -1653,9 +1701,11 @@ class ClientForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ClientForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logClientForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Client( clientType: _clientTypeValue, name: _nameValue, notes: _notesValue); @@ -1702,6 +1752,8 @@ class ClientForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logClientForm.info('Errors'); + _logClientForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -2035,6 +2087,34 @@ class _StandaloneDeliveryPointFormBuilderState widget.initState?.call(context, _formModel); + _logStandaloneDeliveryPointForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -2072,6 +2152,8 @@ class _StandaloneDeliveryPointFormBuilderState } } +final _logStandaloneDeliveryPointForm = Logger('StandaloneDeliveryPointForm'); + class StandaloneDeliveryPointForm implements FormModel { StandaloneDeliveryPointForm( @@ -2256,9 +2338,11 @@ class StandaloneDeliveryPointForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'StandaloneDeliveryPointForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logStandaloneDeliveryPointForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return DeliveryPoint(name: _nameValue, address: _addressValue); } @@ -2306,6 +2390,8 @@ class StandaloneDeliveryPointForm if (currentForm.valid) { onValid(model); } else { + _logStandaloneDeliveryPointForm.info('Errors'); + _logStandaloneDeliveryPointForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/freezed_class_output_test.dart b/packages/generator_tests/test/doc/freezed_class_output_test.dart index b9b53564..51a5118d 100644 --- a/packages/generator_tests/test/doc/freezed_class_output_test.dart +++ b/packages/generator_tests/test/doc/freezed_class_output_test.dart @@ -202,6 +202,34 @@ class _FreezedClassOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logFreezedClassOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -239,6 +267,8 @@ class _FreezedClassOFormBuilderState extends State { } } +final _logFreezedClassOForm = Logger('FreezedClassOForm'); + class FreezedClassOForm implements FormModel { FreezedClassOForm( @@ -919,9 +949,11 @@ class FreezedClassOForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'FreezedClassOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logFreezedClassOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return FreezedClassOOutput(_genderValue, _genderRValue, id: _idValue, @@ -972,6 +1004,8 @@ class FreezedClassOForm if (currentForm.valid) { onValid(model); } else { + _logFreezedClassOForm.info('Errors'); + _logFreezedClassOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/freezed_class_test.dart b/packages/generator_tests/test/doc/freezed_class_test.dart index 05aeb0d9..0f8b505d 100644 --- a/packages/generator_tests/test/doc/freezed_class_test.dart +++ b/packages/generator_tests/test/doc/freezed_class_test.dart @@ -202,6 +202,34 @@ class _FreezedClassFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logFreezedClassForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -239,6 +267,8 @@ class _FreezedClassFormBuilderState extends State { } } +final _logFreezedClassForm = Logger('FreezedClassForm'); + class FreezedClassForm implements FormModel { FreezedClassForm( this.form, @@ -730,9 +760,11 @@ class FreezedClassForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'FreezedClassForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logFreezedClassForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return FreezedClass(_genderValue, id: _idValue, @@ -782,6 +814,8 @@ class FreezedClassForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logFreezedClassForm.info('Errors'); + _logFreezedClassForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/generic_status_list_test.dart b/packages/generator_tests/test/doc/generic_status_list_test.dart index de8217db..377d2264 100644 --- a/packages/generator_tests/test/doc/generic_status_list_test.dart +++ b/packages/generator_tests/test/doc/generic_status_list_test.dart @@ -185,6 +185,34 @@ class _StatusListFormBuilderState widget.initState?.call(context, _formModel); + _logStatusListForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -222,6 +250,8 @@ class _StatusListFormBuilderState } } +final _logStatusListForm = Logger('StatusListForm'); + class StatusListForm implements FormModel, StatusList> { StatusListForm( @@ -348,9 +378,11 @@ class StatusListForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'StatusListForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logStatusListForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return StatusList(list: _listValue); } @@ -396,6 +428,8 @@ class StatusListForm if (currentForm.valid) { onValid(model); } else { + _logStatusListForm.info('Errors'); + _logStatusListForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/generic_test.dart b/packages/generator_tests/test/doc/generic_test.dart index 674b676f..35516940 100644 --- a/packages/generator_tests/test/doc/generic_test.dart +++ b/packages/generator_tests/test/doc/generic_test.dart @@ -180,6 +180,34 @@ class _TagsFormBuilderState extends State> { widget.initState?.call(context, _formModel); + _logTagsForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -217,6 +245,8 @@ class _TagsFormBuilderState extends State> { } } +final _logTagsForm = Logger('TagsForm'); + class TagsForm implements FormModel, Tags> { TagsForm( this.form, @@ -329,9 +359,11 @@ class TagsForm implements FormModel, Tags> { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'TagsForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logTagsForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Tags(tags: _tagsValue); } @@ -377,6 +409,8 @@ class TagsForm implements FormModel, Tags> { if (currentForm.valid) { onValid(model); } else { + _logTagsForm.info('Errors'); + _logTagsForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/group_test.dart b/packages/generator_tests/test/doc/group_test.dart index c06b0283..81fd40ba 100644 --- a/packages/generator_tests/test/doc/group_test.dart +++ b/packages/generator_tests/test/doc/group_test.dart @@ -227,6 +227,34 @@ class _GroupFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logGroupForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -264,6 +292,8 @@ class _GroupFormBuilderState extends State { } } +final _logGroupForm = Logger('GroupForm'); + class GroupForm implements FormModel { GroupForm( this.form, @@ -675,9 +705,11 @@ class GroupForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'GroupForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logGroupForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Group( personal: _personalValue, @@ -735,6 +767,8 @@ class GroupForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logGroupForm.info('Errors'); + _logGroupForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -778,6 +812,8 @@ class GroupForm implements FormModel { disabled: false); } +final _logPersonalForm = Logger('PersonalForm'); + class PersonalForm implements FormModel { PersonalForm( this.form, @@ -985,9 +1021,11 @@ class PersonalForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'PersonalForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logPersonalForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Personal(name: _nameValue, email: _emailValue); } @@ -1033,6 +1071,8 @@ class PersonalForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logPersonalForm.info('Errors'); + _logPersonalForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1086,6 +1126,8 @@ class PersonalForm implements FormModel { disabled: false); } +final _logPhoneForm = Logger('PhoneForm'); + class PhoneForm implements FormModel { PhoneForm( this.form, @@ -1293,9 +1335,11 @@ class PhoneForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'PhoneForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logPhoneForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Phone(phoneNumber: _phoneNumberValue, countryIso: _countryIsoValue); } @@ -1341,6 +1385,8 @@ class PhoneForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logPhoneForm.info('Errors'); + _logPhoneForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1394,6 +1440,8 @@ class PhoneForm implements FormModel { disabled: false); } +final _logAddressForm = Logger('AddressForm'); + class AddressForm implements FormModel { AddressForm( this.form, @@ -1696,9 +1744,11 @@ class AddressForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AddressForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAddressForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Address(street: _streetValue, city: _cityValue, zip: _zipValue); } @@ -1744,6 +1794,8 @@ class AddressForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAddressForm.info('Errors'); + _logAddressForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/login_extended_nullable_test.dart b/packages/generator_tests/test/doc/login_extended_nullable_test.dart index 50797dfe..e946732c 100644 --- a/packages/generator_tests/test/doc/login_extended_nullable_test.dart +++ b/packages/generator_tests/test/doc/login_extended_nullable_test.dart @@ -207,6 +207,34 @@ class _LoginExtendedNullableFormBuilderState widget.initState?.call(context, _formModel); + _logLoginExtendedNullableForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -244,6 +272,8 @@ class _LoginExtendedNullableFormBuilderState } } +final _logLoginExtendedNullableForm = Logger('LoginExtendedNullableForm'); + class LoginExtendedNullableForm implements FormModel { LoginExtendedNullableForm( @@ -927,9 +957,11 @@ class LoginExtendedNullableForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginExtendedNullableForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginExtendedNullableForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return LoginExtendedNullable( email: _emailValue, @@ -982,6 +1014,8 @@ class LoginExtendedNullableForm if (currentForm.valid) { onValid(model); } else { + _logLoginExtendedNullableForm.info('Errors'); + _logLoginExtendedNullableForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/login_extended_output_test.dart b/packages/generator_tests/test/doc/login_extended_output_test.dart index 9f67d8fb..73b631c2 100644 --- a/packages/generator_tests/test/doc/login_extended_output_test.dart +++ b/packages/generator_tests/test/doc/login_extended_output_test.dart @@ -256,6 +256,34 @@ class _LoginExtendedOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logLoginExtendedOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -293,6 +321,8 @@ class _LoginExtendedOFormBuilderState extends State { } } +final _logLoginExtendedOForm = Logger('LoginExtendedOForm'); + class LoginExtendedOForm implements FormModel { LoginExtendedOForm( @@ -976,9 +1006,11 @@ class LoginExtendedOForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginExtendedOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginExtendedOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return LoginExtendedOOutput( email: _emailValue, @@ -1033,6 +1065,8 @@ class LoginExtendedOForm if (currentForm.valid) { onValid(model); } else { + _logLoginExtendedOForm.info('Errors'); + _logLoginExtendedOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/login_extended_test.dart b/packages/generator_tests/test/doc/login_extended_test.dart index 5f3e27fe..8caccc0c 100644 --- a/packages/generator_tests/test/doc/login_extended_test.dart +++ b/packages/generator_tests/test/doc/login_extended_test.dart @@ -255,6 +255,34 @@ class _LoginExtendedFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logLoginExtendedForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -292,6 +320,8 @@ class _LoginExtendedFormBuilderState extends State { } } +final _logLoginExtendedForm = Logger('LoginExtendedForm'); + class LoginExtendedForm implements FormModel { LoginExtendedForm( this.form, @@ -948,9 +978,11 @@ class LoginExtendedForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginExtendedForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginExtendedForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return LoginExtended( email: _emailValue, @@ -1005,6 +1037,8 @@ class LoginExtendedForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logLoginExtendedForm.info('Errors'); + _logLoginExtendedForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/login_output_test.dart b/packages/generator_tests/test/doc/login_output_test.dart index 0adc9002..10698964 100644 --- a/packages/generator_tests/test/doc/login_output_test.dart +++ b/packages/generator_tests/test/doc/login_output_test.dart @@ -205,6 +205,34 @@ class _LoginOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logLoginOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -242,6 +270,8 @@ class _LoginOFormBuilderState extends State { } } +final _logLoginOForm = Logger('LoginOForm'); + class LoginOForm implements FormModel { LoginOForm( this.form, @@ -447,9 +477,11 @@ class LoginOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return LoginOOutput(email: _emailValue, password: _passwordValue); } @@ -495,6 +527,8 @@ class LoginOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logLoginOForm.info('Errors'); + _logLoginOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/login_test.dart b/packages/generator_tests/test/doc/login_test.dart index e7949911..747364e1 100644 --- a/packages/generator_tests/test/doc/login_test.dart +++ b/packages/generator_tests/test/doc/login_test.dart @@ -9,7 +9,7 @@ void main() { group('doc', () { test( 'Login', - () async { + () async { return testGenerator( fileName: fileName, model: ''' @@ -202,6 +202,34 @@ class _LoginFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logLoginForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -239,6 +267,8 @@ class _LoginFormBuilderState extends State { } } +final _logLoginForm = Logger('LoginForm'); + class LoginForm implements FormModel { LoginForm( this.form, @@ -392,9 +422,11 @@ class LoginForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Login(email: _emailValue, password: _passwordValue); } @@ -440,6 +472,8 @@ class LoginForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logLoginForm.info('Errors'); + _logLoginForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/mailing_list_test.dart b/packages/generator_tests/test/doc/mailing_list_test.dart index d0d509da..9c120e88 100644 --- a/packages/generator_tests/test/doc/mailing_list_test.dart +++ b/packages/generator_tests/test/doc/mailing_list_test.dart @@ -197,6 +197,34 @@ class _MailingListFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logMailingListForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -234,6 +262,8 @@ class _MailingListFormBuilderState extends State { } } +final _logMailingListForm = Logger('MailingListForm'); + class MailingListForm implements FormModel { MailingListForm( this.form, @@ -360,9 +390,11 @@ class MailingListForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'MailingListForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logMailingListForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return MailingList(emailList: _emailListValue); } @@ -408,6 +440,8 @@ class MailingListForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logMailingListForm.info('Errors'); + _logMailingListForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/profile_test.dart b/packages/generator_tests/test/doc/profile_test.dart index 6e9d6998..a21e0378 100644 --- a/packages/generator_tests/test/doc/profile_test.dart +++ b/packages/generator_tests/test/doc/profile_test.dart @@ -425,6 +425,34 @@ class _ProfileFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logProfileForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -462,6 +490,8 @@ class _ProfileFormBuilderState extends State { } } +final _logProfileForm = Logger('ProfileForm'); + class ProfileForm implements FormModel { ProfileForm( this.form, @@ -1193,9 +1223,11 @@ class ProfileForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ProfileForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logProfileForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Profile(_idValue, anotherId: _anotherIdValue, @@ -1256,6 +1288,8 @@ class ProfileForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logProfileForm.info('Errors'); + _logProfileForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1349,6 +1383,8 @@ class ProfileForm implements FormModel { disabled: false); } +final _logIncidenceFilterForm = Logger('IncidenceFilterForm'); + class IncidenceFilterForm implements FormModel { IncidenceFilterForm( @@ -1790,9 +1826,11 @@ class IncidenceFilterForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'IncidenceFilterForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logIncidenceFilterForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return IncidenceFilter( isMobilityEnabled: _isMobilityEnabledValue, @@ -1844,6 +1882,8 @@ class IncidenceFilterForm if (currentForm.valid) { onValid(model); } else { + _logIncidenceFilterForm.info('Errors'); + _logIncidenceFilterForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1925,6 +1965,8 @@ class IncidenceFilterForm disabled: false); } +final _logThresholdSettingForm = Logger('ThresholdSettingForm'); + class ThresholdSettingForm implements FormModel { ThresholdSettingForm( @@ -2079,9 +2121,11 @@ class ThresholdSettingForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ThresholdSettingForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logThresholdSettingForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return ThresholdSetting(isEnabled: _isEnabledValue, value: _valueValue); } @@ -2127,6 +2171,8 @@ class ThresholdSettingForm if (currentForm.valid) { onValid(model); } else { + _logThresholdSettingForm.info('Errors'); + _logThresholdSettingForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -2181,6 +2227,8 @@ class ThresholdSettingForm disabled: false); } +final _logTimerSettingForm = Logger('TimerSettingForm'); + class TimerSettingForm implements FormModel { TimerSettingForm( this.form, @@ -2334,9 +2382,11 @@ class TimerSettingForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'TimerSettingForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logTimerSettingForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return TimerSetting(isEnabled: _isEnabledValue, value: _valueValue); } @@ -2382,6 +2432,8 @@ class TimerSettingForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logTimerSettingForm.info('Errors'); + _logTimerSettingForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/renamed_basic_output_test.dart b/packages/generator_tests/test/doc/renamed_basic_output_test.dart index 99ab3cb4..12ed9923 100644 --- a/packages/generator_tests/test/doc/renamed_basic_output_test.dart +++ b/packages/generator_tests/test/doc/renamed_basic_output_test.dart @@ -196,6 +196,34 @@ class _SomeWiredNameFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logSomeWiredNameForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -233,6 +261,8 @@ class _SomeWiredNameFormBuilderState extends State { } } +final _logSomeWiredNameForm = Logger('SomeWiredNameForm'); + class SomeWiredNameForm implements FormModel { SomeWiredNameForm( @@ -439,9 +469,11 @@ class SomeWiredNameForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'SomeWiredNameForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logSomeWiredNameForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return RenamedBasicOOutput(email: _emailValue, password: _passwordValue); } @@ -487,6 +519,8 @@ class SomeWiredNameForm if (currentForm.valid) { onValid(model); } else { + _logSomeWiredNameForm.info('Errors'); + _logSomeWiredNameForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/renamed_basic_test.dart b/packages/generator_tests/test/doc/renamed_basic_test.dart index bda46439..2381d8b2 100644 --- a/packages/generator_tests/test/doc/renamed_basic_test.dart +++ b/packages/generator_tests/test/doc/renamed_basic_test.dart @@ -196,6 +196,34 @@ class _SomeWiredNameFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logSomeWiredNameForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -233,6 +261,8 @@ class _SomeWiredNameFormBuilderState extends State { } } +final _logSomeWiredNameForm = Logger('SomeWiredNameForm'); + class SomeWiredNameForm implements FormModel { SomeWiredNameForm( this.form, @@ -386,9 +416,11 @@ class SomeWiredNameForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'SomeWiredNameForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logSomeWiredNameForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return RenamedBasic(email: _emailValue, password: _passwordValue); } @@ -434,6 +466,8 @@ class SomeWiredNameForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logSomeWiredNameForm.info('Errors'); + _logSomeWiredNameForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/url_list_output_test.dart b/packages/generator_tests/test/doc/url_list_output_test.dart index 3f925492..41c409ef 100644 --- a/packages/generator_tests/test/doc/url_list_output_test.dart +++ b/packages/generator_tests/test/doc/url_list_output_test.dart @@ -194,6 +194,34 @@ class _UrlOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logUrlOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -231,6 +259,8 @@ class _UrlOFormBuilderState extends State { } } +final _logUrlOForm = Logger('UrlOForm'); + class UrlOForm implements FormModel { UrlOForm( this.form, @@ -426,9 +456,11 @@ class UrlOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UrlOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUrlOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return UrlOOutput(urlList: _urlListValue); } @@ -478,6 +510,8 @@ class UrlOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUrlOForm.info('Errors'); + _logUrlOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -525,6 +559,8 @@ class UrlOForm implements FormModel { disabled: false); } +final _logUrlEntityOForm = Logger('UrlEntityOForm'); + class UrlEntityOForm implements FormModel { UrlEntityOForm( this.form, @@ -730,9 +766,11 @@ class UrlEntityOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UrlEntityOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUrlEntityOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return UrlEntityOOutput(label: _labelValue, url: _urlValue); } @@ -778,6 +816,8 @@ class UrlEntityOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUrlEntityOForm.info('Errors'); + _logUrlEntityOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/user_profile_output_test.dart b/packages/generator_tests/test/doc/user_profile_output_test.dart index 64eb52ca..509c9a18 100644 --- a/packages/generator_tests/test/doc/user_profile_output_test.dart +++ b/packages/generator_tests/test/doc/user_profile_output_test.dart @@ -222,6 +222,34 @@ class _UserProfileOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logUserProfileOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -259,6 +287,8 @@ class _UserProfileOFormBuilderState extends State { } } +final _logUserProfileOForm = Logger('UserProfileOForm'); + class UserProfileOForm implements FormModel { UserProfileOForm( this.form, @@ -701,9 +731,11 @@ class UserProfileOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UserProfileOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUserProfileOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return UserProfileOOutput( id: _idValue, @@ -758,6 +790,8 @@ class UserProfileOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUserProfileOForm.info('Errors'); + _logUserProfileOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -820,6 +854,8 @@ class UserProfileOForm implements FormModel { disabled: false); } +final _logAddressOForm = Logger('AddressOForm'); + class AddressOForm implements FormModel { AddressOForm( this.form, @@ -1121,9 +1157,11 @@ class AddressOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AddressOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAddressOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return AddressOOutput( street: _streetValue, city: _cityValue, zip: _zipValue); @@ -1170,6 +1208,8 @@ class AddressOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAddressOForm.info('Errors'); + _logAddressOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/generator_tests/test/doc/user_profile_test.dart b/packages/generator_tests/test/doc/user_profile_test.dart index 9391abe3..74330873 100644 --- a/packages/generator_tests/test/doc/user_profile_test.dart +++ b/packages/generator_tests/test/doc/user_profile_test.dart @@ -220,6 +220,34 @@ class _UserProfileFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logUserProfileForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -257,6 +285,8 @@ class _UserProfileFormBuilderState extends State { } } +final _logUserProfileForm = Logger('UserProfileForm'); + class UserProfileForm implements FormModel { UserProfileForm( this.form, @@ -647,9 +677,11 @@ class UserProfileForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UserProfileForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUserProfileForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return UserProfile( id: _idValue, @@ -704,6 +736,8 @@ class UserProfileForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUserProfileForm.info('Errors'); + _logUserProfileForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -766,6 +800,8 @@ class UserProfileForm implements FormModel { disabled: false); } +final _logAddressForm = Logger('AddressForm'); + class AddressForm implements FormModel { AddressForm( this.form, @@ -1068,9 +1104,11 @@ class AddressForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AddressForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAddressForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Address(street: _streetValue, city: _cityValue, zip: _zipValue); } @@ -1116,6 +1154,8 @@ class AddressForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAddressForm.info('Errors'); + _logAddressForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_annotations/lib/reactive_forms_annotations.dart b/packages/reactive_forms_annotations/lib/reactive_forms_annotations.dart index efd9ff7a..8f00ef05 100644 --- a/packages/reactive_forms_annotations/lib/reactive_forms_annotations.dart +++ b/packages/reactive_forms_annotations/lib/reactive_forms_annotations.dart @@ -1,6 +1,8 @@ library reactive_forms_annotations; +export 'dart:developer' hide Flow; export 'package:flutter/widgets.dart'; +export 'package:logging/logging.dart'; export 'package:reactive_forms/reactive_forms.dart'; export 'package:reactive_forms/src/widgets/reactive_form_pop_scope.dart'; export 'src/reactive_form_annotation.dart'; diff --git a/packages/reactive_forms_annotations/pubspec.yaml b/packages/reactive_forms_annotations/pubspec.yaml index acfad5f7..6dd9f9db 100644 --- a/packages/reactive_forms_annotations/pubspec.yaml +++ b/packages/reactive_forms_annotations/pubspec.yaml @@ -22,9 +22,10 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - reactive_forms: ^17.0.0 flutter: sdk: flutter + logging: 1.1.1 + reactive_forms: ^17.0.0 dev_dependencies: flutter_lints: ^3.0.2 diff --git a/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url.gform.dart b/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url.gform.dart index 281ed593..737257ab 100644 --- a/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url.gform.dart @@ -142,6 +142,34 @@ class _UrlFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logUrlForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -179,6 +207,8 @@ class _UrlFormBuilderState extends State { } } +final _logUrlForm = Logger('UrlForm'); + class UrlForm implements FormModel { UrlForm( this.form, @@ -373,9 +403,11 @@ class UrlForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UrlForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUrlForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Url(urlList: _urlListValue); } @@ -425,6 +457,8 @@ class UrlForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUrlForm.info('Errors'); + _logUrlForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -472,6 +506,8 @@ class UrlForm implements FormModel { disabled: false); } +final _logUrlEntityForm = Logger('UrlEntityForm'); + class UrlEntityForm implements FormModel { UrlEntityForm( this.form, @@ -625,9 +661,11 @@ class UrlEntityForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UrlEntityForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUrlEntityForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return UrlEntity(label: _labelValue, url: _urlValue); } @@ -673,6 +711,8 @@ class UrlEntityForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUrlEntityForm.info('Errors'); + _logUrlEntityForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url_output.gform.dart index a596ee63..9d51f0c3 100644 --- a/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url_output.gform.dart @@ -142,6 +142,34 @@ class _UrlOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logUrlOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -179,6 +207,8 @@ class _UrlOFormBuilderState extends State { } } +final _logUrlOForm = Logger('UrlOForm'); + class UrlOForm implements FormModel { UrlOForm( this.form, @@ -374,9 +404,11 @@ class UrlOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UrlOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUrlOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return UrlOOutput(urlList: _urlListValue); } @@ -426,6 +458,8 @@ class UrlOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUrlOForm.info('Errors'); + _logUrlOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -473,6 +507,8 @@ class UrlOForm implements FormModel { disabled: false); } +final _logUrlEntityOForm = Logger('UrlEntityOForm'); + class UrlEntityOForm implements FormModel { UrlEntityOForm( this.form, @@ -678,9 +714,11 @@ class UrlEntityOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UrlEntityOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUrlEntityOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return UrlEntityOOutput(label: _labelValue, url: _urlValue); } @@ -726,6 +764,8 @@ class UrlEntityOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUrlEntityOForm.info('Errors'); + _logUrlEntityOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless.gform.dart b/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless.gform.dart index 3bb910a5..5980b51c 100644 --- a/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless.gform.dart @@ -148,6 +148,34 @@ class _AnnotatelessFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logAnnotatelessForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _AnnotatelessFormBuilderState extends State { } } +final _logAnnotatelessForm = Logger('AnnotatelessForm'); + class AnnotatelessForm implements FormModel { AnnotatelessForm( this.form, @@ -338,9 +368,11 @@ class AnnotatelessForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AnnotatelessForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAnnotatelessForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Annotateless(email: _emailValue, password: _passwordValue); } @@ -386,6 +418,8 @@ class AnnotatelessForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAnnotatelessForm.info('Errors'); + _logAnnotatelessForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless_output.gform.dart index 96e02880..1e869d60 100644 --- a/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless_output.gform.dart @@ -148,6 +148,34 @@ class _AnnotatelessOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logAnnotatelessOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _AnnotatelessOFormBuilderState extends State { } } +final _logAnnotatelessOForm = Logger('AnnotatelessOForm'); + class AnnotatelessOForm implements FormModel { AnnotatelessOForm( @@ -339,9 +369,11 @@ class AnnotatelessOForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AnnotatelessOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAnnotatelessOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return AnnotatelessOOutput(email: _emailValue, password: _passwordValue); } @@ -387,6 +419,8 @@ class AnnotatelessOForm if (currentForm.valid) { onValid(model); } else { + _logAnnotatelessOForm.info('Errors'); + _logAnnotatelessOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable.gform.dart b/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable.gform.dart index a53e7e36..0c00239e 100644 --- a/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable.gform.dart @@ -148,6 +148,34 @@ class _ArrayNullableFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logArrayNullableForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _ArrayNullableFormBuilderState extends State { } } +final _logArrayNullableForm = Logger('ArrayNullableForm'); + class ArrayNullableForm implements FormModel { ArrayNullableForm( this.form, @@ -788,9 +818,11 @@ class ArrayNullableForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ArrayNullableForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logArrayNullableForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return ArrayNullable( emailList: _emailListValue, @@ -841,6 +873,8 @@ class ArrayNullableForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logArrayNullableForm.info('Errors'); + _logArrayNullableForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/delivery_list/delivery_list.gform.dart b/packages/reactive_forms_generator/example/lib/docs/delivery_list/delivery_list.gform.dart index 8f9204ee..ca2c1326 100644 --- a/packages/reactive_forms_generator/example/lib/docs/delivery_list/delivery_list.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/delivery_list/delivery_list.gform.dart @@ -148,6 +148,34 @@ class _DeliveryListFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logDeliveryListForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _DeliveryListFormBuilderState extends State { } } +final _logDeliveryListForm = Logger('DeliveryListForm'); + class DeliveryListForm implements FormModel { DeliveryListForm( this.form, @@ -592,9 +622,11 @@ class DeliveryListForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'DeliveryListForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logDeliveryListForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return DeliveryList( deliveryList: _deliveryListValue, clientList: _clientListValue); @@ -647,6 +679,8 @@ class DeliveryListForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logDeliveryListForm.info('Errors'); + _logDeliveryListForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -702,6 +736,8 @@ class DeliveryListForm implements FormModel { disabled: false); } +final _logDeliveryPointForm = Logger('DeliveryPointForm'); + class DeliveryPointForm implements FormModel { DeliveryPointForm( this.form, @@ -885,9 +921,11 @@ class DeliveryPointForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'DeliveryPointForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logDeliveryPointForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return DeliveryPoint(name: _nameValue, address: _addressValue); } @@ -935,6 +973,8 @@ class DeliveryPointForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logDeliveryPointForm.info('Errors'); + _logDeliveryPointForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -982,6 +1022,8 @@ class DeliveryPointForm implements FormModel { disabled: false); } +final _logAddressForm = Logger('AddressForm'); + class AddressForm implements FormModel { AddressForm( this.form, @@ -1189,9 +1231,11 @@ class AddressForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AddressForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAddressForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Address(street: _streetValue, city: _cityValue); } @@ -1237,6 +1281,8 @@ class AddressForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAddressForm.info('Errors'); + _logAddressForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1290,6 +1336,8 @@ class AddressForm implements FormModel { disabled: false); } +final _logClientForm = Logger('ClientForm'); + class ClientForm implements FormModel { ClientForm( this.form, @@ -1565,9 +1613,11 @@ class ClientForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ClientForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logClientForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Client( clientType: _clientTypeValue, name: _nameValue, notes: _notesValue); @@ -1614,6 +1664,8 @@ class ClientForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logClientForm.info('Errors'); + _logClientForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1947,6 +1999,34 @@ class _StandaloneDeliveryPointFormBuilderState widget.initState?.call(context, _formModel); + _logStandaloneDeliveryPointForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -1984,6 +2064,8 @@ class _StandaloneDeliveryPointFormBuilderState } } +final _logStandaloneDeliveryPointForm = Logger('StandaloneDeliveryPointForm'); + class StandaloneDeliveryPointForm implements FormModel { StandaloneDeliveryPointForm( @@ -2168,9 +2250,11 @@ class StandaloneDeliveryPointForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'StandaloneDeliveryPointForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logStandaloneDeliveryPointForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return DeliveryPoint(name: _nameValue, address: _addressValue); } @@ -2218,6 +2302,8 @@ class StandaloneDeliveryPointForm if (currentForm.valid) { onValid(model); } else { + _logStandaloneDeliveryPointForm.info('Errors'); + _logStandaloneDeliveryPointForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class.gform.dart b/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class.gform.dart index 0dd20fe8..0a0872da 100644 --- a/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class.gform.dart @@ -148,6 +148,34 @@ class _FreezedClassFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logFreezedClassForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _FreezedClassFormBuilderState extends State { } } +final _logFreezedClassForm = Logger('FreezedClassForm'); + class FreezedClassForm implements FormModel { FreezedClassForm( this.form, @@ -676,9 +706,11 @@ class FreezedClassForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'FreezedClassForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logFreezedClassForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return FreezedClass(_genderValue, id: _idValue, @@ -728,6 +760,8 @@ class FreezedClassForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logFreezedClassForm.info('Errors'); + _logFreezedClassForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class_output.gform.dart index d3013809..ba5e54c9 100644 --- a/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class_output.gform.dart @@ -148,6 +148,34 @@ class _FreezedClassOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logFreezedClassOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _FreezedClassOFormBuilderState extends State { } } +final _logFreezedClassOForm = Logger('FreezedClassOForm'); + class FreezedClassOForm implements FormModel { FreezedClassOForm( @@ -865,9 +895,11 @@ class FreezedClassOForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'FreezedClassOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logFreezedClassOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return FreezedClassOOutput(_genderValue, _genderRValue, id: _idValue, @@ -918,6 +950,8 @@ class FreezedClassOForm if (currentForm.valid) { onValid(model); } else { + _logFreezedClassOForm.info('Errors'); + _logFreezedClassOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/freezed2/test.gform.dart b/packages/reactive_forms_generator/example/lib/docs/freezed2/test.gform.dart index e550a157..38be7b85 100644 --- a/packages/reactive_forms_generator/example/lib/docs/freezed2/test.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/freezed2/test.gform.dart @@ -142,6 +142,34 @@ class _TestFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logTestForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -179,6 +207,8 @@ class _TestFormBuilderState extends State { } } +final _logTestForm = Logger('TestForm'); + class TestForm implements FormModel { TestForm( this.form, @@ -359,9 +389,11 @@ class TestForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'TestForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logTestForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Test(title: _titleValue, description: _descriptionValue); } @@ -407,6 +439,8 @@ class TestForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logTestForm.info('Errors'); + _logTestForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/generic/generic.gform.dart b/packages/reactive_forms_generator/example/lib/docs/generic/generic.gform.dart index a5f91bf7..86bb6e60 100644 --- a/packages/reactive_forms_generator/example/lib/docs/generic/generic.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/generic/generic.gform.dart @@ -142,6 +142,34 @@ class _TagsFormBuilderState extends State> { widget.initState?.call(context, _formModel); + _logTagsForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -179,6 +207,8 @@ class _TagsFormBuilderState extends State> { } } +final _logTagsForm = Logger('TagsForm'); + class TagsForm implements FormModel, Tags> { TagsForm( this.form, @@ -291,9 +321,11 @@ class TagsForm implements FormModel, Tags> { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'TagsForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logTagsForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Tags(tags: _tagsValue); } @@ -339,6 +371,8 @@ class TagsForm implements FormModel, Tags> { if (currentForm.valid) { onValid(model); } else { + _logTagsForm.info('Errors'); + _logTagsForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/generic_status_list/generic_status_list.gform.dart b/packages/reactive_forms_generator/example/lib/docs/generic_status_list/generic_status_list.gform.dart index 1f103c53..32144d41 100644 --- a/packages/reactive_forms_generator/example/lib/docs/generic_status_list/generic_status_list.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/generic_status_list/generic_status_list.gform.dart @@ -150,6 +150,34 @@ class _StatusListFormBuilderState widget.initState?.call(context, _formModel); + _logStatusListForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -187,6 +215,8 @@ class _StatusListFormBuilderState } } +final _logStatusListForm = Logger('StatusListForm'); + class StatusListForm implements FormModel, StatusList> { StatusListForm( @@ -313,9 +343,11 @@ class StatusListForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'StatusListForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logStatusListForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return StatusList(list: _listValue); } @@ -361,6 +393,8 @@ class StatusListForm if (currentForm.valid) { onValid(model); } else { + _logStatusListForm.info('Errors'); + _logStatusListForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/group/group.gform.dart b/packages/reactive_forms_generator/example/lib/docs/group/group.gform.dart index 4a4b1b3d..f5454c8b 100644 --- a/packages/reactive_forms_generator/example/lib/docs/group/group.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/group/group.gform.dart @@ -142,6 +142,34 @@ class _GroupFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logGroupForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -179,6 +207,8 @@ class _GroupFormBuilderState extends State { } } +final _logGroupForm = Logger('GroupForm'); + class GroupForm implements FormModel { GroupForm( this.form, @@ -590,9 +620,11 @@ class GroupForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'GroupForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logGroupForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Group( personal: _personalValue, @@ -650,6 +682,8 @@ class GroupForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logGroupForm.info('Errors'); + _logGroupForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -693,6 +727,8 @@ class GroupForm implements FormModel { disabled: false); } +final _logPersonalForm = Logger('PersonalForm'); + class PersonalForm implements FormModel { PersonalForm( this.form, @@ -900,9 +936,11 @@ class PersonalForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'PersonalForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logPersonalForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Personal(name: _nameValue, email: _emailValue); } @@ -948,6 +986,8 @@ class PersonalForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logPersonalForm.info('Errors'); + _logPersonalForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1001,6 +1041,8 @@ class PersonalForm implements FormModel { disabled: false); } +final _logPhoneForm = Logger('PhoneForm'); + class PhoneForm implements FormModel { PhoneForm( this.form, @@ -1208,9 +1250,11 @@ class PhoneForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'PhoneForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logPhoneForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Phone(phoneNumber: _phoneNumberValue, countryIso: _countryIsoValue); } @@ -1256,6 +1300,8 @@ class PhoneForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logPhoneForm.info('Errors'); + _logPhoneForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1309,6 +1355,8 @@ class PhoneForm implements FormModel { disabled: false); } +final _logAddressForm = Logger('AddressForm'); + class AddressForm implements FormModel { AddressForm( this.form, @@ -1611,9 +1659,11 @@ class AddressForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AddressForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAddressForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Address(street: _streetValue, city: _cityValue, zip: _zipValue); } @@ -1659,6 +1709,8 @@ class AddressForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAddressForm.info('Errors'); + _logAddressForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/login/login.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login/login.gform.dart index 987995bb..87d4fec8 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login/login.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login/login.gform.dart @@ -142,6 +142,34 @@ class _LoginFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logLoginForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -179,6 +207,8 @@ class _LoginFormBuilderState extends State { } } +final _logLoginForm = Logger('LoginForm'); + class LoginForm implements FormModel { LoginForm( this.form, @@ -332,9 +362,11 @@ class LoginForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Login(email: _emailValue, password: _passwordValue); } @@ -380,6 +412,8 @@ class LoginForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logLoginForm.info('Errors'); + _logLoginForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/login/login_form.dart b/packages/reactive_forms_generator/example/lib/docs/login/login_form.dart index e6d70bdc..c54bfcbd 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login/login_form.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login/login_form.dart @@ -83,10 +83,14 @@ class _LoginFormWidgetState extends State { child: ElevatedButton( key: submitRaw.itemKey, onPressed: () { - debugPrint(formModel.model.email); - debugPrint(formModel.model.password); + formModel.submit(onValid: (_) {}); + final model = formModel.model; + formModel.form.markAllAsTouched(); - widget.onChange?.call(formModel.model); + widget.onChange?.call(model); + + debugPrint(model.email); + debugPrint(model.password); }, child: const Text('Submit raw'), ), diff --git a/packages/reactive_forms_generator/example/lib/docs/login/login_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login/login_output.gform.dart index fdfd8170..6a9e5c3a 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login/login_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login/login_output.gform.dart @@ -142,6 +142,34 @@ class _LoginOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logLoginOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -179,6 +207,8 @@ class _LoginOFormBuilderState extends State { } } +final _logLoginOForm = Logger('LoginOForm'); + class LoginOForm implements FormModel { LoginOForm( this.form, @@ -384,9 +414,11 @@ class LoginOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return LoginOOutput(email: _emailValue, password: _passwordValue); } @@ -432,6 +464,8 @@ class LoginOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logLoginOForm.info('Errors'); + _logLoginOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended.gform.dart index 8c726f7d..092b85a8 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended.gform.dart @@ -148,6 +148,34 @@ class _LoginExtendedFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logLoginExtendedForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _LoginExtendedFormBuilderState extends State { } } +final _logLoginExtendedForm = Logger('LoginExtendedForm'); + class LoginExtendedForm implements FormModel { LoginExtendedForm( this.form, @@ -841,9 +871,11 @@ class LoginExtendedForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginExtendedForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginExtendedForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return LoginExtended( email: _emailValue, @@ -898,6 +930,8 @@ class LoginExtendedForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logLoginExtendedForm.info('Errors'); + _logLoginExtendedForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended_output.gform.dart index 95909482..3c203f16 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended_output.gform.dart @@ -150,6 +150,34 @@ class _LoginExtendedOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logLoginExtendedOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -187,6 +215,8 @@ class _LoginExtendedOFormBuilderState extends State { } } +final _logLoginExtendedOForm = Logger('LoginExtendedOForm'); + class LoginExtendedOForm implements FormModel { LoginExtendedOForm( @@ -870,9 +900,11 @@ class LoginExtendedOForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginExtendedOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginExtendedOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return LoginExtendedOOutput( email: _emailValue, @@ -927,6 +959,8 @@ class LoginExtendedOForm if (currentForm.valid) { onValid(model); } else { + _logLoginExtendedOForm.info('Errors'); + _logLoginExtendedOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable.gform.dart index d0e115e4..8e37f4d4 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable.gform.dart @@ -150,6 +150,34 @@ class _LoginExtendedNullableFormBuilderState widget.initState?.call(context, _formModel); + _logLoginExtendedNullableForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -187,6 +215,8 @@ class _LoginExtendedNullableFormBuilderState } } +final _logLoginExtendedNullableForm = Logger('LoginExtendedNullableForm'); + class LoginExtendedNullableForm implements FormModel { LoginExtendedNullableForm( @@ -870,9 +900,11 @@ class LoginExtendedNullableForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginExtendedNullableForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginExtendedNullableForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return LoginExtendedNullable( email: _emailValue, @@ -925,6 +957,8 @@ class LoginExtendedNullableForm if (currentForm.valid) { onValid(model); } else { + _logLoginExtendedNullableForm.info('Errors'); + _logLoginExtendedNullableForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable_output.gform.dart index e32fe74e..e5305b61 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable_output.gform.dart @@ -150,6 +150,34 @@ class _LoginExtendedNullableOFormBuilderState widget.initState?.call(context, _formModel); + _logLoginExtendedNullableOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -187,6 +215,8 @@ class _LoginExtendedNullableOFormBuilderState } } +final _logLoginExtendedNullableOForm = Logger('LoginExtendedNullableOForm'); + class LoginExtendedNullableOForm implements FormModel { LoginExtendedNullableOForm( @@ -870,9 +900,11 @@ class LoginExtendedNullableOForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'LoginExtendedNullableOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logLoginExtendedNullableOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return LoginExtendedNullableO( email: _emailValue, @@ -925,6 +957,8 @@ class LoginExtendedNullableOForm if (currentForm.valid) { onValid(model); } else { + _logLoginExtendedNullableOForm.info('Errors'); + _logLoginExtendedNullableOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list.gform.dart b/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list.gform.dart index 3ca4f424..911e4af4 100644 --- a/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list.gform.dart @@ -146,6 +146,34 @@ class _MailingListFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logMailingListForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -183,6 +211,8 @@ class _MailingListFormBuilderState extends State { } } +final _logMailingListForm = Logger('MailingListForm'); + class MailingListForm implements FormModel { MailingListForm( this.form, @@ -309,9 +339,11 @@ class MailingListForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'MailingListForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logMailingListForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return MailingList(emailList: _emailListValue); } @@ -357,6 +389,8 @@ class MailingListForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logMailingListForm.info('Errors'); + _logMailingListForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/model_extends/model_extends.gform.dart b/packages/reactive_forms_generator/example/lib/docs/model_extends/model_extends.gform.dart index a6352bad..7a394887 100644 --- a/packages/reactive_forms_generator/example/lib/docs/model_extends/model_extends.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/model_extends/model_extends.gform.dart @@ -148,6 +148,34 @@ class _ModelExtendsFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logModelExtendsForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _ModelExtendsFormBuilderState extends State { } } +final _logModelExtendsForm = Logger('ModelExtendsForm'); + class ModelExtendsForm implements FormModel { ModelExtendsForm( this.form, @@ -338,9 +368,11 @@ class ModelExtendsForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ModelExtendsForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logModelExtendsForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return ModelExtends(email: _emailValue, password: _passwordValue); } @@ -386,6 +418,8 @@ class ModelExtendsForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logModelExtendsForm.info('Errors'); + _logModelExtendsForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/model_implements/model_implements.gform.dart b/packages/reactive_forms_generator/example/lib/docs/model_implements/model_implements.gform.dart index 8e917be4..184120af 100644 --- a/packages/reactive_forms_generator/example/lib/docs/model_implements/model_implements.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/model_implements/model_implements.gform.dart @@ -151,6 +151,34 @@ class _ModelImplementsFormBuilderState widget.initState?.call(context, _formModel); + _logModelImplementsForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -188,6 +216,8 @@ class _ModelImplementsFormBuilderState } } +final _logModelImplementsForm = Logger('ModelImplementsForm'); + class ModelImplementsForm implements FormModel { ModelImplementsForm( @@ -342,9 +372,11 @@ class ModelImplementsForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ModelImplementsForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logModelImplementsForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return ModelImplements(email: _emailValue, password: _passwordValue); } @@ -390,6 +422,8 @@ class ModelImplementsForm if (currentForm.valid) { onValid(model); } else { + _logModelImplementsForm.info('Errors'); + _logModelImplementsForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/nested/nested.gform.dart b/packages/reactive_forms_generator/example/lib/docs/nested/nested.gform.dart index c227b7ae..e0e505b9 100644 --- a/packages/reactive_forms_generator/example/lib/docs/nested/nested.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/nested/nested.gform.dart @@ -143,6 +143,34 @@ class _SubGroupFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logSubGroupForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -180,6 +208,8 @@ class _SubGroupFormBuilderState extends State { } } +final _logSubGroupForm = Logger('SubGroupForm'); + class SubGroupForm implements FormModel { SubGroupForm( this.form, @@ -265,9 +295,11 @@ class SubGroupForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'SubGroupForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logSubGroupForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return SubGroup(id: _idValue); } @@ -313,6 +345,8 @@ class SubGroupForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logSubGroupForm.info('Errors'); + _logSubGroupForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -626,6 +660,34 @@ class _GroupFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logGroupForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -663,6 +725,8 @@ class _GroupFormBuilderState extends State { } } +final _logGroupForm = Logger('GroupForm'); + class GroupForm implements FormModel { GroupForm( this.form, @@ -927,9 +991,11 @@ class GroupForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'GroupForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logGroupForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Group(id: _idValue, subGroupList: _subGroupListValue); } @@ -979,6 +1045,8 @@ class GroupForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logGroupForm.info('Errors'); + _logGroupForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1297,6 +1365,34 @@ class _NestedFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logNestedForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -1334,6 +1430,8 @@ class _NestedFormBuilderState extends State { } } +final _logNestedForm = Logger('NestedForm'); + class NestedForm implements FormModel { NestedForm( this.form, @@ -1527,9 +1625,11 @@ class NestedForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'NestedForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logNestedForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Nested(groupList: _groupListValue); } @@ -1579,6 +1679,8 @@ class NestedForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logNestedForm.info('Errors'); + _logNestedForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/profile/profile.gform.dart b/packages/reactive_forms_generator/example/lib/docs/profile/profile.gform.dart index e45229fa..9348c285 100644 --- a/packages/reactive_forms_generator/example/lib/docs/profile/profile.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/profile/profile.gform.dart @@ -142,6 +142,34 @@ class _ProfileFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logProfileForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -179,6 +207,8 @@ class _ProfileFormBuilderState extends State { } } +final _logProfileForm = Logger('ProfileForm'); + class ProfileForm implements FormModel { ProfileForm( this.form, @@ -910,9 +940,11 @@ class ProfileForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ProfileForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logProfileForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Profile(_idValue, anotherId: _anotherIdValue, @@ -973,6 +1005,8 @@ class ProfileForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logProfileForm.info('Errors'); + _logProfileForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1066,6 +1100,8 @@ class ProfileForm implements FormModel { disabled: false); } +final _logIncidenceFilterForm = Logger('IncidenceFilterForm'); + class IncidenceFilterForm implements FormModel { IncidenceFilterForm( @@ -1507,9 +1543,11 @@ class IncidenceFilterForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'IncidenceFilterForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logIncidenceFilterForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return IncidenceFilter( isMobilityEnabled: _isMobilityEnabledValue, @@ -1561,6 +1599,8 @@ class IncidenceFilterForm if (currentForm.valid) { onValid(model); } else { + _logIncidenceFilterForm.info('Errors'); + _logIncidenceFilterForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1642,6 +1682,8 @@ class IncidenceFilterForm disabled: false); } +final _logThresholdSettingForm = Logger('ThresholdSettingForm'); + class ThresholdSettingForm implements FormModel { ThresholdSettingForm( @@ -1796,9 +1838,11 @@ class ThresholdSettingForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ThresholdSettingForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logThresholdSettingForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return ThresholdSetting(isEnabled: _isEnabledValue, value: _valueValue); } @@ -1844,6 +1888,8 @@ class ThresholdSettingForm if (currentForm.valid) { onValid(model); } else { + _logThresholdSettingForm.info('Errors'); + _logThresholdSettingForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1898,6 +1944,8 @@ class ThresholdSettingForm disabled: false); } +final _logTimerSettingForm = Logger('TimerSettingForm'); + class TimerSettingForm implements FormModel { TimerSettingForm( this.form, @@ -2051,9 +2099,11 @@ class TimerSettingForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'TimerSettingForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logTimerSettingForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return TimerSetting(isEnabled: _isEnabledValue, value: _valueValue); } @@ -2099,6 +2149,8 @@ class TimerSettingForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logTimerSettingForm.info('Errors'); + _logTimerSettingForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic.gform.dart b/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic.gform.dart index 9705f669..9a6165a6 100644 --- a/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic.gform.dart @@ -148,6 +148,34 @@ class _SomeWiredNameFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logSomeWiredNameForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _SomeWiredNameFormBuilderState extends State { } } +final _logSomeWiredNameForm = Logger('SomeWiredNameForm'); + class SomeWiredNameForm implements FormModel { SomeWiredNameForm( this.form, @@ -338,9 +368,11 @@ class SomeWiredNameForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'SomeWiredNameForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logSomeWiredNameForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return RenamedBasic(email: _emailValue, password: _passwordValue); } @@ -386,6 +418,8 @@ class SomeWiredNameForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logSomeWiredNameForm.info('Errors'); + _logSomeWiredNameForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic_output.gform.dart index 1c420607..8c9d57d2 100644 --- a/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic_output.gform.dart @@ -148,6 +148,34 @@ class _SomeWiredNameFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logSomeWiredNameForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _SomeWiredNameFormBuilderState extends State { } } +final _logSomeWiredNameForm = Logger('SomeWiredNameForm'); + class SomeWiredNameForm implements FormModel { SomeWiredNameForm( @@ -391,9 +421,11 @@ class SomeWiredNameForm final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'SomeWiredNameForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logSomeWiredNameForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return RenamedBasicOOutput(email: _emailValue, password: _passwordValue); } @@ -439,6 +471,8 @@ class SomeWiredNameForm if (currentForm.valid) { onValid(model); } else { + _logSomeWiredNameForm.info('Errors'); + _logSomeWiredNameForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile.gform.dart b/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile.gform.dart index 8d563163..3dcbbc8f 100644 --- a/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile.gform.dart @@ -146,6 +146,34 @@ class _UserProfileFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logUserProfileForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -183,6 +211,8 @@ class _UserProfileFormBuilderState extends State { } } +final _logUserProfileForm = Logger('UserProfileForm'); + class UserProfileForm implements FormModel { UserProfileForm( this.form, @@ -573,9 +603,11 @@ class UserProfileForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UserProfileForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUserProfileForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return UserProfile( id: _idValue, @@ -630,6 +662,8 @@ class UserProfileForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUserProfileForm.info('Errors'); + _logUserProfileForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -692,6 +726,8 @@ class UserProfileForm implements FormModel { disabled: false); } +final _logAddressForm = Logger('AddressForm'); + class AddressForm implements FormModel { AddressForm( this.form, @@ -994,9 +1030,11 @@ class AddressForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AddressForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAddressForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Address(street: _streetValue, city: _cityValue, zip: _zipValue); } @@ -1042,6 +1080,8 @@ class AddressForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAddressForm.info('Errors'); + _logAddressForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile_output.gform.dart index e637b4e8..86482601 100644 --- a/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile_output.gform.dart @@ -148,6 +148,34 @@ class _UserProfileOFormBuilderState extends State { widget.initState?.call(context, _formModel); + _logUserProfileOForm.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -185,6 +213,8 @@ class _UserProfileOFormBuilderState extends State { } } +final _logUserProfileOForm = Logger('UserProfileOForm'); + class UserProfileOForm implements FormModel { UserProfileOForm( this.form, @@ -627,9 +657,11 @@ class UserProfileOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'UserProfileOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logUserProfileOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return UserProfileOOutput( id: _idValue, @@ -684,6 +716,8 @@ class UserProfileOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logUserProfileOForm.info('Errors'); + _logUserProfileOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -746,6 +780,8 @@ class UserProfileOForm implements FormModel { disabled: false); } +final _logAddressOForm = Logger('AddressOForm'); + class AddressOForm implements FormModel { AddressOForm( this.form, @@ -1047,9 +1083,11 @@ class AddressOForm implements FormModel { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'AddressOForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logAddressOForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return AddressOOutput( street: _streetValue, city: _cityValue, zip: _zipValue); @@ -1096,6 +1134,8 @@ class AddressOForm implements FormModel { if (currentForm.valid) { onValid(model); } else { + _logAddressOForm.info('Errors'); + _logAddressOForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } diff --git a/packages/reactive_forms_generator/lib/src/form_generator.dart b/packages/reactive_forms_generator/lib/src/form_generator.dart index bd17baaa..804e0b95 100644 --- a/packages/reactive_forms_generator/lib/src/form_generator.dart +++ b/packages/reactive_forms_generator/lib/src/form_generator.dart @@ -120,6 +120,8 @@ class FormGenerator { String get className => '${baseName}Form'; + String get log => '_log$className'; + String get classNameFull { return '$className${element.generics}'; } @@ -446,7 +448,11 @@ class FormGenerator { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack(label: '[\${path ?? '$classNameFull'}]\\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + $log.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return $referenceType(${parameterValues.join(', ')}); '''); @@ -572,17 +578,21 @@ class FormGenerator { ), ], ) - ..body = const Code(''' + ..body = Code(''' currentForm.markAllAsTouched(); if (currentForm.valid) { onValid(model); } else { + $log.info('Errors'); + $log.info('┗━━ \${form.errors}'); onNotValid?.call(); } '''); }, ); + Code get logging => Code("final $log = Logger('$classNameFull');"); + Constructor get _constructor => Constructor( (b) => b ..requiredParameters.addAll( @@ -677,6 +687,7 @@ class FormGenerator { List get generate { return [ + logging, Class( (b) => b ..name = className diff --git a/packages/reactive_forms_generator/lib/src/reactive_forms/reactive_form_builder.dart b/packages/reactive_forms_generator/lib/src/reactive_forms/reactive_form_builder.dart index 2caa5e81..0a1158aa 100644 --- a/packages/reactive_forms_generator/lib/src/reactive_forms/reactive_form_builder.dart +++ b/packages/reactive_forms_generator/lib/src/reactive_forms/reactive_form_builder.dart @@ -11,6 +11,8 @@ class ReactiveFormBuilder { String get _baseName => reactiveForm.reactiveInheritedStreamer.formGenerator.className; + String get _log => reactiveForm.reactiveInheritedStreamer.formGenerator.log; + ClassElement get _element => reactiveForm.reactiveInheritedStreamer.formGenerator.element; @@ -161,6 +163,34 @@ class ReactiveFormBuilder { widget.initState?.call(context, _formModel); + $_log.onRecord.listen((LogRecord e) { + // use `dumpErrorToConsole` for severe messages to ensure that severe + // exceptions are formatted consistently with other Flutter examples and + // avoids printing duplicate exceptions + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); '''), ),