Migrate from kDebugMode to something we can control

This commit is contained in:
Ming Ming 2024-10-20 21:49:53 +08:00
parent df400b2690
commit cf1ad9eb0e
22 changed files with 66 additions and 43 deletions

View file

@ -3,11 +3,11 @@ import 'dart:math';
import 'package:clock/clock.dart'; import 'package:clock/clock.dart';
import 'package:copy_with/copy_with.dart'; import 'package:copy_with/copy_with.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:np_codegen/np_codegen.dart'; import 'package:np_codegen/np_codegen.dart';
import 'package:np_collection/np_collection.dart'; import 'package:np_collection/np_collection.dart';
import 'package:np_common/type.dart'; import 'package:np_common/type.dart';
import 'package:np_log/np_log.dart';
import 'package:np_string/np_string.dart'; import 'package:np_string/np_string.dart';
import 'package:to_string/to_string.dart'; import 'package:to_string/to_string.dart';
@ -82,15 +82,15 @@ class Account with EquatableMixin {
final String id; final String id;
final String scheme; final String scheme;
@Format(r"${kDebugMode ? $? : '***'}") @Format(r"${isDevMode ? $? : '***'}")
final String address; final String address;
// For non LDAP users, this is the username used to sign in // For non LDAP users, this is the username used to sign in
@Format(r"${kDebugMode ? $? : '***'}") @Format(r"${isDevMode ? $? : '***'}")
final CiString userId; final CiString userId;
// Username used to sign in. For non-LDAP users, this is identical to userId // Username used to sign in. For non-LDAP users, this is identical to userId
@Format(r"${kDebugMode ? $? : '***'}") @Format(r"${isDevMode ? $? : '***'}")
final String username2; final String username2;
@Format(r"${$?.isNotEmpty ? (kDebugMode ? $? : '***') : null}") @Format(r"${$?.isNotEmpty ? (isDevMode ? $? : '***') : null}")
final String password; final String password;
@deepCopy @deepCopy

View file

@ -78,6 +78,6 @@ extension _$AccountUpgraderV1NpLog on AccountUpgraderV1 {
extension _$AccountToString on Account { extension _$AccountToString on Account {
String _$toString() { String _$toString() {
// ignore: unnecessary_string_interpolations // ignore: unnecessary_string_interpolations
return "Account {id: $id, scheme: $scheme, address: ${kDebugMode ? address : '***'}, userId: ${kDebugMode ? userId : '***'}, username2: ${kDebugMode ? username2 : '***'}, password: ${password.isNotEmpty ? (kDebugMode ? password : '***') : null}, roots: ${roots.toReadableString()}}"; return "Account {id: $id, scheme: $scheme, address: ${isDevMode ? address : '***'}, userId: ${isDevMode ? userId : '***'}, username2: ${isDevMode ? username2 : '***'}, password: ${password.isNotEmpty ? (isDevMode ? password : '***') : null}, roots: ${roots.toReadableString()}}";
} }
} }

View file

@ -2,13 +2,13 @@
import 'dart:convert'; import 'dart:convert';
import 'package:clock/clock.dart'; import 'package:clock/clock.dart';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart'; import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception.dart'; import 'package:nc_photos/exception.dart';
import 'package:np_api/np_api.dart' hide NcAlbumItem; import 'package:np_api/np_api.dart' hide NcAlbumItem;
import 'package:np_log/np_log.dart';
import 'package:to_string/to_string.dart'; import 'package:to_string/to_string.dart';
part 'api_util.g.dart'; part 'api_util.g.dart';
@ -46,7 +46,8 @@ String getFilePreviewUrlRelative(
// We can't use the generic file preview url because collaborative albums do // We can't use the generic file preview url because collaborative albums do
// not create a file share for photos not belonging to you, that means you // not create a file share for photos not belonging to you, that means you
// can only access the file view the Photos API // can only access the file view the Photos API
url = "index.php/apps/photos/api/v1/preview/${file.fdId}?x=$width&y=$height"; url =
"index.php/apps/photos/api/v1/preview/${file.fdId}?x=$width&y=$height";
} else { } else {
if (file_util.isTrash(account, file)) { if (file_util.isTrash(account, file)) {
// trashbin does not support preview.png endpoint // trashbin does not support preview.png endpoint
@ -225,7 +226,7 @@ class InitiateLoginPollOptions {
return clock.now().isBefore(_validUntil); return clock.now().isBefore(_validUntil);
} }
@Format(r"${kDebugMode ? $? : '***'}") @Format(r"${isDevMode ? $? : '***'}")
final String token; final String token;
final Uri endpoint; final Uri endpoint;
final DateTime _validUntil; final DateTime _validUntil;
@ -255,7 +256,7 @@ class AppPasswordSuccess implements AppPasswordResponse {
final Uri server; final Uri server;
final String loginName; final String loginName;
@Format(r"${kDebugMode ? appPassword : '***'}") @Format(r"${isDevMode ? appPassword : '***'}")
final String appPassword; final String appPassword;
} }

View file

@ -16,13 +16,13 @@ extension _$InitiateLoginResponseToString on InitiateLoginResponse {
extension _$InitiateLoginPollOptionsToString on InitiateLoginPollOptions { extension _$InitiateLoginPollOptionsToString on InitiateLoginPollOptions {
String _$toString() { String _$toString() {
// ignore: unnecessary_string_interpolations // ignore: unnecessary_string_interpolations
return "InitiateLoginPollOptions {token: ${kDebugMode ? token : '***'}, endpoint: $endpoint, _validUntil: $_validUntil}"; return "InitiateLoginPollOptions {token: ${isDevMode ? token : '***'}, endpoint: $endpoint, _validUntil: $_validUntil}";
} }
} }
extension _$AppPasswordSuccessToString on AppPasswordSuccess { extension _$AppPasswordSuccessToString on AppPasswordSuccess {
String _$toString() { String _$toString() {
// ignore: unnecessary_string_interpolations // ignore: unnecessary_string_interpolations
return "AppPasswordSuccess {server: $server, loginName: $loginName, appPassword: ${kDebugMode ? appPassword : '***'}}"; return "AppPasswordSuccess {server: $server, loginName: $loginName, appPassword: ${isDevMode ? appPassword : '***'}}";
} }
} }

View file

@ -93,7 +93,7 @@ void initLog() {
} }
np_log.initLog( np_log.initLog(
isDebugMode: kDebugMode, isDebugMode: np_log.isDevMode,
print: (log) => debugPrint(log, wrapWidth: 1024), print: (log) => debugPrint(log, wrapWidth: 1024),
); );
} }

View file

@ -17,6 +17,7 @@ import 'package:nc_photos/use_case/list_tag.dart';
import 'package:nc_photos/use_case/person/list_person.dart'; import 'package:nc_photos/use_case/person/list_person.dart';
import 'package:np_codegen/np_codegen.dart'; import 'package:np_codegen/np_codegen.dart';
import 'package:np_collection/np_collection.dart'; import 'package:np_collection/np_collection.dart';
import 'package:np_log/np_log.dart';
import 'package:np_string/np_string.dart'; import 'package:np_string/np_string.dart';
import 'package:to_string/to_string.dart'; import 'package:to_string/to_string.dart';
import 'package:woozy_search/woozy_search.dart'; import 'package:woozy_search/woozy_search.dart';
@ -162,7 +163,7 @@ class HomeSearchSuggestionBloc
emit(HomeSearchSuggestionBlocLoading(state.results)); emit(HomeSearchSuggestionBlocLoading(state.results));
// doesn't work with upper case // doesn't work with upper case
final results = _search.search(ev.phrase.toCaseInsensitiveString()); final results = _search.search(ev.phrase.toCaseInsensitiveString());
if (kDebugMode) { if (isDevMode) {
final str = results.map((e) => "${e.score}: ${e.text}").join("\n"); final str = results.map((e) => "${e.score}: ${e.text}").join("\n");
_log.fine("[_onEventSearch] Search '${ev.phrase}':\n$str"); _log.fine("[_onEventSearch] Search '${ev.phrase}':\n$str");
} }

View file

@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:np_codegen/np_codegen.dart'; import 'package:np_codegen/np_codegen.dart';
import 'package:np_collection/np_collection.dart'; import 'package:np_collection/np_collection.dart';
import 'package:np_log/np_log.dart';
import 'package:np_string/np_string.dart'; import 'package:np_string/np_string.dart';
import 'package:to_string/to_string.dart'; import 'package:to_string/to_string.dart';
import 'package:woozy_search/woozy_search.dart'; import 'package:woozy_search/woozy_search.dart';
@ -81,7 +82,7 @@ class SearchSuggestionBloc<T>
emit(SearchSuggestionBlocLoading(state.results)); emit(SearchSuggestionBlocLoading(state.results));
// doesn't work with upper case // doesn't work with upper case
final results = _search.search(ev.phrase.toCaseInsensitiveString()); final results = _search.search(ev.phrase.toCaseInsensitiveString());
if (kDebugMode) { if (isDevMode) {
final str = results.map((e) => "${e.score}: ${e.text}").join("\n"); final str = results.map((e) => "${e.score}: ${e.text}").join("\n");
_log.info("[_onEventSearch] Search '${ev.phrase}':\n$str"); _log.info("[_onEventSearch] Search '${ev.phrase}':\n$str");
} }

View file

@ -1,7 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:nc_photos/mobile/platform.dart' import 'package:nc_photos/mobile/platform.dart'
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform; if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
import 'package:np_log/np_log.dart'; import 'package:np_log/np_log.dart';
@ -39,8 +38,11 @@ class LogCapturer {
static LogCapturer? _inst; static LogCapturer? _inst;
} }
String logFilename(String? filename) { String logFilename(
if (shouldLogFileName || filename == null) { String? filename, {
bool? shouldLogFileName,
}) {
if ((shouldLogFileName ?? isDevMode) || filename == null) {
return "$filename"; return "$filename";
} }
try { try {
@ -55,6 +57,3 @@ String logFilename(String? filename) {
return "***"; return "***";
} }
} }
@visibleForTesting
bool shouldLogFileName = kDebugMode;

View file

@ -1,12 +1,12 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart'; import 'package:nc_photos/account.dart';
import 'package:nc_photos/exception.dart'; import 'package:nc_photos/exception.dart';
import 'package:nc_photos/np_api_util.dart'; import 'package:nc_photos/np_api_util.dart';
import 'package:np_codegen/np_codegen.dart'; import 'package:np_codegen/np_codegen.dart';
import 'package:np_log/np_log.dart';
import 'package:to_string/to_string.dart'; import 'package:to_string/to_string.dart';
part 'app_password_exchange_bloc.g.dart'; part 'app_password_exchange_bloc.g.dart';
@ -40,7 +40,7 @@ class AppPasswordExchangeBlocSuccess extends AppPasswordExchangeBlocState {
@override @override
String toString() => _$toString(); String toString() => _$toString();
@Format(r"${kDebugMode ? password : '***'}") @Format(r"${isDevMode ? password : '***'}")
final String password; final String password;
} }

