Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start logging to a file. #19

Merged
merged 1 commit into from
Jul 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/AlecAivazis/survey/v2"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -84,6 +85,8 @@ This will configure:
if err != nil {
fmt.Println(err)
}

log.Info("Configuration complete.")
},
}

Expand Down
10 changes: 10 additions & 0 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -15,6 +16,15 @@ var rootCmd = &cobra.Command{
Long: `The Cloud Unpacked Dynamic DNS tool (cu-ddns) sets up Linode as a DDNS
provider. Useful for networks with a changing IP address such as a home
network.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {

logFile, err := os.OpenFile("/var/log/cu-ddns.log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
log.Error("Error opening log file. Logging to stderr instead.")
} else {
log.SetOutput(logFile)
}
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"

"golang.org/x/oauth2"

"github.com/cloudflare/cloudflare-go"
"github.com/linode/linodego"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -130,6 +130,8 @@ var runCmd = &cobra.Command{
} else {
log.Fatal("Provider not supported.")
}

log.Info("Successfully updated " + viper.GetString("provider") + " the IP: " + dIP)
},
}

Expand Down
3 changes: 2 additions & 1 deletion src/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -30,7 +31,7 @@ var startCmd = &cobra.Command{
}

fmt.Println("cu-ddns has been set to run hourly.")

log.Info("Hourly cron enabled.")
},
}

Expand Down
3 changes: 2 additions & 1 deletion src/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -29,7 +30,7 @@ var stopCmd = &cobra.Command{
}

fmt.Println("cu-ddns will no longer run automatically.")

log.Info("Hourly cron disabled.")
},
}

Expand Down
1 change: 1 addition & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.0.1
github.com/cloudflare/cloudflare-go v0.9.2
github.com/linode/linodego v0.9.0
github.com/sirupsen/logrus v1.2.0
github.com/spf13/cobra v0.0.4
github.com/spf13/viper v1.4.0
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
Expand Down
1 change: 1 addition & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down