Skip to content

Commit

Permalink
cmd/vinegar: add colored logging
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Feb 29, 2024
1 parent 837cda9 commit 0b0d7ac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmd/vinegar/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package main
import (
"errors"
"fmt"
"io"
"log"
"log/slog"
"os"
"os/signal"
Expand All @@ -15,7 +13,9 @@ import (

"github.com/fsnotify/fsnotify"
"github.com/godbus/dbus/v5"
"github.com/lmittmann/tint"
"github.com/nxadm/tail"
slogmulti "github.com/samber/slog-multi"
bsrpc "github.com/vinegarhq/vinegar/bloxstraprpc"
"github.com/vinegarhq/vinegar/config"
"github.com/vinegarhq/vinegar/internal/dirs"
Expand Down Expand Up @@ -115,10 +115,10 @@ func (b *Binary) Main(args ...string) int {
}
defer logFile.Close()

out := io.MultiWriter(os.Stderr, logFile)
b.Prefix.Stderr = out
b.Prefix.Stdout = out
log.SetOutput(out)
slog.SetDefault(slog.New(slogmulti.Fanout(
tint.NewHandler(os.Stderr, nil),
tint.NewHandler(logFile, &tint.Options{NoColor: true}),
)))

b.Splash = splash.New(&b.GlobalConfig.Splash)
b.Config.Env.Setenv()
Expand Down
3 changes: 3 additions & 0 deletions cmd/vinegar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"

"github.com/lmittmann/tint"
"github.com/vinegarhq/vinegar/config"
"github.com/vinegarhq/vinegar/config/editor"
"github.com/vinegarhq/vinegar/internal/dirs"
Expand Down Expand Up @@ -41,6 +42,8 @@ func main() {
cmd := flag.Arg(0)
args := flag.Args()

slog.SetDefault(slog.New(tint.NewHandler(os.Stderr, nil)))

switch cmd {
case "delete", "edit", "uninstall", "version":
switch cmd {
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ require (
github.com/folbricht/pefile v0.1.0
github.com/fsnotify/fsnotify v1.7.0
github.com/godbus/dbus/v5 v5.1.0
github.com/lmittmann/tint v1.0.4
github.com/nxadm/tail v1.4.11
github.com/samber/slog-multi v1.0.2
golang.org/x/sys v0.17.0
golang.org/x/term v0.17.0
)
Expand All @@ -25,6 +27,7 @@ require (
gioui.org/shader v1.0.8 // indirect
github.com/go-text/typesetting v0.0.0-20231206174126-ce41cc83e028 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/samber/lo v1.38.1 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/exp/shiny v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/image v0.15.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/lmittmann/tint v1.0.4 h1:LeYihpJ9hyGvE0w+K2okPTGUdVLfng1+nDNVR4vWISc=
github.com/lmittmann/tint v1.0.4/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
Expand All @@ -36,6 +38,10 @@ github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/samber/slog-multi v1.0.2 h1:6BVH9uHGAsiGkbbtQgAOQJMpKgV8unMrHhhJaw+X1EQ=
github.com/samber/slog-multi v1.0.2/go.mod h1:uLAvHpGqbYgX4FSL0p1ZwoLuveIAJvBECtE07XmYvFo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down

0 comments on commit 0b0d7ac

Please sign in to comment.