[tor-commits] [flashproxy/master] Add --log option to websocket-server.

dcf at torproject.org dcf at torproject.org
Thu Jan 31 23:43:54 UTC 2013


commit 84d83a2e5f21d49c0d56eb4e24e48fcd25bea793
Author: David Fifield <david at bamsoftware.com>
Date:   Thu Jan 31 15:10:52 2013 -0800

    Add --log option to websocket-server.
---
 websocket-transport/websocket-server.go |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/websocket-transport/websocket-server.go b/websocket-transport/websocket-server.go
index 725053c..0556c98 100644
--- a/websocket-transport/websocket-server.go
+++ b/websocket-transport/websocket-server.go
@@ -18,6 +18,8 @@ import (
 	"sync"
 )
 
+var logFile = os.Stderr
+
 var ptInfo PtServerInfo
 
 // When a connection handler starts, +1 is written to this channel; when it
@@ -25,7 +27,7 @@ var ptInfo PtServerInfo
 var handlerChan = make(chan int)
 
 func logDebug(format string, v ...interface{}) {
-	fmt.Fprintf(os.Stderr, format+"\n", v...)
+	fmt.Fprintf(logFile, format+"\n", v...)
 }
 
 // An abstraction that makes an underlying WebSocket connection look like an
@@ -179,10 +181,21 @@ func startListener(addr *net.TCPAddr) (*net.TCPListener, error) {
 func main() {
 	const ptMethodName = "websocket"
 	var defaultPort int
+	var logFilename string
 
 	flag.IntVar(&defaultPort, "port", 0, "port to listen on if unspecified by Tor")
+	flag.StringVar(&logFilename, "log", "", "log file to write to")
 	flag.Parse()
 
+	if logFilename != "" {
+		f, err := os.OpenFile(logFilename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "Can't open log file %q: %s.\n", logFilename, err.Error())
+			os.Exit(1)
+		}
+		logFile = f
+	}
+
 	ptInfo = PtServerSetup([]string{ptMethodName})
 
 	listeners := make([]*net.TCPListener, 0)



More information about the tor-commits mailing list