Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refine logging level and stopwatch checks

Priyanshu Dangare51c99144c588
diff --git a/mobile/apps/photos/lib/core/error-reporting/super_logging.dart b/mobile/apps/photos/lib/core/error-reporting/super_logging.dart
index 6fd7a0f485..0063ce984e 100644
--- a/mobile/apps/photos/lib/core/error-reporting/super_logging.dart
+++ b/mobile/apps/photos/lib/core/error-reporting/super_logging.dart
@@ -167,10 +167,9 @@ class SuperLogging {
/// The logger for SuperLogging
static final $ = Logger('ente_logging');
- static const _rootLogLevelDefine = String.fromEnvironment('ENTE_LOG_LEVEL');
- static const _loggerPrefixDefine = String.fromEnvironment(
+ static final String _loggerPrefixDefine = const String.fromEnvironment(
'ENTE_LOGGER_PREFIX',
- );
+ ).trim().toLowerCase();
/// The current super logging configuration
static late LogConfig config;
@@ -413,32 +412,21 @@ class SuperLogging {
static String _lastExtraLines = '';
- static Level get rootLoggerLevel =>
- _levelFromName(_rootLogLevelDefine) ??
+ static final Level rootLoggerLevel =
+ Level.LEVELS
+ .where(
+ (level) =>
+ level.name.toLowerCase() ==
+ const String.fromEnvironment(
+ 'ENTE_LOG_LEVEL',
+ ).trim().toLowerCase(),
+ )
+ .firstOrNull ??
(kDebugMode ? Level.ALL : Level.INFO);
- static String get loggerPrefixFilter => _loggerPrefixDefine.trim();
-
static bool shouldLogRecord(LogRecord rec) {
- final prefix = loggerPrefixFilter;
- return prefix.isEmpty || rec.loggerName.startsWith(prefix);
- }
-
- static Level? _levelFromName(String name) {
- return switch (name.trim().toUpperCase()) {
- '' => null,
- 'ALL' => Level.ALL,
- 'SHOUT' => Level.SHOUT,
- 'SEVERE' || 'ERROR' => Level.SEVERE,
- 'WARNING' || 'WARN' => Level.WARNING,
- 'INFO' => Level.INFO,
- 'CONFIG' => Level.CONFIG,
- 'FINE' || 'DEBUG' => Level.FINE,
- 'FINER' => Level.FINER,
- 'FINEST' || 'TRACE' => Level.FINEST,
- 'OFF' => Level.OFF,
- _ => null,
- };
+ return _loggerPrefixDefine.isEmpty ||
+ rec.loggerName.toLowerCase().startsWith(_loggerPrefixDefine);
}
static Future onLogRecord(LogRecord rec) async {
diff --git a/mobile/packages/ente_pure_utils/lib/src/stop_watch.dart b/mobile/packages/ente_pure_utils/lib/src/stop_watch.dart
index 0a07cd7779..5574aeb05b 100644
--- a/mobile/packages/ente_pure_utils/lib/src/stop_watch.dart
+++ b/mobile/packages/ente_pure_utils/lib/src/stop_watch.dart
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
+import 'package:logging/logging.dart';
class EnteWatch extends Stopwatch {
final String context;
@@ -6,8 +7,11 @@ class EnteWatch extends Stopwatch {
EnteWatch(this.context) : super();
+ static final bool _shouldLog =
+ kDebugMode && Logger.root.isLoggable(Level.INFO);
+
void log(String msg) {
- if (kDebugMode) {
+ if (_shouldLog) {
debugPrint(
"[$context]: $msg took ${Duration(microseconds: elapsedMicroseconds - previousElapsed).inMilliseconds} ms total: "
"${elapsed.inMilliseconds} ms",
@@ -17,7 +21,7 @@ class EnteWatch extends Stopwatch {
}
void logAndReset(String msg) {
- if (kDebugMode) {
+ if (_shouldLog) {
debugPrint("[$context]: $msg took ${elapsed.inMilliseconds} ms");
}
reset();