Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilich6107 committed Jun 17, 2024
1 parent c6a4e66 commit 1c11bc3
Show file tree
Hide file tree
Showing 53 changed files with 2,171 additions and 239 deletions.
8 changes: 4 additions & 4 deletions packages/generator_tests/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
40 changes: 37 additions & 3 deletions packages/generator_tests/test/doc/annotateless_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,34 @@ class _AnnotatelessFormBuilderState extends State<AnnotatelessFormBuilder> {
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();
}
Expand Down Expand Up @@ -225,6 +253,8 @@ class _AnnotatelessFormBuilderState extends State<AnnotatelessFormBuilder> {
}
}
final _logAnnotatelessForm = Logger('AnnotatelessForm');
class AnnotatelessForm implements FormModel<Annotateless, Annotateless> {
AnnotatelessForm(
this.form,
Expand Down Expand Up @@ -378,9 +408,11 @@ class AnnotatelessForm implements FormModel<Annotateless, Annotateless> {
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);
}
Expand Down Expand Up @@ -426,6 +458,8 @@ class AnnotatelessForm implements FormModel<Annotateless, Annotateless> {
if (currentForm.valid) {
onValid(model);
} else {
_logAnnotatelessForm.info('Errors');
_logAnnotatelessForm.info('┗━━ ${form.errors}');
onNotValid?.call();
}
}
Expand Down
40 changes: 37 additions & 3 deletions packages/generator_tests/test/doc/array_nullable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,34 @@ class _ArrayNullableFormBuilderState extends State<ArrayNullableFormBuilder> {
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();
}
Expand Down Expand Up @@ -240,6 +268,8 @@ class _ArrayNullableFormBuilderState extends State<ArrayNullableFormBuilder> {
}
}
final _logArrayNullableForm = Logger('ArrayNullableForm');
class ArrayNullableForm implements FormModel<ArrayNullable, ArrayNullable> {
ArrayNullableForm(
this.form,
Expand Down Expand Up @@ -843,9 +873,11 @@ class ArrayNullableForm implements FormModel<ArrayNullable, ArrayNullable> {
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,
Expand Down Expand Up @@ -896,6 +928,8 @@ class ArrayNullableForm implements FormModel<ArrayNullable, ArrayNullable> {
if (currentForm.valid) {
onValid(model);
} else {
_logArrayNullableForm.info('Errors');
_logArrayNullableForm.info('┗━━ ${form.errors}');
onNotValid?.call();
}
}
Expand Down
116 changes: 101 additions & 15 deletions packages/generator_tests/test/doc/delivery_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,34 @@ class _DeliveryListFormBuilderState extends State<DeliveryListFormBuilder> {
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();
}
Expand Down Expand Up @@ -273,6 +301,8 @@ class _DeliveryListFormBuilderState extends State<DeliveryListFormBuilder> {
}
}
final _logDeliveryListForm = Logger('DeliveryListForm');
class DeliveryListForm implements FormModel<DeliveryList, DeliveryList> {
DeliveryListForm(
this.form,
Expand Down Expand Up @@ -680,9 +710,11 @@ class DeliveryListForm implements FormModel<DeliveryList, DeliveryList> {
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);
Expand Down Expand Up @@ -735,6 +767,8 @@ class DeliveryListForm implements FormModel<DeliveryList, DeliveryList> {
if (currentForm.valid) {
onValid(model);
} else {
_logDeliveryListForm.info('Errors');
_logDeliveryListForm.info('┗━━ ${form.errors}');
onNotValid?.call();
}
}
Expand Down Expand Up @@ -790,6 +824,8 @@ class DeliveryListForm implements FormModel<DeliveryList, DeliveryList> {
disabled: false);
}
final _logDeliveryPointForm = Logger('DeliveryPointForm');
class DeliveryPointForm implements FormModel<DeliveryPoint, DeliveryPoint> {
DeliveryPointForm(
this.form,
Expand Down Expand Up @@ -973,9 +1009,11 @@ class DeliveryPointForm implements FormModel<DeliveryPoint, DeliveryPoint> {
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);
}
Expand Down Expand Up @@ -1023,6 +1061,8 @@ class DeliveryPointForm implements FormModel<DeliveryPoint, DeliveryPoint> {
if (currentForm.valid) {
onValid(model);
} else {
_logDeliveryPointForm.info('Errors');
_logDeliveryPointForm.info('┗━━ ${form.errors}');
onNotValid?.call();
}
}
Expand Down Expand Up @@ -1070,6 +1110,8 @@ class DeliveryPointForm implements FormModel<DeliveryPoint, DeliveryPoint> {
disabled: false);
}
final _logAddressForm = Logger('AddressForm');
class AddressForm implements FormModel<Address, Address> {
AddressForm(
this.form,
Expand Down Expand Up @@ -1277,9 +1319,11 @@ class AddressForm implements FormModel<Address, Address> {
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);
}
Expand Down Expand Up @@ -1325,6 +1369,8 @@ class AddressForm implements FormModel<Address, Address> {
if (currentForm.valid) {
onValid(model);
} else {
_logAddressForm.info('Errors');
_logAddressForm.info('┗━━ ${form.errors}');
onNotValid?.call();
}
}
Expand Down Expand Up @@ -1378,6 +1424,8 @@ class AddressForm implements FormModel<Address, Address> {
disabled: false);
}
final _logClientForm = Logger('ClientForm');
class ClientForm implements FormModel<Client, Client> {
ClientForm(
this.form,
Expand Down Expand Up @@ -1653,9 +1701,11 @@ class ClientForm implements FormModel<Client, Client> {
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);
Expand Down Expand Up @@ -1702,6 +1752,8 @@ class ClientForm implements FormModel<Client, Client> {
if (currentForm.valid) {
onValid(model);
} else {
_logClientForm.info('Errors');
_logClientForm.info('┗━━ ${form.errors}');
onNotValid?.call();
}
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -2072,6 +2152,8 @@ class _StandaloneDeliveryPointFormBuilderState
}
}
final _logStandaloneDeliveryPointForm = Logger('StandaloneDeliveryPointForm');
class StandaloneDeliveryPointForm
implements FormModel<DeliveryPoint, DeliveryPoint> {
StandaloneDeliveryPointForm(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -2306,6 +2390,8 @@ class StandaloneDeliveryPointForm
if (currentForm.valid) {
onValid(model);
} else {
_logStandaloneDeliveryPointForm.info('Errors');
_logStandaloneDeliveryPointForm.info('┗━━ ${form.errors}');
onNotValid?.call();
}
}
Expand Down
Loading

0 comments on commit 1c11bc3

Please sign in to comment.