mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-13 17:40:53 +00:00
Write to logfile, cut some of logging
This commit is contained in:
parent
014e7bc5e5
commit
6c422b8782
2 changed files with 14 additions and 7 deletions
|
@ -44,6 +44,12 @@ func main() {
|
||||||
Addr: conf.ListenAddr,
|
Addr: conf.ListenAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logFile, err := os.OpenFile("output.log", os.O_WRONLY | os.O_APPEND | os.O_CREATE, 0644)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Could not create logfile: ", err)
|
||||||
|
}
|
||||||
|
log.SetOutput(logFile)
|
||||||
|
|
||||||
server.SetupServerAndHandle(conf, nil)
|
server.SetupServerAndHandle(conf, nil)
|
||||||
|
|
||||||
go commandLineConsole()
|
go commandLineConsole()
|
||||||
|
|
|
@ -102,7 +102,6 @@ func ServeWebsocketOrCatbag(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "error: %v", err)
|
fmt.Fprintf(w, "error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("upgraded!")
|
|
||||||
HandleSocketConnection(conn)
|
HandleSocketConnection(conn)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -113,6 +112,10 @@ func ServeWebsocketOrCatbag(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var CloseGotBinaryMessage = websocket.CloseError{Code: websocket.CloseUnsupportedData, Text: "got binary packet"}
|
var CloseGotBinaryMessage = websocket.CloseError{Code: websocket.CloseUnsupportedData, Text: "got binary packet"}
|
||||||
var CloseGotMessageId0 = websocket.CloseError{Code: websocket.ClosePolicyViolation, Text: "got messageid 0"}
|
var CloseGotMessageId0 = websocket.CloseError{Code: websocket.ClosePolicyViolation, Text: "got messageid 0"}
|
||||||
|
var CloseFirstMessageNotHello = websocket.CloseError{
|
||||||
|
Text: "Error - the first message sent must be a 'hello'",
|
||||||
|
Code: websocket.ClosePolicyViolation,
|
||||||
|
}
|
||||||
|
|
||||||
// Handle a new websocket connection from a FFZ client.
|
// Handle a new websocket connection from a FFZ client.
|
||||||
// This runs in a goroutine started by net/http.
|
// This runs in a goroutine started by net/http.
|
||||||
|
@ -198,10 +201,7 @@ RunLoop:
|
||||||
case msg := <-clientChan:
|
case msg := <-clientChan:
|
||||||
if client.Version == "" && msg.Command != HelloCommand {
|
if client.Version == "" && msg.Command != HelloCommand {
|
||||||
log.Println("error - first message wasn't hello from", conn.RemoteAddr(), "-", msg)
|
log.Println("error - first message wasn't hello from", conn.RemoteAddr(), "-", msg)
|
||||||
CloseConnection(conn, &websocket.CloseError{
|
CloseConnection(conn, &CloseFirstMessageNotHello)
|
||||||
Text: "Error - the first message sent must be a 'hello'",
|
|
||||||
Code: websocket.ClosePolicyViolation,
|
|
||||||
})
|
|
||||||
break RunLoop
|
break RunLoop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +244,9 @@ func CallHandler(handler CommandHandler, conn *websocket.Conn, client *ClientInf
|
||||||
}
|
}
|
||||||
|
|
||||||
func CloseConnection(conn *websocket.Conn, closeMsg *websocket.CloseError) {
|
func CloseConnection(conn *websocket.Conn, closeMsg *websocket.CloseError) {
|
||||||
fmt.Println("Terminating connection with", conn.RemoteAddr(), "-", closeMsg.Text)
|
if closeMsg != &CloseFirstMessageNotHello {
|
||||||
|
log.Println("Terminating connection with", conn.RemoteAddr(), "-", closeMsg.Text)
|
||||||
|
}
|
||||||
conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(closeMsg.Code, closeMsg.Text), time.Now().Add(2*time.Minute))
|
conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(closeMsg.Code, closeMsg.Text), time.Now().Add(2*time.Minute))
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
@ -254,7 +256,6 @@ func SendMessage(conn *websocket.Conn, msg ClientMessage) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to marshal: %v %v", err, msg))
|
panic(fmt.Sprintf("failed to marshal: %v %v", err, msg))
|
||||||
}
|
}
|
||||||
fmt.Println(string(packet))
|
|
||||||
conn.WriteMessage(messageType, packet)
|
conn.WriteMessage(messageType, packet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue