feat(config): уровень логирования log.level (info|debug), по умолчанию info
Отладочные логи API-вызовов к opencode serve теперь включаются только при
log.level=debug (гейт через Client.Debug <- Runner.Debug <- cfg.Log.Debug()).
По умолчанию 'info' — отладочных логов нет.
- config: добавлен LogCfg{Level}, дефолт 'info', валидация (info|debug)
- opencode: Client.Debug и Runner.Debug — гейттят логи do()
- app: Runner.Debug из cfg.Log.Debug()
- config.yaml.example: задокументирован log.level
- тесты: дефолт=info, level=debug, невалидный уровень
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
type Client struct {
|
||||
BaseURL string // http://host:port (без завершающего слеша)
|
||||
Password string // basic auth (username "opencode")
|
||||
Debug bool // включать отладочные логи API-вызовов (log.level=debug)
|
||||
http *http.Client
|
||||
}
|
||||
|
||||
@@ -62,10 +63,11 @@ func (c *Client) do(ctx context.Context, method, path, op string, body []byte) (
|
||||
if body != nil {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
}
|
||||
log.Printf("opencode api %s -> %s %s%s",
|
||||
op, method, c.BaseURL, path)
|
||||
if len(body) > 0 {
|
||||
log.Printf("opencode api %s request body: %s", op, truncateStr(string(body), 5000))
|
||||
if c.Debug {
|
||||
log.Printf("opencode api %s -> %s %s%s", op, method, c.BaseURL, path)
|
||||
if len(body) > 0 {
|
||||
log.Printf("opencode api %s request body: %s", op, truncateStr(string(body), 5000))
|
||||
}
|
||||
}
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
@@ -77,10 +79,14 @@ func (c *Client) do(ctx context.Context, method, path, op string, body []byte) (
|
||||
return nil, &ClientErr{Op: "connect", Err: err}
|
||||
}
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
log.Printf("opencode api %s response: status %d: %s", op, resp.StatusCode, truncateStr(string(b), 1000))
|
||||
if c.Debug {
|
||||
log.Printf("opencode api %s response: status %d: %s", op, resp.StatusCode, truncateStr(string(b), 1000))
|
||||
}
|
||||
return nil, &ClientErr{Op: op, Err: fmt.Errorf("status %d: %s", resp.StatusCode, truncateStr(string(b), 300))}
|
||||
}
|
||||
log.Printf("opencode api %s response (%d bytes): %s", op, len(b), truncateStr(string(b), 5000))
|
||||
if c.Debug {
|
||||
log.Printf("opencode api %s response (%d bytes): %s", op, len(b), truncateStr(string(b), 5000))
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ type Runner struct {
|
||||
IdleTimeout time.Duration
|
||||
HardTimeout time.Duration
|
||||
PollInterval time.Duration
|
||||
Debug bool // отладочные логи API-вызовов (из log.level=debug)
|
||||
|
||||
// Заменяемый для тестов:
|
||||
Stdout io.Writer // диагностика (лог), по умолчанию os.Stderr
|
||||
@@ -71,7 +72,7 @@ func (r *Runner) Run(ctx context.Context, prompt, cwd, agent, sessionID string)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c := &Client{BaseURL: srv.Addr(), Password: srv.Password}
|
||||
c := &Client{BaseURL: srv.Addr(), Password: srv.Password, Debug: r.Debug}
|
||||
|
||||
// Сессия: заданная (resume) или новая.
|
||||
sid := sessionID
|
||||
|
||||
Reference in New Issue
Block a user