AgentSkillsCN

debug-log-patterns

针对不同编程语言的调试日志记录模式与最佳实践。在为 Dart/Flutter、Kotlin/Android、Swift/iOS,或 JavaScript/TypeScript 应用添加监控与日志记录功能时,可参考此技能。

SKILL.md
--- frontmatter
name: debug-log-patterns
description: Language-specific debug logging patterns and best practices. Reference when adding instrumentation for Dart/Flutter, Kotlin/Android, Swift/iOS, or JavaScript/TypeScript applications.

Debug Log Patterns

Overview

This skill provides copy-paste-ready logging patterns for common debugging scenarios across multiple languages. Use these patterns when instrumenting code during PDCA debug cycles.

Supported Languages

LanguageFilePrimary Use Case
Dart/Flutterreferences/dart-flutter.mdFlutter mobile/web apps
Kotlin/Androidreferences/kotlin-android.mdNative Android apps
Swift/iOSreferences/swift-ios.mdNative iOS apps
JavaScript/TypeScriptreferences/javascript-typescript.mdWeb apps, Node.js, React Native

Universal Conventions

Log Format Standard

All logs should follow this format for consistency:

code
[ClassName] methodName: description key=value

Log Levels

LevelWhen to Use
DEBUG/TRACEDetailed flow tracing, variable values
INFOSignificant events, state transitions
WARNUnexpected but recoverable situations
ERRORFailures that affect functionality

Common Patterns (All Languages)

Pattern: Method Entry/Exit

code
[ClassName] methodName: ENTER params=(param1, param2)
[ClassName] methodName: EXIT result=value

Pattern: Conditional Branch

code
[ClassName] methodName: condition branch=TAKEN/SKIPPED reason=why

Pattern: Loop Iteration

code
[ClassName] methodName: loop iteration=N/total item=current

Pattern: State Transition

code
[ClassName] methodName: state from=oldState to=newState trigger=event

Pattern: Async Operation

code
[ClassName] operationName: START
[ClassName] operationName: SUCCESS result=summary
[ClassName] operationName: ERROR error=message

Quick Selection Guide

Debugging Flutter/Dart app? -> See references/dart-flutter.md

Debugging Android native (Kotlin)? -> See references/kotlin-android.md

Debugging iOS native (Swift)? -> See references/swift-ios.md

Debugging web/Node.js/React? -> See references/javascript-typescript.md

Best Practices

  1. Be specific - Include actual values, not just "value changed"
  2. Be consistent - Use the same format throughout the codebase
  3. Be temporary - Remove debug logs after issue is resolved
  4. Be contextual - Include enough info to understand without seeing code
  5. Be careful with sensitive data - Never log passwords, tokens, PII

References

  • references/dart-flutter.md - Dart/Flutter logging patterns
  • references/kotlin-android.md - Kotlin/Android logging patterns
  • references/swift-ios.md - Swift/iOS logging patterns
  • references/javascript-typescript.md - JavaScript/TypeScript logging patterns