API 레퍼런스는 소스 코드의 Go 문서 주석에서 추출되며 영어로 작성되어 있습니다.
package diaglog
import "github.com/nsgo-dev/game/pkg/editor/diaglog"개요
Package diaglog is experimental: its API and documented formats may change in a minor release. See the API stability policy. writes the editor's bounded, redacted diagnostics logs and packages them into a diagnostics zip.
A Writer keeps one stream (such as "editor", "agent", "mcp", "build" or "game") as JSON lines in <dir>/<stream>.log, rotated by size into <stream>.log.1, <stream>.log.2 and so on. Every line passes through a Redactor before it is written, and Export runs the files through it again before it zips them with a versioned manifest.yaml.
색인
상수
const DefaultMaxBytes int64 = 4 << 20DefaultMaxBytes is the size at which a stream's current file is rotated when NewWriter is given no size.
const DefaultMaxFiles = 3DefaultMaxFiles is how many files of one stream are kept, the current file included, when NewWriter is given no count.
const ManifestName = "manifest.yaml"ManifestName is the manifest's file name inside the diagnostics zip.
const ManifestVersion = 1ManifestVersion is the manifest.yaml schema version Export writes and ParseManifest reads.
const MaxLineBytes = 64 << 10MaxLineBytes is the longest message a Writer keeps; a longer one is cut there and marked with TruncatedMark.
함수
func EncodeManifest(m Manifest) ([]byte, error)EncodeManifest returns m as manifest.yaml, refusing a version other than ManifestVersion.
func Export(logDir string, w io.Writer, m Manifest, redactor Redactor) errorExport writes a diagnostics zip to w: manifest.yaml, with m's Entries replaced by the files it holds, then each stream file in logDir, run through redactor again. A missing logDir exports no files.
타입
type Entry struct {
Name string `yaml:"name"`
Size int64 `yaml:"size"`
}Entry is one log file in a diagnostics zip: its name in the zip and its size in bytes after redaction.
type Manifest struct {
// Version must equal ManifestVersion.
Version int `yaml:"version"`
// EditorVersion is the editor's module version, empty when the build has none.
EditorVersion string `yaml:"editorVersion,omitempty"`
// GoVersion is the Go toolchain the editor was built with.
GoVersion string `yaml:"goVersion,omitempty"`
// NSGoVersion is the NSGo module version the editor was built with.
NSGoVersion string `yaml:"nsgoVersion,omitempty"`
// OS and Arch are the editor's GOOS and GOARCH.
OS string `yaml:"os"`
Arch string `yaml:"arch"`
// ProjectVersion is the version field of the open project's game.yaml, 0 when no project is open.
ProjectVersion int `yaml:"projectVersion,omitempty"`
// Entries are the log files in the zip, sorted by name; Export fills them in.
Entries []Entry `yaml:"entries"`
}Manifest describes a diagnostics zip; Export writes it as manifest.yaml.
func ParseManifest(data []byte) (Manifest, error)ParseManifest reads a manifest.yaml, refusing unknown fields, a second document and a version other than ManifestVersion with a *loaderr.Error.
type Redactor struct {
// Home, Project and Data are the user's home directory, the open project's root and the editor's data directory, replaced by <home>, <project> and <data>. The longest is replaced first, so a project inside the home directory becomes <project>, not <home>/....
Home, Project, Data string
// Secrets are exact values the editor holds, such as the built-in agent's API key, each replaced by <redacted>.
Secrets []string
}Redactor removes secrets and machine-local identifiers from diagnostics text.
func (r Redactor) Redact(s string) stringRedact returns s with the Redactor's paths and secrets replaced, then PEM private keys, bearer tokens, Authorization and Cookie header values, environment values whose names contain KEY, SECRET, TOKEN or PASSWORD, common API-key prefixes and email addresses masked, and every http, https, ws and wss URL reduced to its scheme and host. Redacting its own output changes nothing.
func (r Redactor) RedactSecrets(s string) stringRedactSecrets returns s with only the Redactor's exact secrets replaced by <redacted>, leaving the patterns Redact applies untouched. It backs UI paths that must keep URLs and header shapes intact, such as store uploads whose printed URLs are parsed again, while sharing the same secret list.
type Writer struct {
// contains filtered or unexported fields
}Writer writes one stream's redacted lines and rotates its files by size. It is safe for concurrent use, and each line is written whole.
func NewWriter(dir, stream string, redactor Redactor, maxBytes int64, maxFiles int) (*Writer, error)NewWriter returns a Writer for stream in dir, creating dir. A maxBytes or maxFiles of 0 or less uses DefaultMaxBytes or DefaultMaxFiles. The current file is opened on the first write, appending to what an earlier run left.
func (w *Writer) Close() errorClose writes any unfinished line Write holds and closes the current file.
func (w *Writer) Write(p []byte) (int, error)Write implements io.Writer for a child process's stdout or stderr: it splits p on newlines and writes each line with WriteLine, holding an unfinished line until the next Write or Close. A line longer than MaxLineBytes is cut there and the rest of it up to the next newline is dropped.
func (w *Writer) WriteLine(line string) errorWriteLine redacts line, cuts it at MaxLineBytes and writes it as one JSON record, rotating the stream's files first when the record would take the current file past its size.