Skip to content

Commit

Permalink
feat: basic logs page
Browse files Browse the repository at this point in the history
Needs fleshing out more but I need to sleep
  • Loading branch information
adil192 committed Sep 30, 2024
1 parent 88050d1 commit ab51eff
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/data/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ abstract class RoutePaths {
static const home = '$prefixOfHome/:subpage';
static const edit = '/edit';
static const login = '/login';
static const logs = '/logs';

static const prefixOfHome = '/home';

Expand Down
60 changes: 60 additions & 0 deletions lib/i18n/_missing_translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ ar:
select(OUTDATED): Select
mustBeEmpty(OUTDATED): Selected folder must be empty
mustBeDoneSyncing(OUTDATED): Make sure syncing is complete before changing the folder
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
login:
notYou(rich)(OUTDATED): "Not you? ${undoLogin(Choose another account)}."
status:
Expand Down Expand Up @@ -135,7 +139,15 @@ ar:
bgPatterns:
tablature(OUTDATED): Tablature
cs:
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
de:
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
es:
common:
done(OUTDATED): Done
Expand Down Expand Up @@ -164,6 +176,10 @@ es:
select(OUTDATED): Select
mustBeEmpty(OUTDATED): Selected folder must be empty
mustBeDoneSyncing(OUTDATED): Make sure syncing is complete before changing the folder
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
login:
notYou(rich)(OUTDATED): "Not you? ${undoLogin(Choose another account)}."
status:
Expand Down Expand Up @@ -239,6 +255,10 @@ fa:
select(OUTDATED): Select
mustBeEmpty(OUTDATED): Selected folder must be empty
mustBeDoneSyncing(OUTDATED): Make sure syncing is complete before changing the folder
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
login:
notYou(rich)(OUTDATED): "Not you? ${undoLogin(Choose another account)}."
status:
Expand Down Expand Up @@ -308,6 +328,10 @@ fr:
select(OUTDATED): Select
mustBeEmpty(OUTDATED): Selected folder must be empty
mustBeDoneSyncing(OUTDATED): Make sure syncing is complete before changing the folder
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
login:
notYou(rich)(OUTDATED): "Not you? ${undoLogin(Choose another account)}."
status:
Expand Down Expand Up @@ -394,6 +418,10 @@ he:
select(OUTDATED): Select
mustBeEmpty(OUTDATED): Selected folder must be empty
mustBeDoneSyncing(OUTDATED): Make sure syncing is complete before changing the folder
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
login:
notYou(rich)(OUTDATED): "Not you? ${undoLogin(Choose another account)}."
status:
Expand Down Expand Up @@ -550,6 +578,10 @@ hu:
select(OUTDATED): Select
mustBeEmpty(OUTDATED): Selected folder must be empty
mustBeDoneSyncing(OUTDATED): Make sure syncing is complete before changing the folder
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
login:
notYou(rich)(OUTDATED): "Not you? ${undoLogin(Choose another account)}."
status:
Expand Down Expand Up @@ -669,6 +701,10 @@ hu:
lockAxisAlignedPan(OUTDATED): Lock panning to horizontal or vertical
needsToSaveBeforeExiting(OUTDATED): Saving your changes... You can safely exit the editor when it's done
it:
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
ja:
common:
done(OUTDATED): Done
Expand Down Expand Up @@ -736,6 +772,10 @@ ja:
select(OUTDATED): Select
mustBeEmpty(OUTDATED): Selected folder must be empty
mustBeDoneSyncing(OUTDATED): Make sure syncing is complete before changing the folder
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
login:
notYou(rich)(OUTDATED): "Not you? ${undoLogin(Choose another account)}."
status:
Expand Down Expand Up @@ -833,6 +873,10 @@ pt-BR:
select(OUTDATED): Select
mustBeEmpty(OUTDATED): Selected folder must be empty
mustBeDoneSyncing(OUTDATED): Make sure syncing is complete before changing the folder
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
login:
notYou(rich)(OUTDATED): "Not you? ${undoLogin(Choose another account)}."
status:
Expand Down Expand Up @@ -892,6 +936,22 @@ pt-BR:
watchServer(OUTDATED): Watch for updates on the server
watchServerReadOnly(OUTDATED): Editing is disabled while watching the server
ru:
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
tr:
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
zh-Hans-CN:
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
zh-Hant-TW:
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
13 changes: 13 additions & 0 deletions lib/i18n/strings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class Translations implements BaseTranslations<AppLocale, Translations> {
late final _StringsCommonEn common = _StringsCommonEn._(_root);
late final _StringsHomeEn home = _StringsHomeEn._(_root);
late final _StringsSettingsEn settings = _StringsSettingsEn._(_root);
late final _StringsLogsEn logs = _StringsLogsEn._(_root);
late final _StringsLoginEn login = _StringsLoginEn._(_root);
late final _StringsProfileEn profile = _StringsProfileEn._(_root);
late final _StringsAppInfoEn appInfo = _StringsAppInfoEn._(_root);
Expand Down Expand Up @@ -222,6 +223,18 @@ class _StringsSettingsEn {
late final _StringsSettingsCustomDataDirEn customDataDir = _StringsSettingsCustomDataDirEn._(_root);
}

// Path: logs
class _StringsLogsEn {
_StringsLogsEn._(this._root);

final Translations _root; // ignore: unused_field

// Translations
String get logs => 'Logs';
String get viewLogs => 'View logs';
String get debuggingInfo => 'Logs contain information useful for debugging and development';
}

// Path: login
class _StringsLoginEn {
_StringsLoginEn._(this._root);
Expand Down
4 changes: 4 additions & 0 deletions lib/i18n/strings.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ settings:
select: Select
mustBeEmpty: Selected folder must be empty
mustBeDoneSyncing: Make sure syncing is complete before changing the folder
logs:
logs: Logs
viewLogs: View logs
debuggingInfo: Logs contain information useful for debugging and development
login:
title: Login
form:
Expand Down
7 changes: 7 additions & 0 deletions lib/main_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:saber/data/tools/stroke_properties.dart';
import 'package:saber/i18n/strings.g.dart';
import 'package:saber/pages/editor/editor.dart';
import 'package:saber/pages/home/home.dart';
import 'package:saber/pages/logs.dart';
import 'package:saber/pages/user/login.dart';
import 'package:window_manager/window_manager.dart';
import 'package:worker_manager/worker_manager.dart';
Expand All @@ -43,6 +44,8 @@ Future<void> main(
Logger.root.level =
(kDebugMode || parsedArgs.flag('verbose')) ? Level.INFO : Level.WARNING;
Logger.root.onRecord.listen((record) {
logsHistory.add(record);

// ignore: avoid_print
print('${record.level.name}: ${record.loggerName}: ${record.message}');
});
Expand Down Expand Up @@ -225,6 +228,10 @@ class App extends StatefulWidget {
path: '/profile',
redirect: (context, state) => RoutePaths.login,
),
GoRoute(
path: RoutePaths.logs,
builder: (context, state) => const LogsPage(),
),
],
);

Expand Down
8 changes: 8 additions & 0 deletions lib/pages/home/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:go_router/go_router.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:saber/components/navbar/responsive_navbar.dart';
import 'package:saber/components/settings/app_info.dart';
Expand All @@ -24,6 +25,7 @@ import 'package:saber/data/file_manager/file_manager.dart';
import 'package:saber/data/flavor_config.dart';
import 'package:saber/data/locales.dart';
import 'package:saber/data/prefs.dart';
import 'package:saber/data/routes.dart';
import 'package:saber/data/tools/shape_pen.dart';
import 'package:saber/i18n/strings.g.dart';

Expand Down Expand Up @@ -566,6 +568,12 @@ class _SettingsPageState extends State<SettingsPage> {
icon: Icons.private_connectivity,
pref: Prefs.allowInsecureConnections,
),
SettingsButton(
title: t.logs.viewLogs,
subtitle: t.logs.debuggingInfo,
icon: Icons.receipt_long,
onPressed: () => context.push(RoutePaths.logs),
),
],
)),
],
Expand Down
90 changes: 90 additions & 0 deletions lib/pages/logs.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:saber/components/nextcloud/enc_login_step.dart';

