Browse Source

Add EmitDiagnosticNoticesToFiles clientlib Parameter

- Allows different clientlib consumers to choose
  whether to use the rotating log file facility
Rod Hynes 6 years ago
parent
commit
6698adcf97
2 changed files with 13 additions and 5 deletions
  1. 6 0
      ClientLibrary/PsiphonTunnel.go
  2. 7 5
      ClientLibrary/clientlib/clientlib.go

+ 6 - 0
ClientLibrary/PsiphonTunnel.go

@@ -205,6 +205,12 @@ func PsiphonTunnelStart(cConfigJSON, cEmbeddedServerEntryList *C.char, cParams *
 		params.EstablishTunnelTimeoutSeconds = &v
 	}
 
+	// As Client Library doesn't currently implement callbacks, diagnostic
+	// notices aren't relayed to the client application. Set
+	// EmitDiagnosticNoticesToFiles to ensure the rotating diagnostic log file
+	// facility is used when EmitDiagnosticNotices is specified in the config.
+	params.EmitDiagnosticNoticesToFiles = true
+
 	startTime := time.Now()
 
 	// Start the tunnel connection

+ 7 - 5
ClientLibrary/clientlib/clientlib.go

@@ -60,6 +60,12 @@ type Parameters struct {
 	// Zero means there will be no timeout.
 	// Optional.
 	EstablishTunnelTimeoutSeconds *int
+
+	// EmitDiagnosticNoticesToFile indicates whether to use the rotating log file
+	// facility to record diagnostic notices instead of sending diagnostic
+	// notices to noticeReceiver. Has no effect unless the tunnel
+	// config.EmitDiagnosticNotices flag is set.
+	EmitDiagnosticNoticesToFiles bool
 }
 
 // PsiphonTunnel is the tunnel object. It can be used for stopping the tunnel and
@@ -154,11 +160,7 @@ func StartTunnel(ctx context.Context,
 		}
 	}
 
-	// As Client Library doesn't currently implement callbacks, diagnostic
-	// notices aren't relayed to the client application. So, when
-	// EmitDiagnosticNotices is set, initialize the rotating diagnostic log file
-	// facility.
-	if config.EmitDiagnosticNotices {
+	if config.EmitDiagnosticNotices && params.EmitDiagnosticNoticesToFiles {
 		err := psiphon.SetNoticeFiles("", filepath.Join(config.DataStoreDirectory, "diagnostics.log"), 0, 0)
 		if err != nil {
 			return nil, common.ContextErrorMsg(err, "failed to initialize diagnostic logging")