[Pkg-privacy-commits] [obfs4proxy] 47/151: Allow logging to be disabled (default).

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:59:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository obfs4proxy.

commit 676e0428e75a7808e3fac81d777b8cc69e81b712
Author: Yawning Angel <yawning at schwanenlied.me>
Date:   Tue May 20 17:12:19 2014 +0000

    Allow logging to be disabled (default).
    
    Part of #6, still need to make logs nicer.
---
 obfs4proxy/obfs4proxy.go | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/obfs4proxy/obfs4proxy.go b/obfs4proxy/obfs4proxy.go
index 8447eb8..215068d 100644
--- a/obfs4proxy/obfs4proxy.go
+++ b/obfs4proxy/obfs4proxy.go
@@ -316,17 +316,28 @@ func ptGetStateDir() (dir string, err error) {
 	return
 }
 
-func ptInitializeLogging() {
-	dir, err := ptGetStateDir()
-	if err != nil || dir == "" {
-		return
-	}
+type discardWriter struct{}
 
-	f, err := os.OpenFile(path.Join(dir, obfs4LogFile), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
-	if err != nil {
-		log.Fatalf("[ERROR] Failed to open log file: %s", err)
+func (d discardWriter) Write(p []byte) (n int, err error) {
+	return len(p), nil
+}
+
+func ptInitializeLogging(enable bool) {
+	if enable {
+		dir, err := ptGetStateDir()
+		if err != nil || dir == "" {
+			return
+		}
+
+		f, err := os.OpenFile(path.Join(dir, obfs4LogFile), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
+		if err != nil {
+			log.Fatalf("[ERROR] Failed to open log file: %s", err)
+		}
+		log.SetOutput(f)
+	} else {
+		var d discardWriter
+		log.SetOutput(d)
 	}
-	log.SetOutput(f)
 }
 
 func generateServerParams(id string) {
@@ -371,7 +382,8 @@ func generateServerParams(id string) {
 
 func main() {
 	// Some command line args.
-	genParams := flag.String("gen", "", "Generate server params given a bridge fingerprint.")
+	genParams := flag.String("genServerParams", "", "Generate server params given a bridge fingerprint.")
+	doLogging := flag.Bool("enableLogging", false, "Log to TOR_PT_STATE_LOCATION/obfs4proxy.log")
 	flag.Parse()
 	if *genParams != "" {
 		generateServerParams(*genParams)
@@ -379,7 +391,7 @@ func main() {
 	}
 
 	// Initialize pt logging.
-	ptInitializeLogging()
+	ptInitializeLogging(*doLogging)
 
 	// Go through the pt protocol and initialize client or server mode.
 	launched := false
@@ -393,6 +405,9 @@ func main() {
 	}
 
 	log.Println("[INFO] obfs4proxy - Launched and listening")
+	defer func() {
+		log.Println("[INFO] obfs4proxy - Terminated")
+	}()
 
 	// Handle termination notification.
 	numHandlers := 0

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfs4proxy.git



More information about the Pkg-privacy-commits mailing list