mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
cmd/cli: better error if internal log is not available
This commit is contained in:
+6
-4
@@ -31,6 +31,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func initLogCmd() *cobra.Command {
|
func initLogCmd() *cobra.Command {
|
||||||
|
warnRuntimeLoggingNotEnabled := func() {
|
||||||
|
mainLog.Load().Warn().Msg("runtime debug logging is not enabled")
|
||||||
|
mainLog.Load().Warn().Msg(`ctrld may be running without "--cd" flag or logging is already enabled`)
|
||||||
|
}
|
||||||
logSendCmd := &cobra.Command{
|
logSendCmd := &cobra.Command{
|
||||||
Use: "send",
|
Use: "send",
|
||||||
Short: "Send runtime debug logs to ControlD",
|
Short: "Send runtime debug logs to ControlD",
|
||||||
@@ -54,8 +58,7 @@ func initLogCmd() *cobra.Command {
|
|||||||
mainLog.Load().Warn().Msg("runtime logs could only be sent once per minute")
|
mainLog.Load().Warn().Msg("runtime logs could only be sent once per minute")
|
||||||
return
|
return
|
||||||
case http.StatusMovedPermanently:
|
case http.StatusMovedPermanently:
|
||||||
mainLog.Load().Warn().Msg("runtime debugs log is not enabled")
|
warnRuntimeLoggingNotEnabled()
|
||||||
mainLog.Load().Warn().Msg(`ctrld may be run without "--cd" flag or logging is already enabled`)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var logs logSentResponse
|
var logs logSentResponse
|
||||||
@@ -92,8 +95,7 @@ func initLogCmd() *cobra.Command {
|
|||||||
|
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
case http.StatusMovedPermanently:
|
case http.StatusMovedPermanently:
|
||||||
mainLog.Load().Warn().Msg("runtime debugs log is not enabled")
|
warnRuntimeLoggingNotEnabled()
|
||||||
mainLog.Load().Warn().Msg(`ctrld may be run without "--cd" flag or logging is already enabled`)
|
|
||||||
return
|
return
|
||||||
case http.StatusBadRequest:
|
case http.StatusBadRequest:
|
||||||
mainLog.Load().Warn().Msg("runtime debugs log is not available")
|
mainLog.Load().Warn().Msg("runtime debugs log is not available")
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -165,7 +166,7 @@ func (p *prog) logReader() (*logReader, error) {
|
|||||||
return lr, nil
|
return lr, nil
|
||||||
}
|
}
|
||||||
if p.cfg.Service.LogPath == "" {
|
if p.cfg.Service.LogPath == "" {
|
||||||
return nil, nil
|
return &logReader{r: io.NopCloser(strings.NewReader(""))}, nil
|
||||||
}
|
}
|
||||||
f, err := os.Open(normalizeLogFilePath(p.cfg.Service.LogPath))
|
f, err := os.Open(normalizeLogFilePath(p.cfg.Service.LogPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user