로그 진단을 위한 프롬프트 엔지니어링 — Gemini와 실제로 효과적인 방법
Source: Dev.to

모든 테스트는 8년 된 MacBook Air에서 실행되었습니다.
“Analyze this log”는 일반적인 답변을 제공합니다.
“You are an Android specialist. Identify the root cause and the specific fix.”는 유용한 결과를 도출합니다.
프롬프트 설계는 대부분의 사람들이 기대하는 것보다 더 중요합니다. 아래는 HiyokoLogcat의 진단 기능을 위해 제가 거친 반복 과정입니다.
Version 1: Too vague
Analyze this Android logcat output and tell me what's wrong.
[logs]
결과: logcat이 무엇인지에 대한 긴 설명, NullPointerException에 대한 일반적인 조언, 구체적인 라인이 언급되지 않음.
Version 2: Role + constraint
You are an Android development specialist.
Analyze the following logcat output.
Identify the root cause and suggest a fix.
Be concise — 3‑5 sentences maximum.
[logs]
조금 나아짐. 간결한 출력이 나오지만, 여러 예외가 나타날 때 여전히 잘못된 오류에 초점을 맞추는 경우가 있음.
Version 3: Focus on the target line
let prompt = format!(
"You are an Android development specialist.\n\
The following logcat output contains an error.\n\
The KEY ERROR LINE is marked with >>.\n\
Identify the root cause of this specific error and suggest a fix.\n\
Be concise and specific. Point to the relevant line numbers if possible.\n\n\
Logcat:\n{}",
context_with_marker
);
컨텍스트에서 대상 라인을 표시합니다:
pub fn build_context_with_marker(
lines: &[LogLine],
target_idx: usize,
) -> String {
lines
.iter()
.enumerate()
.map(|(i, line)| {
if i == target_idx {
format!(">> {}", line.raw)
} else {
line.raw.clone()
}
})
.collect::>()
.join("\n")
}
>> 마커가 Gemini에게 정확히 어느 오류에 집중해야 하는지 알려줍니다. 품질이 크게 향상되었습니다.
Version 4: Language‑aware (current)
앱은 일본어와 영어를 지원합니다. 시스템 프롬프트는 UI 언어에 따라 전환됩니다:
let system = match lang {
Lang::Japanese =>
"あなたはAndroid開発のスペシャリストです。\
以下のlogcatからエラー原因と解決策を日本語で簡潔に答えてください。\
KEY ERROR LINEが対象のエラーです。",
Lang::English =>
"You are an Android development specialist. \
Identify the root cause of the KEY ERROR LINE \
and suggest a fix. Be concise and specific.",
};
일본어 프롬프트 → 일본어 응답. 후처리가 필요 없습니다.
What I learned
가장 중요한 세 가지 요소:
- 역할 부여 – “You are a specialist”라고 명시하면 출력이 실제로 개선됩니다.
- 대상 표시 – 모델에게 정확히 어느 라인에 집중해야 하는지 알려줍니다.
- 길이 제한 – “3‑5 sentences”라고 지정하면 장문의 에세이를 방지할 수 있습니다.
그 외의 모든 것은 잡음에 불과합니다.
HiyokoLogcat은 무료이며 오픈 소스입니다 →
X에서 저를 팔로우하세요 → @hiyoyok