Skip to content

Commit

Permalink
Add file logging to granted (#451)
Browse files Browse the repository at this point in the history
* Add file logging to granted

* use the latest clio version

* add file logging to assume cmd
  • Loading branch information
Eddie023 authored Aug 2, 2023
1 parent 5ebabe7 commit 9addb71
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ require (

require (
github.com/briandowns/spinner v1.23.0
github.com/common-fate/clio v1.2.1
github.com/common-fate/cli v0.4.5
github.com/common-fate/clio v1.1.0
github.com/common-fate/common-fate v0.15.0
github.com/fatih/color v1.13.0
github.com/lithammer/fuzzysearch v1.1.5
Expand Down Expand Up @@ -75,6 +75,7 @@ require (
golang.org/x/oauth2 v0.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)

require (
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ github.com/common-fate/cli v0.4.5 h1:WEuUVtWmsDRmYt69eBRX/Bv9Dj65qHy0p28aIXlYbh4
github.com/common-fate/cli v0.4.5/go.mod h1:CSq3HFjg3se/IFujNdp8LDEKlAKVMoMOQz+oeLlNFu0=
github.com/common-fate/clio v1.1.0 h1:M5fyMuYHjB+qODYbl0IGT28SBiokxsIlxluUVnD8cOQ=
github.com/common-fate/clio v1.1.0/go.mod h1:BYm9XmDIsmpQQdw+xbhQO5hbpUhH03Lk6gQmQ6Wpu1k=
github.com/common-fate/clio v1.1.1-0.20230801053624-539d17a2c7c7 h1:r8Eb0kF05E31JmpCIAdHy89C1sivCUQJsOLmEOxs9nU=
github.com/common-fate/clio v1.1.1-0.20230801053624-539d17a2c7c7/go.mod h1:NkozaS15SA+6Y9zb+82eIj1i41aWShorTqA01GKQ7A8=
github.com/common-fate/clio v1.2.0 h1:F1E8WAu4mE+0zz4di5aDcVC+cqaLin9S20nFylhufvI=
github.com/common-fate/clio v1.2.0/go.mod h1:NkozaS15SA+6Y9zb+82eIj1i41aWShorTqA01GKQ7A8=
github.com/common-fate/clio v1.2.1 h1:op+k1ONrakrjS7mANQBIjum/yK7hc3qj29HAJkgWzqo=
github.com/common-fate/clio v1.2.1/go.mod h1:NkozaS15SA+6Y9zb+82eIj1i41aWShorTqA01GKQ7A8=
github.com/common-fate/cloudform v0.6.0 h1:VDme3jSJAltnF8OlSdqxjHn8YnvIoknARvISN+OHkdQ=
github.com/common-fate/cloudform v0.6.0/go.mod h1:lWkYU3gfk0ohl66sdML9qCYxe5nSdbcqS6U9j/ewmjw=
github.com/common-fate/common-fate v0.15.0 h1:ZDpc1x6DctuU2l5ILt5q8MB4V9beYfliQ40t9XGMtkw=
Expand Down Expand Up @@ -665,6 +671,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
12 changes: 12 additions & 0 deletions pkg/assume/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package assume

import (
"os"
"path"

"github.com/common-fate/clio"
"github.com/common-fate/clio/cliolog"
"github.com/common-fate/granted/internal/build"
"github.com/common-fate/granted/pkg/alias"
"github.com/common-fate/granted/pkg/autosync"
Expand Down Expand Up @@ -83,6 +85,16 @@ func GetCliApp() *cli.App {
return err
}

grantedFolder, err := config.GrantedConfigFolder()
if err != nil {
return err
}

logfilepath := path.Join(grantedFolder, "log")
clio.SetFileLogging(cliolog.FileLoggerConfig{
Filename: logfilepath,
})

if err := config.SetupConfigFolder(); err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/granted/entrypoint.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package granted

import (
"path"

"github.com/common-fate/cli/cmd/command"
"github.com/common-fate/clio"
"github.com/common-fate/clio/cliolog"
"github.com/common-fate/granted/internal/build"
"github.com/common-fate/granted/pkg/banners"
"github.com/common-fate/granted/pkg/config"
Expand Down Expand Up @@ -52,6 +55,18 @@ func GetCliApp() *cli.App {
EnableBashCompletion: true,
Before: func(c *cli.Context) error {
clio.SetLevelFromEnv("GRANTED_LOG")

grantedFolder, err := config.GrantedConfigFolder()
if err != nil {
return err
}

logfilepath := path.Join(grantedFolder, "log")

clio.SetFileLogging(cliolog.FileLoggerConfig{
Filename: logfilepath,
})

zap.ReplaceGlobals(clio.G())
if c.Bool("verbose") {
clio.SetLevelFromString("debug")
Expand Down

0 comments on commit 9addb71

Please sign in to comment.