Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
dev: add .sst/log/function.log
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Sep 12, 2024
1 parent a63f9e9 commit ba73c53
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
23 changes: 21 additions & 2 deletions cmd/sst/mosaic/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ type UI struct {
hasBlank bool
hasHeader bool
options *Options
log *os.File
}

type Options struct {
Silent bool
Log *os.File
Dev bool
}

Expand All @@ -71,6 +73,12 @@ func WithDev(u *Options) {
u.Dev = true
}

func WithLog(file *os.File) Option {
return func(opts *Options) {
opts.Log = file
}
}

func New(ctx context.Context, options ...Option) *UI {
opts := &Options{}
for _, option := range options {
Expand All @@ -84,6 +92,9 @@ func New(ctx context.Context, options ...Option) *UI {
hasBlank: false,
options: opts,
}
if opts.Log != nil {
result.log = opts.Log
}
if isTTY && !opts.Silent {
result.footer = NewFooter()
go result.footer.Start(ctx)
Expand All @@ -102,11 +113,16 @@ func (u *UI) printf(tmpl string, args ...interface{}) {

func (u *UI) println(args ...interface{}) {
u.buffer = append(u.buffer, args...)
line := fmt.Sprint(u.buffer...)
if u.footer == nil {
fmt.Println(fmt.Sprint(u.buffer...))
fmt.Println(line)
}
if u.footer != nil {
u.footer.Send(lineMsg(fmt.Sprint(u.buffer...)))
u.footer.Send(lineMsg(line))
}
if u.log != nil {
stripped := ansi.Strip(line)
u.log.WriteString(stripped + "\n")
}
u.buffer = []interface{}{}
u.hasBlank = false
Expand Down Expand Up @@ -523,6 +539,9 @@ func (u *UI) Destroy() {
if u.footer != nil {
u.footer.Destroy()
}
if u.log != nil {
u.log.Close()
}
}

func (u *UI) header(version, app, stage string) {
Expand Down
19 changes: 17 additions & 2 deletions cmd/sst/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"log/slog"
"os"

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/sst/ion/cmd/sst/cli"
Expand All @@ -23,7 +24,14 @@ func CmdUI(c *cli.Cli) error {
}
types := []interface{}{}
filter := c.String("filter")
var u *ui.UI
opts := []ui.Option{
ui.WithDev,
}
if filter == "function" || filter == "" {
if err != nil {
return err
}
if filter != "" {
fmt.Println(ui.TEXT_HIGHLIGHT_BOLD.Render("Function Logs"))
fmt.Println()
Expand All @@ -42,6 +50,7 @@ func CmdUI(c *cli.Cli) error {
)
}
if filter == "sst" || filter == "" {
u = ui.New(c.Context, ui.WithDev)
types = append(types,
common.StdoutEvent{},
deployer.DeployFailedEvent{},
Expand All @@ -60,8 +69,14 @@ func CmdUI(c *cli.Cli) error {
if err != nil {
return err
}

u := ui.New(c.Context, ui.WithDev)
if filter == "function" {
log, err := os.Create(".sst/log/function.log")
if err != nil {
return err
}
opts = append(opts, ui.WithLog(log))
}
u = ui.New(c.Context, opts...)
slog.Info("initialized ui")
if filter == "sst" || filter == "" {
err = dev.Deploy(c.Context, url)
Expand Down

0 comments on commit ba73c53

Please sign in to comment.