-
-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathtalker_dio_logger_settings.dart
More file actions
185 lines (159 loc) · 5.93 KB
/
Copy pathtalker_dio_logger_settings.dart
File metadata and controls
185 lines (159 loc) · 5.93 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import 'package:dio/dio.dart';
import 'package:talker/talker.dart';
/// [TalkerDioLogger] settings and customization
class TalkerDioLoggerSettings {
const TalkerDioLoggerSettings({
this.enabled = true,
this.logLevel = LogLevel.debug,
this.printResponseData = true,
this.printResponseHeaders = false,
this.printResponseMessage = true,
this.printResponseRedirects = false,
this.printResponseTime = false,
this.printErrorData = true,
this.printErrorHeaders = true,
this.printErrorMessage = true,
this.printRequestData = true,
this.printRequestHeaders = false,
this.printRequestExtra = false,
this.logTimestamp = false,
this.timestampFormat = TimeFormat.yearMonthDayAndTime,
this.timestampLabel = 'Date',
this.hiddenHeaders = const <String>{},
this.responseDataConverter,
this.requestPen,
this.responsePen,
this.errorPen,
this.requestFilter,
this.responseFilter,
this.errorFilter,
});
// Print Dio logger if true
final bool enabled;
// LogLevel of all dio logs. By default set as debug
final LogLevel logLevel;
/// Print [response.data] if true
final bool printResponseData;
/// Print [response.headers] if true
final bool printResponseHeaders;
/// Print [response.statusMessage] if true
final bool printResponseMessage;
/// Print [response.redirects] if true
final bool printResponseRedirects;
/// Print response time if true
final bool printResponseTime;
/// Print [error.response.data] if true
final bool printErrorData;
/// Print [error.response.headers] if true
final bool printErrorHeaders;
/// Print [error.message] if true
final bool printErrorMessage;
/// Print [request.data] if true
final bool printRequestData;
/// Print [request.headers] if true
final bool printRequestHeaders;
/// Print [request.extra] if true
final bool printRequestExtra;
/// Print timestamp in logs if true
final bool logTimestamp;
/// The [TimeFormat] used when [logTimestamp] is enabled.
/// Defaults to [TimeFormat.yearMonthDayAndTime].
final TimeFormat timestampFormat;
/// The label printed before the timestamp value when [logTimestamp] is enabled.
/// Defaults to `'Date'`.
final String timestampLabel;
/// Field to set custom http request console logs color
///```
///// Red color
///final redPen = AnsiPen()..red();
///
///// Blue color
///final redPen = AnsiPen()..blue();
///```
/// More details in [AnsiPen] docs
final AnsiPen? requestPen;
/// Field to set custom http response console logs color
///```
///// Red color
///final redPen = AnsiPen()..red();
///
///// Blue color
///final redPen = AnsiPen()..blue();
///```
/// More details in [AnsiPen] docs
final AnsiPen? responsePen;
/// Field to set custom http error console logs color
///```
///// Red color
///final redPen = AnsiPen()..red();
///
///// Blue color
///final redPen = AnsiPen()..blue();
///```
/// More details in [AnsiPen] docs
final AnsiPen? errorPen;
/// For request filtering.
/// You can add your custom logic to log only specific HTTP requests [RequestOptions].
final bool Function(RequestOptions requestOptions)? requestFilter;
/// For response filtering.
/// You can add your custom logic to log only specific HTTP responses [Response].
final bool Function(Response response)? responseFilter;
/// response data converter.
final String Function(Response response)? responseDataConverter;
/// For error filtering.
/// You can add your custom logic to log only specific Dio error [DioException].
final bool Function(DioException response)? errorFilter;
/// Header values for the specified keys in the Set will be replaced with *****.
/// Case insensitive
final Set<String> hiddenHeaders;
TalkerDioLoggerSettings copyWith({
bool? printResponseData,
bool? printResponseHeaders,
bool? printResponseMessage,
bool? printResponseTime,
bool? printErrorData,
bool? printErrorHeaders,
bool? printErrorMessage,
bool? printRequestData,
bool? printRequestHeaders,
bool? printRequestExtra,
bool? logTimestamp,
TimeFormat? timestampFormat,
String? timestampLabel,
AnsiPen? requestPen,
AnsiPen? responsePen,
AnsiPen? errorPen,
bool Function(RequestOptions requestOptions)? requestFilter,
bool Function(Response response)? responseFilter,
String Function(Response response)? responseDataConverter,
bool Function(DioException response)? errorFilter,
Set<String>? hiddenHeaders,
LogLevel? logLevel,
}) {
return TalkerDioLoggerSettings(
printResponseData: printResponseData ?? this.printResponseData,
printResponseHeaders: printResponseHeaders ?? this.printResponseHeaders,
printResponseMessage: printResponseMessage ?? this.printResponseMessage,
printResponseTime: printResponseTime ?? this.printResponseTime,
printErrorData: printErrorData ?? this.printErrorData,
printErrorHeaders: printErrorHeaders ?? this.printErrorHeaders,
printErrorMessage: printErrorMessage ?? this.printErrorMessage,
printRequestData: printRequestData ?? this.printRequestData,
printRequestHeaders: printRequestHeaders ?? this.printRequestHeaders,
printRequestExtra: printRequestExtra ?? this.printRequestExtra,
logTimestamp: logTimestamp ?? this.logTimestamp,
timestampFormat: timestampFormat ?? this.timestampFormat,
timestampLabel: timestampLabel ?? this.timestampLabel,
requestPen: requestPen ?? this.requestPen,
responsePen: responsePen ?? this.responsePen,
errorPen: errorPen ?? this.errorPen,
requestFilter: requestFilter ?? this.requestFilter,
responseFilter: responseFilter ?? this.responseFilter,
responseDataConverter:
responseDataConverter ?? this.responseDataConverter,
errorFilter: errorFilter ?? this.errorFilter,
hiddenHeaders: hiddenHeaders ?? this.hiddenHeaders,
logLevel: logLevel ?? this.logLevel,
);
}
}