Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

var (
logTimeStyle = lipgloss.NewStyle().Foreground(grayColor)
logAttrStyle = lipgloss.NewStyle().Foreground(grayColor)
logTimeStyle = lipgloss.NewStyle().Foreground(grayColor)
logAttrKeyStyle = lipgloss.NewStyle().Foreground(grayColor)
logAttrValStyle = lipgloss.NewStyle().Foreground(defaultColor)

logDebugStyle = lipgloss.NewStyle().Foreground(defaultColor)
logInfoStyle = lipgloss.NewStyle().Foreground(defaultColor)
Expand All @@ -40,18 +41,20 @@ func (h *slogHandler) Handle(ctx context.Context, record slog.Record) error {

var b bytes.Buffer
b.WriteString(logTimeStyle.Render(record.Time.Format("2006-01-02 15:04:05.000")))
b.WriteByte(' ')
b.WriteString(levelString(record.Level))
if record.Level >= slog.LevelWarn {
b.WriteByte(' ')
b.WriteString(levelString(record.Level))
}
b.WriteByte(' ')
b.WriteString(record.Message)
record.Attrs(func(attr slog.Attr) bool {
b.WriteByte(' ')
b.WriteString(logAttrStyle.Render(attr.String()))
writeAttr(&b, attr)
return true
})
for _, attr := range h.attrs {
b.WriteByte(' ')
b.WriteString(logAttrStyle.Render(attr.String()))
writeAttr(&b, attr)
}
b.WriteByte('\n')

Expand All @@ -74,6 +77,11 @@ func levelString(level slog.Level) string {
}
}

func writeAttr(b *bytes.Buffer, attr slog.Attr) {
b.WriteString(logAttrKeyStyle.Render(attr.Key + "="))
b.WriteString(logAttrValStyle.Render(attr.Value.String()))
}

func (h *slogHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
parent := h
if parent.parent != nil {
Expand Down
12 changes: 9 additions & 3 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,13 @@ func invoke(ctx context.Context, client *http.Client, url, requestID string, bri
return fmt.Errorf("invalid response from Dispatch API: %v", err)
}
logger.Debug("parsed request", "function", runRequest.Function, "dispatch_id", runRequest.DispatchId)
switch runRequest.Directive.(type) {
switch d := runRequest.Directive.(type) {
case *sdkv1.RunRequest_Input:
logger.Info("calling function", "function", runRequest.Function)
if Verbose {
logger.Info("calling function", "function", runRequest.Function, "input", anyString(d.Input))
} else {
logger.Info("calling function", "function", runRequest.Function)
}
case *sdkv1.RunRequest_PollResult:
logger.Info("resuming function", "function", runRequest.Function)
}
Expand Down Expand Up @@ -497,11 +501,13 @@ func invoke(ctx context.Context, client *http.Client, url, requestID string, bri
case *sdkv1.RunResponse_Exit:
if d.Exit.TailCall != nil {
logger.Info("function tail-called", "function", runRequest.Function, "tail_call", d.Exit.TailCall.Function)
} else if Verbose && d.Exit.Result != nil {
logger.Info("function call succeeded", "function", runRequest.Function, "output", anyString(d.Exit.Result.Output))
} else {
logger.Info("function call succeeded", "function", runRequest.Function)
}
case *sdkv1.RunResponse_Poll:
logger.Info("function yielded", "function", runRequest.Function, "calls", len(d.Poll.Calls))
logger.Info("function yielded", "function", runRequest.Function)
}
default:
err := runResponse.GetExit().GetResult().GetError()
Expand Down