File tree 3 files changed +40
-2
lines changed 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change 1
1
import 'dart:convert' ;
2
2
3
- import 'package:flutter/foundation.dart' ;
4
3
import 'package:http/http.dart' as http;
5
4
5
+ import '../log.dart' ;
6
+
6
7
class Auth {
7
8
Auth ({required this .realmUrl, required this .email, required this .apiKey})
8
9
: assert (realmUrl.query.isEmpty && realmUrl.fragment.isEmpty);
@@ -74,7 +75,7 @@ class LiveApiConnection extends ApiConnection {
74
75
assert (_isOpen);
75
76
final url = auth.realmUrl.replace (
76
77
path: "/api/v1/$route " , queryParameters: encodeParameters (params));
77
- if (kDebugMode) print ("GET $url " );
78
+ assert ( debugLog ("GET $url " ) );
78
79
final response = await _client.get (url, headers: _headers ());
79
80
if (response.statusCode != 200 ) {
80
81
throw Exception ("error on GET $route : status ${response .statusCode }" );
Original file line number Diff line number Diff line change
1
+
2
+ /// Whether [debugLog] should do anything.
3
+ ///
4
+ /// This has an effect only in a debug build.
5
+ bool debugLogEnabled = false ;
6
+
7
+ /// Print a log message, if debug logging is enabled.
8
+ ///
9
+ /// In a debug build, if [debugLogEnabled] is true, this prints the given
10
+ /// message to the log. Otherwise it does nothing.
11
+ ///
12
+ /// Typically we set [debugLogEnabled] so that this will print when running
13
+ /// the app in a debug build, but not when running tests.
14
+ ///
15
+ /// Call sites of this function should be enclosed in `assert` expressions, so
16
+ /// that any interpolation to construct the message happens only in debug mode.
17
+ /// To help make that convenient, this function always returns true.
18
+ ///
19
+ /// Example usage:
20
+ /// ```dart
21
+ /// assert(debugLog("Got frobnitz: $frobnitz"));
22
+ /// ```
23
+ bool debugLog (String message) {
24
+ assert (() {
25
+ // TODO(log): make it convenient to enable these logs in tests for debugging a failing test
26
+ if (debugLogEnabled) {
27
+ print (message); // ignore: avoid_print
28
+ }
29
+ return true ;
30
+ }());
31
+ return true ;
32
+ }
Original file line number Diff line number Diff line change 1
1
import 'package:flutter/material.dart' ;
2
2
3
+ import 'log.dart' ;
3
4
import 'widgets/app.dart' ;
4
5
5
6
void main () {
7
+ assert (() {
8
+ debugLogEnabled = true ;
9
+ return true ;
10
+ }());
6
11
runApp (const ZulipApp ());
7
12
}
You can’t perform that action at this time.
0 commit comments