|
1 | 1 | part of '../common.dart'; |
2 | 2 |
|
3 | 3 | class ApiConfig { |
4 | | - static bool get printLog => _printLog ??= false; |
| 4 | + static _LogConfig get logConfig => _logConfig ??= _LogConfig(); |
5 | 5 |
|
6 | | - static set printLog(bool value) => _printLog = value; |
| 6 | + static set logConfig(_LogConfig value) => _logConfig = value; |
7 | 7 |
|
8 | | - static bool? _printLog; |
| 8 | + static _LogConfig? _logConfig; |
| 9 | +} |
| 10 | + |
| 11 | +class _LogConfig { |
| 12 | + factory _LogConfig({ |
| 13 | + bool enableLog = false, |
| 14 | + bool request = true, |
| 15 | + bool requestHeader = true, |
| 16 | + bool requestBody = true, |
| 17 | + bool responseHeader = true, |
| 18 | + bool responseBody = true, |
| 19 | + bool error = true, |
| 20 | + }) { |
| 21 | + _instance ??= _LogConfig._internal( |
| 22 | + enableLog: enableLog, |
| 23 | + showRequest: request, |
| 24 | + showRequestHeader: requestHeader, |
| 25 | + showRequestBody: requestBody, |
| 26 | + showResponseHeader: responseHeader, |
| 27 | + showResponseBody: responseBody, |
| 28 | + showError: error, |
| 29 | + ); |
| 30 | + return _instance!; |
| 31 | + } |
| 32 | + |
| 33 | + _LogConfig._internal({ |
| 34 | + required this.enableLog, |
| 35 | + required this.showRequest, |
| 36 | + required this.showRequestHeader, |
| 37 | + required this.showRequestBody, |
| 38 | + required this.showResponseHeader, |
| 39 | + required this.showResponseBody, |
| 40 | + required this.showError, |
| 41 | + }); |
| 42 | + |
| 43 | + bool enableLog; |
| 44 | + bool showRequest; |
| 45 | + bool showRequestHeader; |
| 46 | + bool showRequestBody; |
| 47 | + bool showResponseHeader; |
| 48 | + bool showResponseBody; |
| 49 | + bool showError; |
| 50 | + |
| 51 | + static _LogConfig? _instance; |
| 52 | + |
| 53 | + @override |
| 54 | + String toString() => |
| 55 | + 'Log Enabled: ${enableLog.capitalize}\nShow Request: ${showRequest.capitalize}\nShow Request Header: ${showRequestHeader.capitalize}\nShow Request Body: ${showRequestBody.capitalize}\nShow Response Header: ${showResponseHeader.capitalize}\nShow Response Body: ${showResponseBody.capitalize}\nShow Error: ${showError.capitalize}'; |
9 | 56 | } |
0 commit comments