Commit 84936d8a authored by Erick Hitter's avatar Erick Hitter

No debugging, log it all!

parent 301cfcb8
Pipeline #174 passed with stages
in 15 minutes and 24 seconds
{ {
"debug-dest": "os.Stdout", "log-dest": "os.Stdout",
"debug": false,
"api-key": "", "api-key": "",
"threshold": 3600, "threshold": 3600,
"schedule": "* */10 * * * *", "schedule": "* */10 * * * *",
......
...@@ -19,8 +19,7 @@ import ( ...@@ -19,8 +19,7 @@ import (
) )
type config struct { type config struct {
DebugDest string `json:"debug-dest"` LogDest string `json:"log-dest"`
Debug bool `json:"debug"`
APIKey string `json:"api-key"` APIKey string `json:"api-key"`
Threshold int `json:"threshold"` Threshold int `json:"threshold"`
Schedule string `json:"schedule"` Schedule string `json:"schedule"`
...@@ -34,9 +33,8 @@ type tokenSource struct { ...@@ -34,9 +33,8 @@ type tokenSource struct {
var ( var (
configPath string configPath string
logger *log.Logger logger *log.Logger
debugDest string logDest string
debug bool
apiKey string apiKey string
...@@ -66,8 +64,7 @@ func init() { ...@@ -66,8 +64,7 @@ func init() {
usage() usage()
} }
debugDest = cfg.DebugDest logDest = cfg.LogDest
debug = cfg.Debug
apiKey = cfg.APIKey apiKey = cfg.APIKey
...@@ -166,9 +163,6 @@ func listDroplets(ctx context.Context, client *godo.Client) ([]godo.Droplet, err ...@@ -166,9 +163,6 @@ func listDroplets(ctx context.Context, client *godo.Client) ([]godo.Droplet, err
} }
func checkDropletAge(droplet godo.Droplet) { func checkDropletAge(droplet godo.Droplet) {
logger.Print(droplet.ID)
logger.Print(droplet.Created)
thr := time.Now().Add(time.Duration(threshold)) thr := time.Now().Add(time.Duration(threshold))
created, err := time.Parse(time.RFC3339, droplet.Created) created, err := time.Parse(time.RFC3339, droplet.Created)
if err != nil { if err != nil {
...@@ -194,10 +188,10 @@ func deleteDroplet(droplet godo.Droplet) bool { ...@@ -194,10 +188,10 @@ func deleteDroplet(droplet godo.Droplet) bool {
func setUpLogger() { func setUpLogger() {
logOpts := log.Ldate | log.Ltime | log.LUTC | log.Lshortfile logOpts := log.Ldate | log.Ltime | log.LUTC | log.Lshortfile
if debugDest == "os.Stdout" { if logDest == "os.Stdout" {
logger = log.New(os.Stdout, "DEBUG: ", logOpts) logger = log.New(os.Stdout, "DEBUG: ", logOpts)
} else { } else {
path, err := filepath.Abs(debugDest) path, err := filepath.Abs(logDest)
if err != nil { if err != nil {
logger.Fatal(err) logger.Fatal(err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment