Skip to content
Snippets Groups Projects
Commit 676e0428 authored by Yawning Angel's avatar Yawning Angel
Browse files

Allow logging to be disabled (default).

Part of #6, still need to make logs nicer.
parent 66edb786
Branches
No related tags found
No related merge requests found
...@@ -316,7 +316,14 @@ func ptGetStateDir() (dir string, err error) { ...@@ -316,7 +316,14 @@ func ptGetStateDir() (dir string, err error) {
return return
} }
func ptInitializeLogging() { type discardWriter struct{}
func (d discardWriter) Write(p []byte) (n int, err error) {
return len(p), nil
}
func ptInitializeLogging(enable bool) {
if enable {
dir, err := ptGetStateDir() dir, err := ptGetStateDir()
if err != nil || dir == "" { if err != nil || dir == "" {
return return
...@@ -327,6 +334,10 @@ func ptInitializeLogging() { ...@@ -327,6 +334,10 @@ func ptInitializeLogging() {
log.Fatalf("[ERROR] Failed to open log file: %s", err) log.Fatalf("[ERROR] Failed to open log file: %s", err)
} }
log.SetOutput(f) log.SetOutput(f)
} else {
var d discardWriter
log.SetOutput(d)
}
} }
func generateServerParams(id string) { func generateServerParams(id string) {
...@@ -371,7 +382,8 @@ func generateServerParams(id string) { ...@@ -371,7 +382,8 @@ func generateServerParams(id string) {
func main() { func main() {
// Some command line args. // 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() flag.Parse()
if *genParams != "" { if *genParams != "" {
generateServerParams(*genParams) generateServerParams(*genParams)
...@@ -379,7 +391,7 @@ func main() { ...@@ -379,7 +391,7 @@ func main() {
} }
// Initialize pt logging. // Initialize pt logging.
ptInitializeLogging() ptInitializeLogging(*doLogging)
// Go through the pt protocol and initialize client or server mode. // Go through the pt protocol and initialize client or server mode.
launched := false launched := false
...@@ -393,6 +405,9 @@ func main() { ...@@ -393,6 +405,9 @@ func main() {
} }
log.Println("[INFO] obfs4proxy - Launched and listening") log.Println("[INFO] obfs4proxy - Launched and listening")
defer func() {
log.Println("[INFO] obfs4proxy - Terminated")
}()
// Handle termination notification. // Handle termination notification.
numHandlers := 0 numHandlers := 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment