DEV Community

Cover image for Prompt Engineering for Log Diagnosis — What Actually Works With Gemini
hiyoyo
hiyoyo

Posted on

Prompt Engineering for Log Diagnosis — What Actually Works With Gemini

All tests run on an 8-year-old MacBook Air.

"Analyze this log" produces a generic answer.
"You are an Android specialist. Identify the root cause and the specific fix." produces something useful.

Prompt design matters more than most people expect. Here's what I iterated through for HiyokoLogcat's diagnosis feature.


Version 1: too vague

Analyze this Android logcat output and tell me what's wrong.

[logs]
Enter fullscreen mode Exit fullscreen mode

Result: long explanations of what logcat is, generic advice about NullPointerExceptions, no specific lines called out.


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]
Enter fullscreen mode Exit fullscreen mode

Better. Concise output. But still sometimes focused on the wrong error when multiple exceptions appeared.


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
);
Enter fullscreen mode Exit fullscreen mode

Mark the target line in the context:

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")
}
Enter fullscreen mode Exit fullscreen mode

The >> marker tells Gemini exactly which error to focus on. Quality improved significantly.


Version 4: language-aware (current)

The app supports Japanese and English. The system prompt switches based on UI language:

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.",
};
Enter fullscreen mode Exit fullscreen mode

Japanese prompt → Japanese response. No post-processing needed.


What I learned

Three things matter most:

  1. Role assignment — "You are a specialist" genuinely improves output
  2. Target marking — tell the model exactly which line to focus on
  3. Length constraint — "3-5 sentences" prevents essays

Everything else is noise.


HiyokoLogcat is free and open source → github.com/hiyoyok/HiyokoLogcat
X → @hiyoyok

Top comments (0)