streamlog-knowledge

Integrate StreamLog logging SDK into Golang microservices for log collection and reporting.

Updated Apr 30, 2026
One-click install
npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill streamlog-knowledge-yuezhen-huang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: streamlog-knowledge
Source: https://github.com/yuezhen-huang/my-bytedance-skillhub/tree/main/streamlog-knowledge
Command: npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill streamlog-knowledge-yuezhen-huang

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires code.byted.org/gopkg/logs/v2, code.byted.org/gopkg/logid.

What problem does it solve? Go developers on ByteDance platforms need to wire their services into the StreamLog streaming log platform, but choosing between the v1 and v2 SDKs, configuring writers, and handling context propagation is error-prone without guidance. ## Core Features & Use Cases - SDK Selection & Migration: Explains differences between StreamLog 1.0 and 2.0 SDKs and how to migrate from gopkg/logs to gopkg/logs/v2. - Logger Configuration: Shows how to initialize loggers with console, agent, and async file writers, including rotation, retention, and rate limiting. - Structured Logging Patterns: Demonstrates chain-style APIs (Str, KV, Obj, Error) with LogID context propagation for traceable microservice logs. - Use Case: A backend engineer deploying a Go service to TCE uses this Skill to configure an async file writer with hourly rotation, emit structured logs with LogID context, and avoid losing buffered logs on shutdown via log.Flush(). ## Quick Start Ask the AI to show how to initialize the StreamLog v2 SDK in a Go service with an async file writer and structured logging.

Frequently Asked Questions about streamlog-knowledge

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I integrate the StreamLog SDK into a Golang microservice?

Install code.byted.org/gopkg/logs/v2 with go get, then configure a default logger in init using logs.SetWriter with console, agent, or async file writers. Use log.V2 chain APIs like Str, KV, and Obj to emit structured logs.

What is the difference between StreamLog v1 and v2 SDK?

The v1 SDK uses format-style APIs with pure asynchronous, droppable delivery, while v2 offers chain-style APIs like Str() and Obj() with synchronous, non-dropping defaults. Versions v2.1.49 and later are compatible with most v1 APIs, so migration usually only requires changing the import path.

How do I migrate from gopkg/logs v1 to logs/v2?

Replace the import path code.byted.org/gopkg/logs with code.byted.org/gopkg/logs/v2 in your code. Most v1 APIs remain compatible, but note v2 defaults to synchronous non-dropping writes, which can affect performance under heavy load.

Why does my Go program lose the last few log lines on exit?

Async writers buffer logs in a channel processed by a background goroutine, so exiting before it finishes drops pending logs. Call log.Flush() before main returns to block until all buffered logs are written.

How do I log the correct file and line number when wrapping the logger?

When you wrap log.V2 calls in your own function, the reported caller points to your wrapper instead of business code. Use the CallDepth(n) API per log entry or logs.SetCallDepth() globally to adjust the call stack depth.

How do I rate limit high-frequency logs in a loop?

Use the .Limit(n) API on a single log entry to cap it at n emissions per second, preventing log storms in loops. You can also wrap a writer with writer.NewRateLimitWriter to throttle an entire output target.