arnaucube
arnaucube/blockchainIDsystemPublic Self-hosted repository
blockchainIDsystem/peer/log.go
peer/log.goRaw
 1package main
 2
 3import (
 4	"io"
 5	"log"
 6	"os"
 7	"strings"
 8	"time"
 9)
10
11func savelog() {
12	timeS := time.Now().String()
13	_ = os.Mkdir("logs", os.ModePerm)
14	//next 3 lines are to avoid windows filesystem errors
15	timeS = strings.Replace(timeS, " ", "_", -1)
16	timeS = strings.Replace(timeS, ".", "-", -1)
17	timeS = strings.Replace(timeS, ":", "-", -1)
18	logFile, err := os.OpenFile("logs/log-"+timeS+".log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
19	if err != nil {
20		panic(err)
21	}
22	mw := io.MultiWriter(os.Stdout, logFile)
23	log.SetOutput(mw)
24}