Skip to content

Commit 56a54ab

Browse files
committed
feat(logs): include hook information in log entry formatting
1 parent 303c8e4 commit 56a54ab

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎internal/cli/logs/formatter.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (f *Formatter) formatMachine(name string) string {
8282
return style.Render(name)
8383
}
8484

85-
func (f *Formatter) formatService(serviceName, containerID string) string {
85+
func (f *Formatter) formatService(serviceName, containerID, hook string) string {
8686
styleService := lipgloss.NewStyle().Bold(true)
8787
padding := f.maxServiceWidth - len(serviceName)
8888

@@ -102,7 +102,11 @@ func (f *Formatter) formatService(serviceName, containerID string) string {
102102
return styleService.PaddingRight(padding).Render(serviceName)
103103
}
104104

105-
return styleService.Render(serviceName) + tui.Faint.PaddingRight(padding).Render("/"+containerID[:5])
105+
out := styleService.Render(serviceName) + tui.Faint.PaddingRight(padding).Render("/"+containerID[:5])
106+
if hook != "" {
107+
out += tui.Faint.Render(" [" + hook + "]")
108+
}
109+
return out
106110
}
107111

108112
// PrintEntry prints a single log entry with proper formatting.
@@ -126,7 +130,7 @@ func (f *Formatter) PrintEntry(entry api.ServiceLogEntry) {
126130
output.WriteString(" ")
127131

128132
// Service/container_id or service name for a systemd service.
129-
output.WriteString(f.formatService(entry.Metadata.ServiceName, entry.Metadata.ContainerID))
133+
output.WriteString(f.formatService(entry.Metadata.ServiceName, entry.Metadata.ContainerID, entry.Metadata.Hook))
130134
output.WriteString(" ")
131135

132136
// Message

‎pkg/api/logs.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ type ServiceLogEntryMetadata struct {
7676
ContainerID string
7777
MachineID string
7878
MachineName string
79+
// Hook is the hook type of the source container (e.g., "pre-deploy"). Empty for non-hook containers.
80+
Hook string
7981
}
8082

8183
// LogEntry represents a single log entry from a container or a service.

‎pkg/client/logs.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (cli *Client) ServiceLogs(
8181
ContainerID: ctr.Container.ID,
8282
MachineID: ctr.MachineID,
8383
MachineName: machineName,
84+
Hook: ctr.Container.Config.Labels[api.LabelHook],
8485
}
8586
enrichedStream := logsStreamWithServiceMetadata(stream, metadata)
8687
ctrStreams = append(ctrStreams, enrichedStream)

0 commit comments

Comments
 (0)