2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-25 06:07:44 +00:00

Use different tags for debug log

This commit is contained in:
Alexander Neumann 2014-11-16 15:40:28 +01:00
parent cf33b01582
commit 616a2c749d
3 changed files with 9 additions and 11 deletions

View File

@ -1,4 +1,4 @@
// +build debug
// +build debug_cmd
package main
@ -17,8 +17,8 @@ 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)
path := filepath.Join(os.TempDir(), filename)
f, err := os.OpenFile(path, 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)
@ -26,7 +26,7 @@ func initDebugLogger() *log.Logger {
// open logger
l := log.New(io.MultiWriter(os.Stderr, f), "DEBUG: ", log.LstdFlags)
fmt.Fprintf(os.Stderr, "logging activated, writing log file %s\n", filename)
fmt.Fprintf(os.Stderr, "debug log for khepri command activated, writing log file %s\n", path)
l.Printf("khepri %s", version)
return l

View File

@ -1,4 +1,4 @@
// +build !debug
// +build !debug_cmd
package main

View File

@ -11,15 +11,14 @@ import (
"time"
)
var version = "compiled manually"
var debugLogger = initDebugLogger()
func initDebugLogger() *log.Logger {
// create new log file
filename := fmt.Sprintf("khepri-debug-%d-%s",
filename := fmt.Sprintf("khepri-lib-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)
path := filepath.Join(os.TempDir(), filename)
f, err := os.OpenFile(path, 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)
@ -27,8 +26,7 @@ func initDebugLogger() *log.Logger {
// open logger
l := log.New(io.MultiWriter(os.Stderr, f), "DEBUG: ", log.LstdFlags)
fmt.Fprintf(os.Stderr, "logging activated, writing log file %s\n", filename)
l.Printf("khepri %s", version)
fmt.Fprintf(os.Stderr, "debug log for khepri library activated, writing log file %s\n", path)
return l
}