Prompt Engineering for Log Diagnosis — What Actually Works With Gemini

Published: (May 1, 2026 at 11:20 PM EDT)
3 min read
Source: Dev.to

Source: Dev.to

Cover image for 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. Below is the iteration I went through for HiyokoLogcat’s diagnosis feature.

Version 1: Too vague

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

[logs]

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]

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
);

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")
}

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.",
};

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

What I learned

Three things matter most:

  • Role assignment – “You are a specialist” genuinely improves output.
  • Target marking – tell the model exactly which line to focus on.
  • Length constraint – “3‑5 sentences” prevents essays.

Everything else is noise.

HiyokoLogcat is free and open source →

Follow me on X → @hiyoyok

0 views
Back to Blog

Related posts

Read more »