सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
एक डार्ट पैकेज जो डार्ट या फ्लटर एप्लिकेशन में HTTP ट्रैफ़िक लॉगिंग को बिना किसी दिक्कत के एकीकृत करता है। इससे विकासकर्ता को न्यूनतम सेटअप के साथ HTTP रिक्वेस्ट और रिस्पॉन्स को मॉनिटर और डिबग करने में सहायता मिलती है, जिससे नेटवर्क व्यवहार के बारे में विस्तृत जानकारी मिलती है। API संचार में समस्याओं की पहचान, रिक्वेस्ट/रिस्पॉन्स हेडर का ट्रैकिंग और विकास के दौरान प्रदर्शन के विश्लेषण के लिए आदर्श है। पैकेज हल्का है और सभी प्रमुख प्लेटफॉर्म, जैसे मोबाइल, डेस्कटॉप और वेब में संगत है।
उपयोग
API कॉल्स का डीबगिंग
नेटवर्क प्रदर्शन का निगरानी करें
ट्रैकिंग अनुरोध/प्रतिक्रिया हेडर
बैकएंड इंटीग्रेशन का परीक्षण
HTTP त्रुटियों का विश्लेषण
मुख्य विशेषताएँ
HTTP अनुरोधों और प्रतिक्रियाओं का स्वचालित लॉगिंग
सभी डार्ट/फ्लटर प्लेटफॉर्म के लिए समर्थन
आवश्यक न्यूनतम सेटिंग
समयांकित सहित पठनीय लॉग आउटपुट
कस्टम लॉगिंग लॉजिक के लिए विस्तार्य
इनके लिए उपयुक्त
विकासकर्मी एपीआई समस्याओं का निदान कर रहे हैं
मजबूत डिबगिंग कार्यप्रवाह का कार्यान्वयन करने वाली टीमें
पारदर्शी नेटवर्क मॉनिटरिंग की आवश्यकता वाले प्रोजेक्ट
REST APIs के साथ काम कर रहे फ्रंटएंड विकासकर्ता
विस्तृत HTTP ट्रेसिबिलिटी की आवश्यकता वाले परीक्षण वातावरण
विचार योग्य बातें
सुरक्षा जोखिम के कारण उत्पादन उपयोग के लिए सुझाव नहीं है
लॉग में संवेदनशील डेटा हो सकता है
उच्च-आवृत्ति परिदृश्यों में प्रदर्शन अतिरिक्त खर्च
अपने लॉग को बेहतर तरीके से प्रबंधित करने की आवश्यकता है ताकि गड़बड़ी न हो
रिलीज बिल्ड में अक्षम होना चाहिए
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
HttpTools
A comprehensive collection of Dart and Flutter packages for HTTP request handling, providing intercepting, logging, and caching capabilities to enhance your network operations.
✅ Smart Binary Detection - Clean logs without garbage data
✅ Production Ready - Configurable for development vs production
✅ Human Readable - Clean, structured log format
Log Output Examples:
[a1b2c3d4] --> GET https://api.example.com/users/123
[a1b2c3d4] authorization: Bearer ***
[a1b2c3d4] content-type: application/json
[a1b2c3d4] --> END GET
[a1b2c3d4] <-- 200OK (145ms)
[a1b2c3d4] content-type: application/json
[a1b2c3d4] {"id": 123, "name": "John Doe"}
[a1b2c3d4] <-- END
Usage:
import'package:http_client_logger/http_client_logger.dart';
import'package:logging/logging.dart'hideLevel;
// Set up loggingLogger.root.onRecord.listen((record) => print(record.message));
// Configure loggerHttpClientProxy(
interceptors: [
HttpLogger(
level: Level.body, // basic | headers | body
logBodyContentTypes: {'application/json'}, // Only log JSON as text
),
],
)
http_client_cache
HTTP caching with disk/memory storage - Improve performance and reduce network usage
Key Features:
✅ RFC 7234 Compliant - Standard HTTP caching behavior
✅ Memory & Disk Storage - Choose what fits your needs
✅ Cache-Control Support - Respects server cache directives
✅ Stale-While-Revalidate - Serve stale content while updating
✅ Stale-If-Error - Fallback to cache when network fails
✅ Automatic Cleanup - LRU eviction and size limits
✅ Private Content Filtering - Secure handling of sensitive data
Cache Behavior Examples:
Cache miss for https://api.example.com/posts/1 # First requestCache hit for https://api.example.com/posts/1 # Served from cacheCache entry expired for https://api.example.com/posts/1 # Needs refreshServing stale content due to network error # Stale-if-error fallback
HttpClientProxy(
interceptors: [
if (kDebugMode) HttpLogger(level: Level.body), // Only log in debugAuthInterceptor(apiKey),
cache,
],
)
Custom Cache Control
classCacheControlInterceptorextendsHttpInterceptor{
@overrideFutureOr<OnResponse> onResponse(StreamedResponse response) {
final headers = Map<String, String>.from(response.headers);
// Cache API responses with resilience featuresif (response.request?.url.path.startsWith('/api/') ?? false) {
headers['cache-control'] =
'max-age=300, stale-while-revalidate=60, stale-if-error=3600';
// Cache for 5 min, serve stale for 1 min while revalidating,// serve stale for 1 hour if network fails
}
returnOnResponse.next(response.copyWith(headers: headers));
}
}
🔗 Framework Compatibility
Works seamlessly with popular HTTP packages:
✅ http - A composable, multi-platform, Future-based API for HTTP requests.
✅ chopper - An http client generator using source_gen, inspired by Retrofit
✅ retrofit - An dio client generator using source_gen and inspired by Chopper and Retrofit
Note:dio and retrofit (which uses dio) require the dio_compatibility_layer package to work with the standard http package that these interceptors depend on.
dependencies:http:^1.2.0dio_compatibility_layer:^3.0.0# Required for dio/retrofit compatibility
📊 Performance Considerations
Development vs Production:
HttpClientProxy(
interceptors: [
// Production: Only basic loggingif (kReleaseMode) HttpLogger(level: Level.basic),
// Development: Full logging with bodies if (kDebugMode) HttpLogger(level: Level.body),
// Always cache for better performance
cache,
],
)
Memory Management:
Cache automatically manages size with LRU eviction
Use cache.clearCache() when memory is low
Use cache.deletePrivateContent() when user logs out