惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
C
Check Point Blog
J
Java Code Geeks
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
量子位
Google DeepMind News
Google DeepMind News
I
InfoQ
The GitHub Blog
The GitHub Blog
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
V
V2EX
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
小众软件
小众软件
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
IT之家
IT之家

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How Many Log Lines Should You Send to Gemini? The Context...
hiyoyo · 2026-05-01 · via DEV Community

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

When you send logcat lines to Gemini for diagnosis, how many lines should you include?

Too few: the model lacks context, gives a generic answer.
Too many: you hit token limits, slow down the response, and bury the relevant signal in noise.

Here's what I found after testing different window sizes in HiyokoLogcat.


The naive approach: send everything

First attempt: grab the last 500 lines and send them all.

Problems:

  • Gemini 1.5 Flash has a large context window, but 500 verbose logcat lines is a lot of tokens
  • Response latency increases noticeably
  • The model sometimes focuses on unrelated noise rather than the actual error

What actually works: 50 lines before, 50 after

After testing, ±50 lines around the target error hits the sweet spot:

pub fn get_diagnosis_context(
    buffer: &LogRingBuffer,
    error_idx: usize,
) -> String {
    let window = 50;
    let lines = buffer.context_around(error_idx, window);

    lines
        .iter()
        .map(|l| format!("[{}] {}/{}: {}",
            l.timestamp, l.level, l.tag, l.message))
        .collect::>()
        .join("\n")
}

Enter fullscreen mode Exit fullscreen mode

50 lines before captures the sequence of events leading to the crash.
50 lines after captures any follow-on errors and recovery attempts.

100 lines total. Typically 3,000–6,000 tokens. Fast response, relevant diagnosis.


When to go wider

Some crashes only make sense with more context — memory leaks that build up over minutes, threading issues with long setup chains.

For these, I added a "deep diagnosis" mode that sends ±200 lines:

pub enum DiagnosisMode {
    Quick,  // ±50 lines
    Deep,   // ±200 lines
}

Enter fullscreen mode Exit fullscreen mode

Quick is the default. Deep is one extra click. Most users never need it.


The format matters too

Raw logcat output has a lot of repetitive structure. Reformatting before sending reduces token count without losing information:

// Raw (verbose)
04-20 10:23:45.123  1234  5678 E AndroidRuntime: FATAL EXCEPTION: main

// Reformatted (compact)
[10:23:45] E/AndroidRuntime: FATAL EXCEPTION: main

Enter fullscreen mode Exit fullscreen mode

Same information, fewer tokens. Over 100 lines this adds up.


The result

±50 lines, reformatted, PII-masked → Gemini gives a specific, actionable diagnosis in 2–3 seconds on the free tier.

That's the configuration I shipped with.


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