log_util.dart
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import 'package:wow_english/common/request/basic_config.dart';
enum LogLevel { debug, info, warning, error }
class Log {
static LogLevel level = BasicConfig.isTestDev ? LogLevel.debug : LogLevel.error;
/// debug
static void d(Object? object) {
if (level.index <= LogLevel.debug.index) {
String line = "$object";
print(line);
}
}
/// info
static void i(Object? object) {
if (level.index <= LogLevel.info.index) {
String line = "$object";
print(line);
}
}
/// warning
static void w(Object? object) {
if (level.index <= LogLevel.warning.index) {
String line = "$object";
print(line);
}
}
/// error
static void e(Object? object) {
if (level.index <= LogLevel.error.index) {
String line = "$object";
print(line);
}
}
}
extension LogExtension on Object? {
Object? logD() {
Log.d(this);
return this;
}
Object? logI() {
Log.i(this);
return this;
}
Object? logW() {
Log.w(this);
return this;
}
Object? logE() {
Log.e(this);
return this;
}
}