Goit

Simple and lightweight Git web server
Mirror of https://github.com/Jamozed/Goit
git clone http://git.omkov.net/Goit
Log | Tree | Refs | README | Download

AuthorJakob Wakeling <[email protected]>
Date2023-11-27 08:58:27
Commitc768e5c1b66cada5b99688924036c9a4f5d1a272
Parent3c55d1d0149283f0387e3111a86d10a5b18a0acf

Log to file as well as STDOUT

Diffstat

M src/goit/goit.go | 15 +++++++++++++++
M src/main.go | 4 +---

2 files changed, 16 insertions, 3 deletions

diff --git a/src/goit/goit.go b/src/goit/goit.go
index 6ae4c24..25130bd 100644
--- a/src/goit/goit.go
+++ b/src/goit/goit.go
@@ -18,6 +18,7 @@ import (
 	"strings"
 	"time"
 
+	"github.com/Jamozed/Goit/res"
 	"github.com/Jamozed/Goit/src/util"
 	"github.com/adrg/xdg"
 	"github.com/go-git/go-git/v5"
@@ -59,6 +60,19 @@ func Goit(conf string) (err error) {
 		}
 	}
 
+	logPath, err := xdg.StateFile(filepath.Join("goit", fmt.Sprint("goit_", time.Now().Unix(), ".log")))
+	if err != nil {
+		log.Fatalln("[log]", err.Error())
+	}
+
+	logFile, err := os.Create(logPath)
+	if err != nil {
+		log.Fatalln("[log]", err.Error())
+	}
+
+	log.SetOutput(io.MultiWriter(os.Stderr, logFile))
+	log.Println("Starting Goit", res.Version)
+
 	log.Println("[Config] using data path:", Conf.DataPath)
 	if err := os.MkdirAll(Conf.DataPath, 0o777); err != nil {
 		return fmt.Errorf("[Config] %w", err)
diff --git a/src/main.go b/src/main.go
index 3d96181..d5cdf8c 100644
--- a/src/main.go
+++ b/src/main.go
@@ -58,8 +58,6 @@ func main() {
 		os.Exit(util.If(buf[0] == 0x01, -1, 0))
 	}
 
-	log.Println("Starting Goit", res.Version)
-
 	/* Listen for and handle SIGINT */
 	stop := make(chan struct{})
 	wait := &sync.WaitGroup{}
@@ -73,6 +71,7 @@ func main() {
 		os.Exit(0)
 	}()
 
+	/* Initialise Goit */
 	if err := goit.Goit(goit.ConfPath()); err != nil {
 		log.Fatalln(err.Error())
 	}