From 57cfa58833a00ecd1c5791ec9716a5028f45ce64 Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 11 Mar 2020 03:46:28 +1100 Subject: [PATCH] add logfile support --- main.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index f29b28d..b245985 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,9 @@ package main import ( "log" "net/http" + "os" "text/template" + "time" ) func main() { @@ -11,20 +13,25 @@ func main() { readConfigForTest() db.h = nil //make sure it's in proper state. + filename := "rpn.superforex." + time.Now().Format("20060102150406") + ".log" + f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + if err != nil { + log.Fatalf("error opening file: %v", err) + } + defer f.Close() + log.SetOutput(f) + log.Println("Server started on: http://localhost:8080") + + //setup http handler http.HandleFunc("/choosePayment", choosePayment) http.HandleFunc("/rpnNameAndCard", rpnNameAndCard) http.HandleFunc("/rpn_notify", rpnNotify) //called by rpn - // http.HandleFunc("/", Index) - // http.HandleFunc("/show", Show) - // http.HandleFunc("/new", New) - // http.HandleFunc("/edit", Edit) - // http.HandleFunc("/insert", Insert) - // http.HandleFunc("/update", Update) - // http.HandleFunc("/delete", Delete) fs := wrapHandler(http.FileServer(http.Dir("./PG"))) http.HandleFunc("/", fs) http.ListenAndServe(":8080", nil) - log.Println("Server started on: http://localhost:8080") + + //start log file + } func errPage(w http.ResponseWriter, code int, msg string) {