cmd/cli: better error message when log file is empty

While at it, also record the size of logs being sent in debug/error
message.
This commit is contained in:
Cuong Manh Le
2024-12-27 16:28:56 +07:00
committed by Cuong Manh Le
parent ff43c74d8d
commit 5a566c028a
5 changed files with 45 additions and 12 deletions
+11
View File
@@ -24,6 +24,11 @@ type logViewResponse struct {
Data string `json:"data"`
}
type logSentResponse struct {
Size int `json:"size"`
Error string `json:"error"`
}
// logWriter is an internal buffer to keep track of runtime log when no logging is enabled.
type logWriter struct {
mu sync.Mutex
@@ -118,6 +123,9 @@ func (p *prog) logContent() ([]byte, error) {
lw.mu.Lock()
data = lw.buf.Bytes()
lw.mu.Unlock()
if len(data) == 0 {
return nil, errors.New("internal log is empty")
}
} else {
if p.cfg.Service.LogPath == "" {
return nil, nil
@@ -127,6 +135,9 @@ func (p *prog) logContent() ([]byte, error) {
return nil, err
}
data = buf
if len(data) == 0 {
return nil, errors.New("log file is empty")
}
}
return data, nil
}