RootStream includes an AI Coding Logging Mode designed specifically for AI-assisted development workflows. This mode provides structured, machine-readable logging output that helps AI coding assistants (like GitHub Copilot, Claude, ChatGPT) understand the internal operation of RootStream in real-time.
- Zero overhead when disabled - Macros compile out completely
- Structured output format -
[AICODING][timestamp][module] message - Multiple activation methods - CLI flag, environment variable, or API
- Optional file output - Can log to file or stderr
- Startup banner - Clear warning when verbose mode is active
- Session summary - Reports total log entries on shutdown
Set the AI_COPILOT_MODE environment variable to enable logging:
AI_COPILOT_MODE=1 ./rootstream --serviceThis is the recommended method for AI-assisted debugging as it persists across all invocations.
Use the --ai-coding-logs flag when starting RootStream:
# Log to stderr (default)
./rootstream --ai-coding-logs
# Log to file
./rootstream --ai-coding-logs=/var/log/rootstream-ai.logFor integration testing or custom workflows:
#include "ai_logging.h"
rootstream_ctx_t ctx;
ai_logging_init(&ctx);
ai_logging_set_enabled(&ctx, true);
ai_logging_set_output(&ctx, "/tmp/debug.log");
// ... your code ...
ai_logging_shutdown(&ctx);All AI coding logs follow this structured format:
[AICODING][timestamp][module] message
[AICODING][2026-02-13 03:48:15][core] init: AI logging module initialized (mode=stderr)
[AICODING][2026-02-13 03:48:15][core] startup: RootStream version=1.0.0
[AICODING][2026-02-13 03:48:15][core] startup: port=9876 bitrate=10000 service_mode=1
[AICODING][2026-02-13 03:48:15][capture] init: attempting DRM/KMS backend
[AICODING][2026-02-13 03:48:15][capture] init: DRM device=/dev/dri/card0 fd=5
[AICODING][2026-02-13 03:48:16][encode] init: available backends=[NVENC:0, VAAPI:1, x264:1]
[AICODING][2026-02-13 03:48:16][encode] init: selected backend=VAAPI
[AICODING][2026-02-13 03:48:16][network] init: bound to port 9876
[AICODING][2026-02-13 03:48:16][discovery] init: mDNS service started name=gaming-pc
Logging is organized by subsystem:
- core - Main initialization, configuration, shutdown
- capture - Video capture backends (DRM, X11, dummy)
- encode - Video encoder backends (VAAPI, NVENC, x264)
- network - Network stack, socket operations
- input - Input injection (uinput, xdotool)
- audio - Audio capture/playback
- crypto - Encryption, key exchange
- discovery - mDNS peer discovery
- gui - Tray/GUI backends
When troubleshooting why a specific backend was chosen:
AI_COPILOT_MODE=1 ./rootstream --service 2>&1 | grep -E '\[encode\]|\[capture\]'You'll see:
[AICODING][...][capture] init: attempting DRM/KMS backend
[AICODING][...][capture] fallback: DRM failed, trying X11
[AICODING][...][encode] init: available backends=[NVENC:0, VAAPI:1, x264:1]
[AICODING][...][encode] init: selected backend=x264 (reason=VAAPI init failed)
Understanding the startup sequence:
AI_COPILOT_MODE=1 ./rootstream --service 2>&1 | head -30Shows complete initialization order with timing.
Debugging peer connection failures:
AI_COPILOT_MODE=1 ./rootstream connect kXx7Y...@peer 2>&1 | grep '\[network\]'When working with an AI coding assistant:
- Enable logging:
export AI_COPILOT_MODE=1 - Run RootStream:
./rootstream --service - Share logs with AI: Copy relevant log sections to your AI chat
- AI can now understand: Code paths taken, backends selected, error conditions
When AI logging is enabled, you'll see:
╔═══════════════════════════════════════════════════════════════════╗
║ AI CODING LOGGING MODE ENABLED ║
╠═══════════════════════════════════════════════════════════════════╣
║ Verbose structured logging active for AI-assisted development ║
║ Output format: [AICODING][module][tag] message ║
║ ║
║ To disable: AI_COPILOT_MODE=0 or remove --ai-coding-logs flag ║
╚═══════════════════════════════════════════════════════════════════╝
This ensures you're aware that verbose logging is active.
When the program exits, you'll see:
╔═══════════════════════════════════════════════════════════════════╗
║ AI CODING LOGGING SESSION SUMMARY ║
╠═══════════════════════════════════════════════════════════════════╣
║ Total log entries: 147 ║
║ Output destination: stderr ║
╚═══════════════════════════════════════════════════════════════════╝
Zero overhead - The ai_log() macro is compiled out entirely:
#define AI_LOG_CAPTURE(fmt, ...) ai_log("capture", fmt, ##__VA_ARGS__)When disabled, this becomes a no-op at compile time.
Minimal overhead - Each log call is a single fprintf():
- CPU: < 0.01% overhead per log call
- Latency: < 1μs per message
- Memory: ~1KB static state
Even with hundreds of log calls during startup, the performance impact is negligible.
Workflow:
AI_COPILOT_MODE=1 ./rootstream host 2>&1 | grep -A5 '\[encode\].*init'Expected output:
[AICODING][...][encode] init: available backends=[NVENC:0, VAAPI:1, x264:1]
[AICODING][...][encode] init: attempting VAAPI
[AICODING][...][encode] init: VAAPI device=/dev/dri/renderD128
[AICODING][...][encode] fallback: VAAPI init failed (error=-1)
[AICODING][...][encode] init: attempting x264
[AICODING][...][encode] init: selected backend=x264
Now you know VAAPI initialization failed, and can investigate why.
Workflow:
AI_COPILOT_MODE=1 ./rootstream connect kXx7Y...@peer 2>&1 | grep '\[network\]'Expected output:
[AICODING][...][network] init: attempting connection to 192.168.1.100:9876
[AICODING][...][network] error: connect() failed (errno=111 Connection refused)
[AICODING][...][network] retry: attempt 2/5 in 2 seconds
Workflow:
AI_COPILOT_MODE=1 ./rootstream host 2>&1 | grep '\[input\]'Expected output:
[AICODING][...][input] init: attempting uinput backend
[AICODING][...][input] error: failed to open /dev/uinput (errno=13 Permission denied)
[AICODING][...][input] fallback: using xdotool backend
[AICODING][...][input] init: selected backend=xdotool
Now you know to add your user to the input group or use sudo.
-
Start RootStream with logging:
AI_COPILOT_MODE=1 ./rootstream --service 2> /tmp/rootstream.log -
When debugging an issue, open
/tmp/rootstream.login your editor -
Copilot can now see the execution flow and suggest fixes based on:
- Which backends were selected
- Where initialization failed
- Error codes and errno values
-
Enable logging and reproduce your issue:
AI_COPILOT_MODE=1 ./rootstream host 2>&1 | tee /tmp/debug.log
-
Copy relevant sections to your AI chat:
I'm debugging RootStream encoder selection. Here are the logs: [paste logs here] Why did it choose x264 instead of VAAPI? -
The AI can now analyze the actual execution path and provide targeted advice
AI_COPILOT_MODE=0 ./rootstream --serviceunset AI_COPILOT_MODE
./rootstream --serviceFor production builds, you can compile out all AI logging support:
make CFLAGS="-DDISABLE_AI_LOGGING" allThis removes all AI logging code at compile time.
✅ Use AI logging when working with AI coding assistants ✅ Enable logging to debug backend selection issues ✅ Redirect to file when logging large sessions ✅ Use grep/awk to filter specific modules ✅ Share log snippets with AI for targeted help
❌ Enable AI logging in production (performance overhead) ❌ Commit AI log files to version control ❌ Use AI logging to replace proper error handling ❌ Expect AI logging to capture all internal state ❌ Leave AI logging enabled for benchmarking
- ARCHITECTURE.md - System architecture overview
- TROUBLESHOOTING.md - Common issues and solutions
- CONTRIBUTING.md - Development workflow
- docs/api.md - C API reference