mirror of
https://github.com/restic/restic.git
synced 2024-12-22 07:43:03 +00:00
Add debug() function to khepri cmd and lib
This commit is contained in:
parent
4b0fae6099
commit
bd105b69a8
3 changed files with 44 additions and 1 deletions
|
@ -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", filename)
|
||||
fmt.Fprintf(os.Stderr, "logging activated, writing log file %s\n", filename)
|
||||
l.Printf("khepri %s", version)
|
||||
|
||||
return l
|
||||
|
|
38
debug.go
Normal file
38
debug.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
// +build debug
|
||||
|
||||
package khepri
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
var version = "compiled manually"
|
||||
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\n", filename)
|
||||
l.Printf("khepri %s", version)
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
func debug(fmt string, args ...interface{}) {
|
||||
debugLogger.Printf(fmt, args...)
|
||||
}
|
5
debug_release.go
Normal file
5
debug_release.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
// +build !debug
|
||||
|
||||
package khepri
|
||||
|
||||
func debug(fmt string, args ...interface{}) {}
|
Loading…
Reference in a new issue