Check warning on line 3 in lib/pages/logs.dart

View workflow job for this annotation

GitHub Actions / Run Flutter tests

Unused import: 'package:saber/components/nextcloud/enc_login_step.dart'.

Try removing the import directive. See https://dart.dev/diagnostics/unused_import to learn more about this problem.
import 'package:saber/i18n/strings.g.dart';

final logsHistory = _LogsHistory();

class _LogsHistory extends ChangeNotifier {
final _history = <LogRecord>[];

void add(LogRecord record) {
_history.add(record);
notifyListeners();
}
}

class LogsPage extends StatelessWidget {
const LogsPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(t.logs.logs),
),
body: AnimatedBuilder(
animation: logsHistory,
builder: (context, _) {
return ListView.builder(
itemCount: logsHistory._history.length,
itemBuilder: (context, index) => _LogsItem(
record: logsHistory._history[index],
),
);
},
),
);
}
}

class _LogsItem extends StatelessWidget {
const _LogsItem({required this.record});

final LogRecord record;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_LogLevel(level: record.level),
Text(record.message),
],
),
);
}
}

class _LogLevel extends StatelessWidget {
const _LogLevel({required this.level});

final Level level;

@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return DecoratedBox(
decoration: BoxDecoration(
color: switch (level) {
Level.SHOUT || Level.SEVERE => colorScheme.error,
Level.WARNING => colorScheme.tertiary,
_ => colorScheme.surfaceContainer,
},
borderRadius: BorderRadius.circular(2),
),
child: Text(
level.name,
style: TextStyle(
color: switch (level) {
Level.SHOUT || Level.SEVERE => colorScheme.onError,
Level.WARNING => colorScheme.onTertiary,
_ => colorScheme.onSurface,
},
),
),
);
}
}

0 comments on commit ab51eff

Please sign in to comment.