mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
refactor(logs): encapsulate printing errors in PrintEntry
This commit is contained in:
@@ -125,10 +125,6 @@ func runLogs(ctx context.Context, uncli *cli.CLI, units []string, opts logs.Opti
|
|||||||
|
|
||||||
// Print merged logs.
|
// Print merged logs.
|
||||||
for entry := range stream {
|
for entry := range stream {
|
||||||
if entry.Err != nil {
|
|
||||||
formatter.PrintError(entry)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
formatter.PrintEntry(entry)
|
formatter.PrintEntry(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,10 +180,6 @@ func runLogs(ctx context.Context, uncli *cli.CLI, args []string, opts logs.Optio
|
|||||||
|
|
||||||
// Print merged logs.
|
// Print merged logs.
|
||||||
for entry := range stream {
|
for entry := range stream {
|
||||||
if entry.Err != nil {
|
|
||||||
formatter.PrintError(entry)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
formatter.PrintEntry(entry)
|
formatter.PrintEntry(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,10 @@ func (f *Formatter) formatService(serviceName, containerID string) string {
|
|||||||
|
|
||||||
// PrintEntry prints a single log entry with proper formatting.
|
// PrintEntry prints a single log entry with proper formatting.
|
||||||
func (f *Formatter) PrintEntry(entry api.ServiceLogEntry) {
|
func (f *Formatter) PrintEntry(entry api.ServiceLogEntry) {
|
||||||
|
if entry.Err != nil {
|
||||||
|
f.printError(entry)
|
||||||
|
return
|
||||||
|
}
|
||||||
if entry.Stream != api.LogStreamStdout && entry.Stream != api.LogStreamStderr {
|
if entry.Stream != api.LogStreamStdout && entry.Stream != api.LogStreamStderr {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -136,11 +140,11 @@ func (f *Formatter) PrintEntry(entry api.ServiceLogEntry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintError prints an error entry (e.g., stalled stream warning).
|
// printError prints an error entry (e.g., stalled stream warning).
|
||||||
func (f *Formatter) PrintError(entry api.ServiceLogEntry) {
|
func (f *Formatter) printError(entry api.ServiceLogEntry) {
|
||||||
if entry.Metadata.ServiceName == "" {
|
if entry.Metadata.ServiceName == "" {
|
||||||
msg := fmt.Sprintf("ERROR: %v", entry.Err)
|
msg := fmt.Sprintf("ERROR: %v", entry.Err)
|
||||||
style := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.BrightRed) // Bold bright red.
|
style := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.BrightRed)
|
||||||
fmt.Fprintln(os.Stderr, style.Render(msg))
|
fmt.Fprintln(os.Stderr, style.Render(msg))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -163,7 +167,7 @@ func (f *Formatter) PrintError(entry api.ServiceLogEntry) {
|
|||||||
msg += fmt.Sprintf(": %v", entry.Err)
|
msg += fmt.Sprintf(": %v", entry.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
style := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("11")) // Bold bright yellow.
|
style := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.BrightYellow)
|
||||||
fmt.Fprintln(os.Stderr, style.Render(msg))
|
fmt.Fprintln(os.Stderr, style.Render(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user