Skip to content

Commit

Permalink
Logfiles default dir and configurable log dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Dec 10, 2016
1 parent 4797460 commit 0a25111
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions builtin/bins/dkron-processor-files/files_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,31 @@ package main
import (
"fmt"
"io/ioutil"
"os"

log "github.com/Sirupsen/logrus"
"github.com/victorcoder/dkron/dkron"
)

const defaultLogDir = "/var/log/dkron"

type FilesOutput struct {
forward bool
logDir string
}

func (l *FilesOutput) Process(args *dkron.ExecutionProcessorArgs) dkron.Execution {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
l.parseConfig(args.Config)

out := args.Execution.Output
tmp := "." //os.TempDir()
filePath := fmt.Sprintf("%s/%s.log", tmp, args.Execution.Key())
filePath := fmt.Sprintf("%s/%s.log", l.logDir, args.Execution.Key())

log.WithField("file", filePath).Info("files: Writing file")
if err := ioutil.WriteFile(filePath, out, 0644); err != nil {
log.WithError(err).Error("Error writting log file")
}
l.parseConfig(args.Config)

if !l.forward {
args.Execution.Output = []byte(filePath)
}
Expand All @@ -37,6 +41,19 @@ func (l *FilesOutput) parseConfig(config dkron.PluginConfig) {
l.forward = forward
log.Infof("Forwarding set to: %s", forward)
} else {
log.Error("Incorrect format in forward param")
l.forward = false
log.WithField("param", "forward").Warning("Incorrect format or param not found.")
}

logDir, ok := config["log_dir"].(string)
if ok {
l.logDir = logDir
log.Infof("Log dir set to: %s", logDir)
} else {
l.logDir = defaultLogDir
log.WithField("param", "log_dir").Warning("Incorrect format or param not found.")
if _, err := os.Stat(defaultLogDir); os.IsNotExist(err) {
os.MkdirAll(defaultLogDir, os.ModePerm)
}
}
}

0 comments on commit 0a25111

Please sign in to comment.