2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 06:46:34 +00:00
restic/cmd/khepri/debug.go
2014-11-15 19:08:15 +01:00

38 lines
780 B
Go

// +build debug
package main
import (
"fmt"
"io"
"log"
"os"
"path/filepath"
"time"
)
var debugLogger = initDebugLogger()
func initDebugLogger() *log.Logger {
// create new log file
filename := fmt.Sprintf("khepri-debug-%d-%s",
os.Getpid(), time.Now().Format("20060201-150405"))
f, err := os.OpenFile(filepath.Join(os.TempDir(), filename),
os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to create debug log file: %v", err)
os.Exit(2)
}
// open logger
l := log.New(io.MultiWriter(os.Stderr, f), "DEBUG: ", log.LstdFlags)
fmt.Fprintf(os.Stderr, "logging activated, writing log file %s", filename)
l.Printf("khepri %s", version)
return l
}
func debug(fmt string, args ...interface{}) {
debugLogger.Printf(fmt, args...)
}