View file

@ -30,7 +30,7 @@ extension _$AppPasswordExchangeBlocSuccessToString
on AppPasswordExchangeBlocSuccess { on AppPasswordExchangeBlocSuccess {
String _$toString() { String _$toString() {
// ignore: unnecessary_string_interpolations // ignore: unnecessary_string_interpolations
return "AppPasswordExchangeBlocSuccess {password: ${kDebugMode ? password : '***'}}"; return "AppPasswordExchangeBlocSuccess {password: ${isDevMode ? password : '***'}}";
} }
} }

View file

@ -1,8 +1,8 @@
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:np_codegen/np_codegen.dart'; import 'package:np_codegen/np_codegen.dart';
import 'package:np_collection/np_collection.dart'; import 'package:np_collection/np_collection.dart';
import 'package:np_log/np_log.dart';
import 'package:np_string/np_string.dart'; import 'package:np_string/np_string.dart';
import 'package:woozy_search/woozy_search.dart'; import 'package:woozy_search/woozy_search.dart';
@ -24,7 +24,7 @@ class Suggester<T> {
List<T> search(CiString phrase) { List<T> search(CiString phrase) {
final results = _searcher.search(phrase.toCaseInsensitiveString()); final results = _searcher.search(phrase.toCaseInsensitiveString());
if (kDebugMode) { if (isDevMode) {
final str = results.map((e) => "${e.score}: ${e.text}").join("\n"); final str = results.map((e) => "${e.score}: ${e.text}").join("\n");
_log.info("[search] Search '$phrase':\n$str"); _log.info("[search] Search '$phrase':\n$str");
} }

View file

@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:kiwi/kiwi.dart'; import 'package:kiwi/kiwi.dart';
@ -13,6 +12,7 @@ import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/snack_bar_manager.dart';
import 'package:np_codegen/np_codegen.dart'; import 'package:np_codegen/np_codegen.dart';
import 'package:np_log/np_log.dart';
import 'package:np_ui/np_ui.dart'; import 'package:np_ui/np_ui.dart';
import 'package:path/path.dart' as path_lib; import 'package:path/path.dart' as path_lib;
@ -226,7 +226,7 @@ class DirPickerState extends State<DirPicker> {
if (state is LsDirBlocSuccess) { if (state is LsDirBlocSuccess) {
if (!_fillResult(_root, state)) { if (!_fillResult(_root, state)) {
_log.shout("[_onStateChange] Failed while _fillResult" + _log.shout("[_onStateChange] Failed while _fillResult" +
(kDebugMode (isDevMode
? ", root:\n${_root.toString(isDeep: true)}\nstate: ${state.root.path}" ? ", root:\n${_root.toString(isDeep: true)}\nstate: ${state.root.path}"
: "")); : ""));
} }

View file

@ -1,5 +1,4 @@
import 'package:copy_with/copy_with.dart'; import 'package:copy_with/copy_with.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:kiwi/kiwi.dart'; import 'package:kiwi/kiwi.dart';
@ -13,6 +12,7 @@ import 'package:nc_photos/mobile/self_signed_cert_manager.dart';
import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/page_visibility_mixin.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart';
import 'package:np_codegen/np_codegen.dart'; import 'package:np_codegen/np_codegen.dart';
import 'package:np_log/np_log.dart';
import 'package:np_platform_util/np_platform_util.dart'; import 'package:np_platform_util/np_platform_util.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:to_string/to_string.dart'; import 'package:to_string/to_string.dart';
@ -90,7 +90,7 @@ class _WrappedDeveloperSettingsState extends State<_WrappedDeveloperSettings>
context.read<_Bloc>().add(const _VacuumDb()); context.read<_Bloc>().add(const _VacuumDb());
}, },
), ),
if (kDebugMode) ...[ if (isDevMode) ...[
ListTile( ListTile(
title: const Text("Export SQLite DB"), title: const Text("Export SQLite DB"),
onTap: () { onTap: () {

View file

@ -4,25 +4,41 @@ import 'package:test/test.dart';
void main() { void main() {
group("debug_util", () { group("debug_util", () {
group("logFilename", () { group("logFilename", () {
shouldLogFileName = false;
test("null", () { test("null", () {
expect(logFilename(null), "null"); expect(
logFilename(null, shouldLogFileName: false),
"null",
);
}); });
test("path + name + ext", () { test("path + name + ext", () {
expect(logFilename("path/to/a/fancy_file.ext"), "***/fan***ile.ext"); expect(
logFilename("path/to/a/fancy_file.ext", shouldLogFileName: false),
"***/fan***ile.ext",
);
}); });
test("path + short name + ext", () { test("path + short name + ext", () {
expect(logFilename("path/to/a/file01.ext"), "***/file01.ext"); expect(
logFilename("path/to/a/file01.ext", shouldLogFileName: false),
"***/file01.ext",
);
}); });
test("path + name", () { test("path + name", () {
expect(logFilename("path/to/a/fancy_file"), "***/fan***ile"); expect(
logFilename("path/to/a/fancy_file", shouldLogFileName: false),
"***/fan***ile",
);
}); });
test("name + ext", () { test("name + ext", () {
expect(logFilename("fancy_file"), "fan***ile"); expect(
logFilename("fancy_file", shouldLogFileName: false),
"fan***ile",
);
}); });
test("name", () { test("name", () {
expect(logFilename("fancy_file.ext"), "fan***ile.ext"); expect(
logFilename("fancy_file.ext", shouldLogFileName: false),
"fan***ile.ext",
);
}); });
}); });
}); });

View file

@ -1,7 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:np_api/src/util.dart'; import 'package:np_api/src/util.dart';
import 'package:np_log/np_log.dart';
import 'package:np_string/np_string.dart'; import 'package:np_string/np_string.dart';
import 'package:to_string/to_string.dart'; import 'package:to_string/to_string.dart';
@ -23,7 +23,7 @@ class Response {
/// Content of the response body, String if isResponseString == true during /// Content of the response body, String if isResponseString == true during
/// request, Uint8List otherwise /// request, Uint8List otherwise
@Format( @Format(
r"${kDebugMode ? $?.toString().replaceAll(RegExp(r'\n\t'), '').slice(0, 200) : '...'}") r"${isDevMode ? $?.toString().replaceAll(RegExp(r'\n\t'), '').slice(0, 200) : '...'}")
final dynamic body; final dynamic body;
} }

View file

@ -9,7 +9,7 @@ part of 'type.dart';
extension _$ResponseToString on Response { extension _$ResponseToString on Response {
String _$toString() { String _$toString() {
// ignore: unnecessary_string_interpolations // ignore: unnecessary_string_interpolations
return "Response {statusCode: $statusCode, headers: ..., body: ${kDebugMode ? body.toString().replaceAll(RegExp(r'\n\t'), '').slice(0, 200) : '...'}}"; return "Response {statusCode: $statusCode, headers: ..., body: ${isDevMode ? body.toString().replaceAll(RegExp(r'\n\t'), '').slice(0, 200) : '...'}}";
} }
} }

View file

@ -5,7 +5,7 @@ bool isHttpStatusGood(int status) => status ~/ 100 == 2;
void initLog() { void initLog() {
np_log.initLog( np_log.initLog(
isDebugMode: kDebugMode, isDebugMode: np_log.isDevMode,
print: (log) => debugPrint(log, wrapWidth: 1024), print: (log) => debugPrint(log, wrapWidth: 1024),
); );
} }

View file

@ -57,7 +57,7 @@ extension SqliteDbCompatExtension on SqliteDb {
_log.info( _log.info(
"[migrateV55] ${dateTimeUpdates.length} rows require updating, ${imageRemoves.length} rows require removing"); "[migrateV55] ${dateTimeUpdates.length} rows require updating, ${imageRemoves.length} rows require removing");
if (kDebugMode) { if (isDevMode) {
_log.fine( _log.fine(
"[migrateV55] dateTimeUpdates: ${dateTimeUpdates.map((e) => e.rowId).toReadableString()}"); "[migrateV55] dateTimeUpdates: ${dateTimeUpdates.map((e) => e.rowId).toReadableString()}");
_log.fine( _log.fine(

View file

@ -20,6 +20,7 @@ import 'package:np_db_sqlite/src/k.dart' as k;
import 'package:np_db_sqlite/src/table.dart'; import 'package:np_db_sqlite/src/table.dart';
import 'package:np_db_sqlite/src/util.dart'; import 'package:np_db_sqlite/src/util.dart';
import 'package:np_geocoder/np_geocoder.dart'; import 'package:np_geocoder/np_geocoder.dart';
import 'package:np_log/np_log.dart';
import 'package:np_platform_lock/np_platform_lock.dart'; import 'package:np_platform_lock/np_platform_lock.dart';
import 'package:np_platform_util/np_platform_util.dart'; import 'package:np_platform_util/np_platform_util.dart';

View file

@ -35,6 +35,8 @@ dependencies:
path: ../np_db path: ../np_db
np_geocoder: np_geocoder:
path: ../np_geocoder path: ../np_geocoder
np_log:
path: ../np_log
np_platform_lock: np_platform_lock:
path: ../np_platform_lock path: ../np_platform_lock
np_platform_util: np_platform_util:

View file

@ -1,3 +1,4 @@
library np_log; library np_log;
export 'src/dev_mode.dart';
export 'src/log.dart'; export 'src/log.dart';

View file

@ -0,0 +1 @@
const isDevMode = false;