Skip to content

Commit

Permalink
Attach echo logging to pterm
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Dec 2, 2021
1 parent 4b7fbbb commit 556cffb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ require (
github.com/moby/sys/mountinfo v0.4.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/mudler/go-isterminal v0.0.0-20211031135732-5e4e06fc5a58 // indirect
github.com/mudler/topsort v0.0.0-20201103161459-db5c7901c290 // indirect
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/opencontainers/runc v1.0.2 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
github.com/mudler/cobra-extensions v0.0.0-20200612154940-31a47105fe3d/go.mod h1:puRUWSwyecW2V355tKncwPVPRAjQBduPsFjG0mrV/Nw=
github.com/mudler/go-isterminal v0.0.0-20211031135732-5e4e06fc5a58 h1:bMXak5giXxc++J/TUY7qW24D8ASxqLQRqOoduuFgdIM=
github.com/mudler/go-isterminal v0.0.0-20211031135732-5e4e06fc5a58/go.mod h1:bZC4k76DbPOxOcMq6Z9oEKAZrOhsfh9jAZ9Hu3qVAQI=
github.com/mudler/go-pluggable v0.0.0-20211022125509-94dbf124830d h1:NKvvf/q1dWDde+yg5cMiU5EuYZ2jNuKs/9hb8xod8A0=
github.com/mudler/go-pluggable v0.0.0-20211022125509-94dbf124830d/go.mod h1:WmKcT8ONmhDQIqQ+HxU+tkGWjzBEyY/KFO8LTGCu4AI=
github.com/mudler/luet v0.0.0-20211127201214-79e98af60482 h1:hoEZENScAJzlOVNNOSJ1nGmsfelDpNVXfhWmNEHm2uE=
Expand Down Expand Up @@ -1461,6 +1463,7 @@ golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210915083310-ed5796bab164/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 h1:WecRHqgE09JBkh/584XIE6PMz5KKE/vER4izNUi30AQ=
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand Down
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/mholt/archiver/v3"
"github.com/mudler/containerbay/api"
"github.com/mudler/containerbay/internal"
terminal "github.com/mudler/go-isterminal"
"github.com/mudler/luet/pkg/api/core/image"
"github.com/pkg/errors"
"github.com/pterm/pterm"
Expand Down Expand Up @@ -77,14 +78,23 @@ var flags = []cli.Flag{
},
}

type ptermWriter struct {
Printer pterm.PrefixPrinter
}

func (p *ptermWriter) Write(b []byte) (int, error) {
p.Printer.Println(string(b))
return len(b), nil
}

func echoConfig(c *cli.Context) func(e *echo.Echo) error {
return func(e *echo.Echo) error {
if c.Bool("gzip") {
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 5,
}))
}
e.Use(middleware.Logger())
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{Output: &ptermWriter{Printer: pterm.Info}}))
return nil
}
}
Expand All @@ -95,6 +105,11 @@ func startBanner() {

func main() {
rand.Seed(time.Now().UTC().UnixNano())
if !terminal.IsTerminal(os.Stdout) {
pterm.DisableColor()
pterm.DisableStyling()
}

app := &cli.App{
Name: "containerbay",
Author: "Ettore Di Giacinto",
Expand Down

0 comments on commit 556cffb

Please sign in to comment.