If I comment out lines 19 and 20 (i.e. I don’t start the listener), then the logging and the wait both work. Leaving them in, once the listener starts, no further logging takes place. “before listener starts” gets properly logged, but “after listener starts” does not. Also, wait for input from stdin doesn’t work either. For testing purposes, I’d like to log various messages and wait for input now and again. Any ideas, anyone?
package main
import (“fmt”
“net/http”
“log”
“os”
“bufio”)
var mux = http.NewServeMux()
func index(w http.ResponseWriter, r *http.Request) { }
func main() {
mux.HandleFunc("/", index)
logFile, err1 := os.OpenFile(“logfile.txt”, os.O_RDWR|os.O_CREATE, 0755)
if err1 != nil { fmt.Println(“error opening log file”)
return }
defer logFile.Close()
log.SetOutput(logFile)
fmt.Println(“test log pgm”)
log.Println(“before listener starts”)
err := http.ListenAndServe(":8080", mux) // take this out, and logging works correctly
log.Fatal(err) // and this
log.Println(“after listener starts”)
wait()
return
}
func wait() {
fmt.Println(“waiting…”)
log.Println(“waiting…”)
reader := bufio.NewReader(os.Stdin)
input, _ := reader.ReadString(’\n’)
input=input+“dummy”
}