문서 목차
이 페이지에서목차

HTTP Logging Rules

TalkerDioLogger configuration and security guide for HTTP request/response logging.

TalkerDioLogger configuration and security guide for HTTP request/response logging.

HttpModule Interceptor Order#

package/openapi_service/lib/src/http/http_module.dartof the Interceptor chain:

OrderInterceptorRole
1DioCacheInterceptorResponse caching (HiveStore/MemStore)
2Setting interceptorsCustom setting interceptors
3AuthInterceptorAuth token injection
4RateLimitInterceptorRequest rate limiting
5TalkerDioLoggerHTTP Logging (Debug mode only)
6RetryInterceptorRetry on failure

TalkerDioLogger Configuration#

Default Configuration#

import 'package:flutter/foundation.dart' show kDebugMode;
import 'package:talker_dio_logger/talker_dio_logger.dart';

// Enabled only in debug mode
if (kDebugMode) {
  dio.interceptors.add(
    TalkerDioLogger(
      settings: const TalkerDioLoggerSettings(
        printRequestHeaders: true,
        printResponseHeaders: true,
      ),
    ),
  );
}

Configuration Options#

OptionDefaultDescription
printRequestHeadersfalsePrint request headers
printResponseHeadersfalsePrint response headers
printResponseMessagetruePrint response message
printRequestDatatruePrint request body
printResponseDatatruePrint response body

Extended Configuration (if needed)#

TalkerDioLogger(
  settings: TalkerDioLoggerSettings(
    printRequestHeaders: true,
    printResponseHeaders: true,
    // 에러만 출력
    printErrorData: true,
    printErrorHeaders: true,
    printErrorMessage: true,
    // Request/response data filtering
    requestFilter: (options) => !options.path.contains('/health'),
    responseFilter: (response) => response.statusCode != 200,
  ),
)

Security Rules#

Sensitive Information Logging Prohibited#

// ❌ Prohibited: Including sensitive info in logs
Log.d('🔐 로그인: userId=$userId, password=$password');
Log.d('🔄 토큰: accessToken=$accessToken');

// ✅ 권장: 상태만 기록
Log.d('🔐 로그인 API 호출');
Log.d('🔄 토큰 갱신 완료');

Sensitive Information List#

TypeExampleLogging
Credentialspassword, pin, userPw❌ Prohibited
TokensaccessToken, refreshToken, idToken❌ Prohibited
IdentificationuserId, loginId (except debugging)⚠️ Caution
Personal InfophoneNumber, email, address❌ Prohibited
Auth CodessmsCode, verificationCode❌ Prohibited

kDebugMode Pattern#

Correct Usage#

import 'package:flutter/foundation.dart' show kDebugMode;

// ✅ Compile-time constant, removed from production code
if (kDebugMode) {
  // Debug-only code
}

Precautions#

// ❌ 금지: Runtime check (code included in production)
final isDebug = !const bool.fromEnvironment('dart.vm.product');
if (isDebug) { ... }

// ✅ 권장: kDebugMode 사용
if (kDebugMode) { ... }

Checklist#

When Adding a Logger#

  • kDebugMode Add logger within condition
  • Verify logging is disabled in production builds
  • Review for sensitive information logging

During PR Review#

  • No sensitive info in new logs
  • kDebugMode Conditional logging usage
  • No unnecessary verbose logging

Logging Style for Mapper and Repository Mixin#

Log Message Hierarchy#

LayerPatternExample
Mapper Structured logging only Log.e('msg', error: e, stackTrace: st)
Repository start Fixed message Log.d('📝 API Call')
Repository Success Including result Log.d('✅ Complete: ${count}개')
Repository Error Structured logging Log.e('msg', error: e, stackTrace: st)

Structured Logging Pattern (Required)#

// ✅ CORRECT: error 파라미터 포함
Log.e('❌ Homework API Error', error: error, stackTrace: stackTrace);

// ❌ WRONG: error 파라미터 누락
Log.e('❌ Homework API Error: $error');
Log.e('❌ Homework API Error');

// ❌ WRONG: stackTrace 누락
Log.e('❌ Homework API Error', error: error);

Reason#

  1. Consistency: All error logging follows the same structure
  2. Parsing: Log aggregation tools (Stack Driver, etc.) can parse error field
  3. Information preservation: stackTrace stored as structured field
  • 프로젝트 루트의 CLAUDE.md(AGENTS.md) - HTTP debugging section

검색어를 입력하면 문서를 찾습니다.

↑ ↓ 이동 · Enter 열기Esc 닫기