Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit b9c154e

Browse files
committed
added logging
1 parent 8cf0944 commit b9c154e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"log"
88
"net/http"
9+
"os"
910
"os/exec"
1011
)
1112

@@ -43,7 +44,17 @@ func loadConfig(configFile *string) {
4344
}
4445
}
4546

47+
func setLog(logFile *string) {
48+
log_handler, err := os.OpenFile(*logFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777)
49+
if err != nil {
50+
panic("cannot write log")
51+
}
52+
log.SetOutput(log_handler)
53+
log.SetFlags(5)
54+
}
55+
4656
func startWebserver() {
57+
log.Println("starting webserver")
4758
http.ListenAndServe(":"+*port, nil)
4859
}
4960

@@ -74,13 +85,15 @@ func executeShell(shell string) {
7485
var (
7586
port = flag.String("port", "7654", "port to listen on")
7687
configFile = flag.String("config", "./config.json", "config")
88+
logFile = flag.String("log", "./log", "log file")
7789
)
7890

7991
func init() {
8092
flag.Parse()
8193
}
8294

8395
func main() {
96+
setLog(logFile)
8497
loadConfig(configFile)
8598
startWebserver()
8699
}

0 commit comments

Comments
 (0)