66 "log"
77 "net/url"
88 "os"
9+ "path/filepath"
910 "time"
1011
1112 "github.com/alecthomas/kong"
@@ -32,6 +33,7 @@ type CLI struct {
3233 Version commands.VersionCmd `cmd help:"Print sectionctl version"`
3334 WhoAmI commands.WhoAmICmd `cmd name:"whoami" help:"Show information about the currently authenticated user"`
3435 Debug bool `env:"DEBUG" help:"Enable debug output"`
36+ DebugFileDir string `default:"." help:"Directory where debug output should be written"`
3537 SectionToken string `env:"SECTION_TOKEN" help:"Secret token for API auth"`
3638 SectionAPIPrefix * url.URL `default:"https://aperture.section.io" env:"SECTION_API_PREFIX"`
3739 SectionAPITimeout time.Duration `default:"30s" env:"SECTION_API_TIMEOUT" help:"Request timeout for the Section API"`
@@ -51,16 +53,17 @@ func bootstrap(c CLI, ctx *kong.Context) {
5153 }
5254 if c .Debug {
5355 filter .MinLevel = logutils .LogLevel ("DEBUG" )
54- logFilename := fmt .Sprintf ("sectionctl-debug-%s.log" , time .Now ().Format (time .RFC3339 ))
55- logFile , err := os .OpenFile (logFilename , os .O_CREATE | os .O_APPEND | os .O_RDWR , 0666 )
56+ logFilename := fmt .Sprintf ("sectionctl-debug-%s.log" , time .Now ().Format ("2006-01-02-15-04-05Z0700" ))
57+ logFilePath := filepath .Join (c .DebugFileDir , logFilename )
58+ logFile , err := os .OpenFile (logFilePath , os .O_CREATE | os .O_APPEND | os .O_RDWR , 0666 )
5659 if err != nil {
5760 panic (err )
5861 }
5962 fmt .Fprintf (logFile , "Version: %s\n " , commands.VersionCmd {}.String ())
6063 fmt .Fprintf (logFile , "Command: %s\n " , ctx .Args )
6164 fmt .Fprintf (logFile , "PrefixURI: %s\n " , api .PrefixURI )
6265 fmt .Fprintf (logFile , "Timeout: %s\n " , api .Timeout )
63- fmt .Printf ("Writing debug log to: %s\n " , logFilename )
66+ fmt .Printf ("Writing debug log to: %s\n " , logFilePath )
6467 mw := io .MultiWriter (logFile , colorableWriter )
6568 filter .Writer = mw
6669 }
0 commit comments