Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: enable debug logs in internal build (#5713)
Lucas.Xu0fe383e53821
diff --git a/frontend/appflowy_flutter/lib/env/env.dart b/frontend/appflowy_flutter/lib/env/env.dartindex a0786e4d5b..b861b4cfb8 100644--- a/frontend/appflowy_flutter/lib/env/env.dart+++ b/frontend/appflowy_flutter/lib/env/env.dart@@ -29,4 +29,11 @@ abstract class Env {defaultValue: '',)static const String afCloudUrl = _Env.afCloudUrl;++ @EnviedField(+ obfuscate: false,+ varName: 'INTERNAL_BUILD',+ defaultValue: '',+ )+ static const String internalBuild = _Env.internalBuild;}diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dartindex a50c7cac2d..cc99dd60c5 100644--- a/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart@@ -18,6 +18,7 @@ import 'package:appflowy/util/color_to_hex_string.dart';import 'package:appflowy/util/debounce.dart';import 'package:appflowy/util/throttle.dart';import 'package:appflowy/workspace/application/view/view_listener.dart';+import 'package:appflowy_backend/log.dart';import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart';import 'package:appflowy_backend/protobuf/flowy-document/protobuf.dart';import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';@@ -37,6 +38,8 @@ import 'package:freezed_annotation/freezed_annotation.dart';part 'document_bloc.freezed.dart';+bool enableDocumentInternalLog = false;+class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {DocumentBloc({required this.documentId,@@ -212,6 +215,10 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {}Future<EditorState?> _initAppFlowyEditorState(DocumentDataPB data) async {+ if (enableDocumentInternalLog) {+ Log.info('document data: ${data.toProto3Json()}');+ }+final document = data.toDocument();if (document == null) {assert(false, 'document is null');diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dartindex da99886014..91faccf484 100644--- a/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart@@ -180,6 +180,8 @@ extension NodeToBlock on Node {String? parentId,String? childrenId,Attributes? attributes,+ String? externalId,+ String? externalType,}) {assert(id.isNotEmpty);final block = BlockPB.create()@@ -192,6 +194,12 @@ extension NodeToBlock on Node {if (parentId != null && parentId.isNotEmpty) {block.parentId = parentId;}+ if (externalId != null && externalId.isNotEmpty) {+ block.externalId = externalId;+ }+ if (externalType != null && externalType.isNotEmpty) {+ block.externalType = externalType;+ }return block;}diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart b/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dartindex 666dea3f00..f69d116df5 100644--- a/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart@@ -1,6 +1,7 @@import 'dart:async';import 'dart:convert';+import 'package:appflowy/plugins/document/application/document_bloc.dart';import 'package:appflowy/plugins/document/application/document_data_pb_extension.dart';import 'package:appflowy/plugins/document/application/document_service.dart';import 'package:appflowy_backend/log.dart';@@ -21,6 +22,8 @@ import 'package:appflowy_editor/appflowy_editor.dart'import 'package:collection/collection.dart';import 'package:nanoid/nanoid.dart';+const _kExternalTextType = 'text';+/// Uses to adjust the data structure between the editor and the backend.////// The editor uses a tree structure to represent the document, while the backend uses a flat structure.@@ -34,11 +37,9 @@ class TransactionAdapter {final DocumentService documentService;final String documentId;- final bool _enableDebug = false;-Future<void> apply(Transaction transaction, EditorState editorState) async {final stopwatch = Stopwatch()..start();- if (_enableDebug) {+ if (enableDocumentInternalLog) {Log.debug('transaction => ${transaction.toJson()}');}final actions = transaction.operations@@ -60,8 +61,10 @@ class TransactionAdapter {textId: payload.textId,delta: payload.delta,);- if (_enableDebug) {- Log.debug('create external text: ${payload.delta}');+ if (enableDocumentInternalLog) {+ Log.debug(+ '[editor_transaction_adapter] create external text: ${payload.delta}',+ );}} else if (type == TextDeltaType.update) {await documentService.updateExternalText(@@ -69,8 +72,10 @@ class TransactionAdapter {textId: payload.textId,delta: payload.delta,);- if (_enableDebug) {- Log.debug('update external text: ${payload.delta}');+ if (enableDocumentInternalLog) {+ Log.debug(+ '[editor_transaction_adapter] update external text: ${payload.delta}',+ );}}}@@ -82,9 +87,9 @@ class TransactionAdapter {);final elapsed = stopwatch.elapsedMilliseconds;stopwatch.stop();- if (_enableDebug) {+ if (enableDocumentInternalLog) {Log.debug(- 'apply transaction cost: total $elapsed ms, converter action $actionCostTime ms, apply action ${elapsed - actionCostTime} ms',+ '[editor_transaction_adapter] apply transaction cost: total $elapsed ms, converter action $actionCostTime ms, apply action ${elapsed - actionCostTime} ms',);}}@@ -136,8 +141,9 @@ extension on InsertOperation {// create the external text if the node contains the delta in its data.final delta = node.delta;TextDeltaPayloadPB? textDeltaPayloadPB;+ String? textId;if (delta != null) {- final textId = nanoid(6);+ textId = nanoid(6);textDeltaPayloadPB = TextDeltaPayloadPB(documentId: documentId,@@ -148,13 +154,17 @@ extension on InsertOperation {// sync the text id to the nodenode.externalValues = ExternalValues(externalId: textId,- externalType: 'text',+ externalType: _kExternalTextType,);}// remove the delta from the data when the incremental update is stable.final payload = BlockActionPayloadPB()- ..block = node.toBlock(childrenId: nanoid(6))+ ..block = node.toBlock(+ childrenId: nanoid(6),+ externalId: textId,+ externalType: textId != null ? _kExternalTextType : null,+ )..parentId = parentId..prevId = prevId;@@ -248,7 +258,7 @@ extension on UpdateOperation {node.externalValues = ExternalValues(externalId: textId,- externalType: 'text',+ externalType: _kExternalTextType,);actions.add(diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dartindex 75936f42d5..47bfc237d8 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart@@ -27,7 +27,6 @@ import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/sidebarimport 'package:appflowy/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart';import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/space_migration.dart';import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart';-import 'package:appflowy_backend/log.dart';import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'show UserProfilePB;@@ -371,11 +370,6 @@ class _SidebarState extends State<_Sidebar> {final sidebarSectionBloc = context.watch<SidebarSectionsBloc>();final containsSpace = sidebarSectionBloc.state.containsSpace;- Log.info('fetch the space info from sidebar section: $containsSpace');- Log.info(- 'fetch the space info from space: ${spaceState.spaces.isNotEmpty}',- );-if (containsSpace && spaceState.spaces.isEmpty) {context.read<SpaceBloc>().add(const SpaceEvent.didReceiveSpaceUpdate());}diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/float_bubble/question_bubble.dartindex fde71f9150..6ff84a9adc 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart@@ -1,9 +1,12 @@import 'package:appflowy/core/helpers/url_launcher.dart';+import 'package:appflowy/env/env.dart';import 'package:appflowy/generated/flowy_svgs.g.dart';import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/plugins/document/application/document_bloc.dart';import 'package:appflowy/startup/tasks/rust_sdk.dart';import 'package:appflowy/util/theme_extension.dart';import 'package:appflowy/workspace/presentation/home/toast.dart';+import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';import 'package:appflowy_popover/appflowy_popover.dart';import 'package:device_info_plus/device_info_plus.dart';@@ -203,9 +206,24 @@ class FlowyVersionDescription extends CustomActionCell {thickness: 1.0,),const VSpace(6),- FlowyText(- "$appName $version",- color: Theme.of(context).hintColor,+ GestureDetector(+ behavior: HitTestBehavior.opaque,+ onDoubleTap: () {+ if (Env.internalBuild != '1') {+ return;+ }+ enableDocumentInternalLog = !enableDocumentInternalLog;+ showToastNotification(+ context,+ message: enableDocumentInternalLog+ ? 'Enabled Internal Log'+ : 'Disabled Internal Log',+ );+ },+ child: FlowyText(+ '$appName $version',+ color: Theme.of(context).hintColor,+ ),),],).padding(