Repository navigation
Expand file tree
/
Copy pathtalker_chopper_logger_settings.dart
More file actions
194 lines (169 loc) · 6.02 KB
/
Copy pathtalker_chopper_logger_settings.dart
File metadata and controls
194 lines (169 loc) · 6.02 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
186
187
188
189
190
191
192
193
194
import 'package:chopper/chopper.dart' show Response, Request;
import 'package:equatable/equatable.dart';
import 'package:talker/talker.dart' show AnsiPen, LogLevel, TalkerJsonFormatter;
typedef RequestFilter = bool Function(Request request);
typedef ResponseFilter = bool Function(Response response);
class TalkerChopperLoggerSettings with EquatableMixin {
const TalkerChopperLoggerSettings({
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.printRequestCurl = false,
this.hiddenHeaders = const <String>{},
this.jsonFormatter = const TalkerJsonFormatter(),
this.requestPen,
this.responsePen,
this.errorPen,
this.requestFilter,
this.responseFilter,
this.errorFilter,
});
/// Print Chopper logger if true
final bool enabled;
// LogLevel, default is 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;
/// Prints a curl request equivalent of the network call if true
final bool printRequestCurl;
/// 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 [Request].
final RequestFilter? requestFilter;
/// For response filtering.
/// You can add your custom logic to log only specific HTTP responses [Response].
final ResponseFilter? responseFilter;
/// For error filtering.
/// You can add your custom logic to log only specific Chopper error [Response].
final ResponseFilter? errorFilter;
/// Header values for the specified keys in the Set will be replaced with *****.
/// Case insensitive
final Set<String> hiddenHeaders;
/// JSON formatter for converting data to pretty string.
/// Use [TalkerJsonFormatter] for default formatting,
/// [TalkerJsonFormatter(stripQuotes: true)] to strip quotes,
/// or [TalkerJsonFormatter.custom(fn)] for custom formatting.
final TalkerJsonFormatter jsonFormatter;
TalkerChopperLoggerSettings copyWith({
bool? enabled,
LogLevel? logLevel,
bool? printResponseData,
bool? printResponseHeaders,
bool? printResponseMessage,
bool? printResponseTime,
bool? printErrorData,
bool? printErrorHeaders,
bool? printErrorMessage,
bool? printRequestData,
bool? printRequestHeaders,
bool? printRequestCurl,
AnsiPen? requestPen,
AnsiPen? responsePen,
AnsiPen? errorPen,
RequestFilter? requestFilter,
ResponseFilter? responseFilter,
ResponseFilter? errorFilter,
Set<String>? hiddenHeaders,
TalkerJsonFormatter? jsonFormatter,
}) =>
TalkerChopperLoggerSettings(
enabled: enabled ?? this.enabled,
logLevel: logLevel ?? this.logLevel,
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,
printRequestCurl: printRequestCurl ?? this.printRequestCurl,
requestPen: requestPen ?? this.requestPen,
responsePen: responsePen ?? this.responsePen,
errorPen: errorPen ?? this.errorPen,
requestFilter: requestFilter ?? this.requestFilter,
responseFilter: responseFilter ?? this.responseFilter,
errorFilter: errorFilter ?? this.errorFilter,
hiddenHeaders: hiddenHeaders ?? this.hiddenHeaders,
jsonFormatter: jsonFormatter ?? this.jsonFormatter,
);
@override
List<Object?> get props => [
enabled,
printResponseData,
printResponseHeaders,
printResponseMessage,
printResponseTime,
printErrorData,
printErrorHeaders,
printErrorMessage,
printRequestData,
printRequestHeaders,
printRequestCurl,
requestPen,
responsePen,
errorPen,
requestFilter,
responseFilter,
errorFilter,
hiddenHeaders,
jsonFormatter,
];
}