Skip to content

Commit

Permalink
feat(agent): ✨ add a --no-log-file command-line option to not write…
Browse files Browse the repository at this point in the history
… a log file
  • Loading branch information
joshuar committed Apr 29, 2024
1 parent 39480b1 commit 59f2ce5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ var registerCmd = &cobra.Command{
Long: text.RegisterCmdLongText,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
logging.SetLoggingLevel(traceFlag, debugFlag, profileFlag)
logging.SetLogFile("go-hass-agent.log")
if !noLogFileFlag {
logging.SetLogFile("go-hass-agent.log")
}
},
Run: func(cmd *cobra.Command, args []string) {
agent := agent.New(&agent.Options{
Expand Down
4 changes: 3 additions & 1 deletion cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ var resetCmd = &cobra.Command{
Long: text.ResetCmdLongText,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
logging.SetLoggingLevel(traceFlag, debugFlag, profileFlag)
logging.SetLogFile("go-hass-agent.log")
if !noLogFileFlag {
logging.SetLogFile("go-hass-agent.log")
}
},
Run: func(cmd *cobra.Command, args []string) {
agent := agent.New(&agent.Options{
Expand Down
26 changes: 17 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import (
)

var (
traceFlag bool
debugFlag bool
AppID string
profileFlag bool
cpuProfile string
heapProfile string
headlessFlag bool
traceProfile string
traceFlag bool
debugFlag bool
AppID string
profileFlag bool
cpuProfile string
heapProfile string
headlessFlag bool
traceProfile string
noLogFileFlag bool
)

// rootCmd represents the base command when called without any subcommands.
Expand All @@ -43,8 +44,13 @@ var rootCmd = &cobra.Command{
Short: "A Home Assistant, native app integration for desktop/laptop devices.",
Long: text.RootCmdLongText,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
fmt.Println("here")
logging.SetLoggingLevel(traceFlag, debugFlag, profileFlag)
logging.SetLogFile("go-hass-agent.log")
fmt.Println("here")
if !noLogFileFlag {
logging.SetLogFile("go-hass-agent.log")
}
log.Info().Msg("here")
if cpuProfile != "" {
f, err := os.Create(cpuProfile)
if err != nil {
Expand Down Expand Up @@ -121,6 +127,8 @@ func init() {
"trace output (default is false)")
rootCmd.PersistentFlags().BoolVar(&debugFlag, "debug", false,
"debug output (default is false)")
rootCmd.PersistentFlags().BoolVar(&noLogFileFlag, "no-log-file", false,
"don't write to a log file (default is false)")
rootCmd.PersistentFlags().BoolVar(&profileFlag, "profile", false,
"enable profiling (default is false)")
rootCmd.PersistentFlags().StringVar(&cpuProfile, "cpu-profile", "",
Expand Down

0 comments on commit 59f2ce5

Please sign in to comment.