AT Protocol Terminal Interface Explorer

switch to slog

+22 -60
+2 -23
at/client.go
··· 4 4 "context" 5 5 "encoding/json" 6 6 "fmt" 7 + "log/slog" 7 8 8 9 comatproto "github.com/bluesky-social/indigo/api/atproto" 9 - log "github.com/sirupsen/logrus" 10 10 11 11 "github.com/bluesky-social/indigo/api/agnostic" 12 12 "github.com/bluesky-social/indigo/atproto/atclient" ··· 97 97 if err != nil { 98 98 return nil, fmt.Errorf("failed to lookup identifier: %w", err) 99 99 } 100 - log.WithFields(log.Fields{ 101 - "handle": idd.Handle, 102 - "DID": idd.DID, 103 - "PDS": idd.PDSEndpoint(), 104 - }).Info("identifier resolved") 100 + slog.Info("identifier resolved", "handle", idd.Handle, "DID", idd.DID, "PDS", idd.PDSEndpoint()) 105 101 return idd, nil 106 102 } 107 103 ··· 118 114 if err != nil { 119 115 return nil, fmt.Errorf("failed to get client with identifier: %w", err) 120 116 } 121 - 122 - log.WithFields(log.Fields{ 123 - "client_host": client.Host, 124 - "repo": repo, 125 - "pds": id.PDSEndpoint(), 126 - }).Info("describe repo") 127 117 128 118 // TODO: download repo as car 129 119 // https://github.com/bluesky-social/cookbook/blob/main/go-repo-export/main.go#L46 ··· 138 128 } 139 129 140 130 func (c *Client) ListRecords(ctx context.Context, collection, repo string) (*RecordsWithIdentity, error) { 141 - log.WithFields(log.Fields{ 142 - "collection": collection, 143 - "repo": repo, 144 - }).Info("list records") 145 - 146 131 client, id, err := c.withIdentifier(ctx, repo) 147 132 if err != nil { 148 133 return nil, fmt.Errorf("failed to get client with identifier: %w", err) ··· 165 150 } 166 151 167 152 func (c *Client) GetRecord(ctx context.Context, collection, repo, rkey string) (*RecordWithIdentity, error) { 168 - log.WithFields(log.Fields{ 169 - "collection": collection, 170 - "repo": repo, 171 - "rkey": rkey, 172 - }).Info("get record") 173 - 174 153 client, id, err := c.withIdentifier(ctx, repo) 175 154 if err != nil { 176 155 return nil, fmt.Errorf("failed to get client with identifier: %w", err)
+6 -9
main.go
··· 1 1 package main 2 2 3 3 import ( 4 + "log/slog" 4 5 "os" 5 6 6 - log "github.com/sirupsen/logrus" 7 7 "github.com/treethought/attie/ui" 8 8 9 9 "github.com/bluesky-social/indigo/atproto/identity" ··· 15 15 } 16 16 17 17 func main() { 18 - log.SetFormatter(&log.TextFormatter{ 19 - FullTimestamp: false, 20 - DisableTimestamp: true, 21 - }) 22 18 f, err := os.Create("/tmp/attie.log") 23 19 if err != nil { 24 - log.Fatal(err) 20 + slog.Error("failed to create log file", "error", err) 21 + os.Exit(1) 25 22 } 26 23 defer f.Close() 27 - log.SetOutput(f) 28 - log.Warn("starting attie") 24 + slog.SetDefault(slog.New(slog.NewTextHandler(f, nil))) 25 + slog.Info("starting attie") 29 26 30 27 query := "" 31 28 if len(os.Args) > 1 { ··· 36 33 37 34 p := tea.NewProgram(app, tea.WithAltScreen()) 38 35 if _, err := p.Run(); err != nil { 39 - log.Fatal(err) 36 + slog.Error("program error", "error", err) 40 37 } 41 38 }
+12 -23
ui/app.go
··· 2 2 3 3 import ( 4 4 "context" 5 - 6 - log "github.com/sirupsen/logrus" 5 + "log/slog" 7 6 8 7 comatproto "github.com/bluesky-social/indigo/api/atproto" 9 8 "github.com/bluesky-social/indigo/atproto/identity" ··· 57 56 func (a *App) Init() tea.Cmd { 58 57 a.loading = true 59 58 if id, err := syntax.ParseAtIdentifier(a.query); err == nil { 60 - log.Printf("Starting with query: %s", id.String()) 59 + slog.Info("Starting with query", "id", id.String()) 61 60 return a.fetchRepo(id.String()) 62 61 } 63 62 if uri, err := syntax.ParseATURI(a.query); err == nil { ··· 72 71 return a.fetchRecords(uri.Collection().String(), id) 73 72 } 74 73 75 - log.Printf("Starting with query: %s", uri.String()) 74 + slog.Info("Starting with query", "uri", uri.String()) 76 75 return a.fetchRecord(uri.Collection().String(), uri.Authority().String(), uri.RecordKey().String()) 77 76 } 78 77 ··· 142 141 // parse for handle/DID or a record URI 143 142 id, err := syntax.ParseAtIdentifier(msg.identifier.String()) 144 143 if err != nil { 145 - log.Fatalf("Failed to parse identifier, should have caught during submission: %s", err.Error()) 144 + slog.Error("Failed to parse identifier, should have caught during submission", "error", err) 146 145 return a, nil 147 146 } 148 147 if id.IsDID() || id.IsHandle() { 149 - log.Printf("Repo identifier submitted: %s", id.String()) 150 148 return a, a.fetchRepo(id.String()) 151 149 } 152 150 ··· 163 161 return a, cmd 164 162 165 163 case selectCollectionMsg: 166 - log.Printf("Collection selected: %s", msg.collection) 164 + slog.Info("Collection selected", "collection", msg.collection) 167 165 a.actx.collection = msg.collection 168 166 return a, a.fetchRecords(msg.collection, a.repoView.repo.Handle) 169 167 ··· 208 206 209 207 func (a *App) fetchRepo(repoId string) tea.Cmd { 210 208 return func() tea.Msg { 209 + slog.Info("Fetching repo", "repoId", repoId) 211 210 resp, err := a.client.GetRepo(context.Background(), repoId) 212 211 if err != nil { 213 - log.Printf("Failed to get repo: %s", err.Error()) 212 + slog.Error("Failed to get repo", "error", err) 214 213 return repoErrorMsg{err: err} 215 214 } 216 - log.WithFields(log.Fields{ 217 - "repo": resp.Repo.Handle, 218 - }).Info("Repo loaded") 215 + slog.Info("Repo loaded", "repo", resp.Repo.Handle) 219 216 return repoLoadedMsg{repo: resp} 220 217 } 221 218 } ··· 224 221 return func() tea.Msg { 225 222 recs, err := a.client.ListRecords(context.Background(), collection, repo) 226 223 if err != nil { 227 - log.Printf("Failed to list records: %s", err.Error()) 224 + slog.Error("Failed to list records", "error", err) 228 225 return repoErrorMsg{err: err} 229 226 } 230 - log.WithFields(log.Fields{ 231 - "repo": repo, 232 - "collection": collection, 233 - "numRecords": len(recs.Records), 234 - }).Info("Records loaded") 227 + slog.Info("Records loaded", "repo", repo, "collection", collection, "numRecords", len(recs.Records)) 235 228 return recordsLoadedMsg{records: recs} 236 229 } 237 230 } ··· 240 233 return func() tea.Msg { 241 234 rec, err := a.client.GetRecord(context.Background(), collection, repo, rkey) 242 235 if err != nil { 243 - log.Printf("Failed to get record: %s", err.Error()) 236 + slog.Error("Failed to get record", "error", err) 244 237 return repoErrorMsg{err: err} 245 238 } 246 - log.WithFields(log.Fields{ 247 - "repo": repo, 248 - "collection": collection, 249 - "rkey": rkey, 250 - }).Info("Record loaded") 239 + slog.Info("Record loaded", "repo", repo, "collection", collection, "rkey", rkey) 251 240 return recordSelectedMsg{ 252 241 record: rec, 253 242 }
-2
ui/collection.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 - log "github.com/sirupsen/logrus" 6 5 "strings" 7 6 8 7 "github.com/bluesky-social/indigo/atproto/syntax" ··· 72 71 73 72 func (rl *RecordsList) SetRecords(records []*at.Record) tea.Cmd { 74 73 if records == nil { 75 - log.Error("SetRecords called with nil") 76 74 return nil 77 75 } 78 76 rl.preview.SetRecord(nil)
+2 -3
ui/search.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 - 6 - log "github.com/sirupsen/logrus" 5 + "log/slog" 7 6 8 7 "github.com/bluesky-social/indigo/atproto/syntax" 9 8 "github.com/charmbracelet/bubbles/spinner" ··· 68 67 c.err = "" 69 68 c.loading = true 70 69 return c, func() tea.Msg { 71 - log.Printf("Looking up identifier: %s", id.String()) 70 + slog.Info("Looking up identifier", "id", id.String()) 72 71 return searchSubmitMsg{identifier: id} 73 72 } 74 73 }