Dart 또는 Flutter 애플리케이션에 HTTP 트래픽 로깅을 원활하게 통합하는 Dart 패키지입니다. 최소한의 설정으로 HTTP 요청과 응답을 모니터링하고 디버깅할 수 있으며, 네트워크 동작에 대한 자세한 인사이트를 제공합니다. API 통신 문제 식별, 요청/응답 헤더 추적, 개발 중 성능 분석에 이상적입니다. 가볍고 모든 주요 플랫폼(모바일, 데스크톱, 웹)과 호환됩니다.
사용 사례
API 호출 디버깅
네트워크 성능 모니터링
요청/응답 헤더 추적
백엔드 통합 테스트
HTTP 오류 분석
주요 기능
HTTP 요청 및 응답의 자동 로깅
모든 Dart/Flutter 플랫폼 지원
필수 최소 구성
타임스탬프가 있는 읽기 쉬운 로그 출력
사용자 정의 로깅 로직을 위한 확장 가능
적합한 대상
개발자가 API 문제 해결 중
강력한 디버깅 워크플로를 구현하는 팀
투명한 네트워크 모니터링이 필요한 프로젝트
REST API를 사용하는 프론트엔드 개발자
세부 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