Skip to content

Commit

Permalink
add config options for log file rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip committed Oct 29, 2016
1 parent 95a8b8e commit 9409135
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions config.go
Expand Up @@ -22,6 +22,9 @@ type pdnsConfig struct {
kafkaBrokers string
kafkaTopic string
logFile string
logMaxAge int
logMaxSize int
logMaxBackups int
statsdHost string
statsdInterval int
statsdPrefix string
Expand All @@ -36,6 +39,9 @@ func initConfig() *pdnsConfig {
var bpf = flag.String("bpf", getEnvStr("PDNS_BPF", "port 53"), "BPF Filter") //default port 53
var pcapFile = flag.String("pcap", getEnvStr("PDNS_PCAP_FILE", ""), "pcap file")
var logFile = flag.String("logfile", getEnvStr("PDNS_LOG_FILE", ""), "log file (recommended for debug only")
var logMaxAge = flag.Int("logMaxAge", getEnvInt("PDNS_LOG_AGE", 28), "max age of a log file before rotation, in days") //8
var logMaxBackups = flag.Int("logMaxBackups", getEnvInt("PDNS_LOG_BACKUP", 3), "max number of files kept after rotation") //8
var logMaxSize = flag.Int("logMaxSize", getEnvInt("PDNS_LOG_SIZE", 100), "max size of log file before rotation, in MB") //8
var quiet = flag.Bool("quiet", getEnvBool("PDNS_QUIET", false), "do not log to stdout")
var gcAge = flag.String("gc_age", getEnvStr("PDNS_GC_AGE", "-1m"), "How old a connection table entry should be before it is garbage collected.") //-1m
var gcInterval = flag.String("gc_interval", getEnvStr("PDNS_GC_INTERVAL", "3m"), "How often to run garbage collection.") //3m
Expand Down Expand Up @@ -84,6 +90,9 @@ func initConfig() *pdnsConfig {
kafkaBrokers: *kafkaBrokers,
kafkaTopic: *kafkaTopic,
logFile: *logFile,
logMaxAge: *logMaxAge,
logMaxSize: *logMaxSize,
logMaxBackups: *logMaxBackups,
statsdHost: *statsdHost,
statsdInterval: *statsdInterval,
statsdPrefix: *statsdPrefix,
Expand Down
12 changes: 9 additions & 3 deletions log.go
Expand Up @@ -14,6 +14,9 @@ type logOptions struct {
quiet bool
debug bool
Filename string
MaxAge int
MaxBackups int
MaxSize int
KafkaBrokers string
KafkaTopic string
closed bool
Expand All @@ -27,6 +30,9 @@ func NewLogOptions(config *pdnsConfig) *logOptions {
Filename: config.logFile,
KafkaBrokers: config.kafkaBrokers,
KafkaTopic: config.kafkaTopic,
MaxAge: config.logMaxAge,
MaxSize: config.logMaxSize,
MaxBackups: config.logMaxBackups,
}
}

Expand Down Expand Up @@ -167,9 +173,9 @@ func logConnFile(logC chan dnsLogEntry, opts *logOptions) {

logger := &lumberjack.Logger{
Filename: opts.Filename,
MaxSize: 1, // megabytes
MaxBackups: 3,
MaxAge: 28, //days
MaxSize: opts.MaxSize, // megabytes
MaxBackups: opts.MaxBackups,
MaxAge: opts.MaxAge, //days
}

enc := ffjson.NewEncoder(bufio.NewWriter(logger))
Expand Down

0 comments on commit 9409135

Please sign in to comment.