mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
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:
committed by
Cuong Manh Le
parent
ff43c74d8d
commit
5a566c028a
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user