[VOL-3199] Fixed a double mutex locking flow in earlier patch

Change-Id: I1379e674d51bedd3d13f91355f54e91a9a67eab3
diff --git a/VERSION b/VERSION
index 406ebcb..f092941 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.2.7
+3.2.8
diff --git a/pkg/log/log.go b/pkg/log/log.go
index 62a232e..b8d498c 100644
--- a/pkg/log/log.go
+++ b/pkg/log/log.go
@@ -520,134 +520,134 @@
 
 // Debug logs a message at level Debug on the standard logger.
 func (l clogger) Debug(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Debug(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Debug(args...)
 }
 
 // Debugln logs a message at level Debug on the standard logger with a line feed. Default in any case.
 func (l clogger) Debugln(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Debug(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Debug(args...)
 }
 
 // Debugw logs a message at level Debug on the standard logger.
 func (l clogger) Debugf(ctx context.Context, format string, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Debugf(format, args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Debugf(format, args...)
 }
 
 // Debugw logs a message with some additional context. The variadic key-value
 // pairs are treated as they are in With.
 func (l clogger) Debugw(ctx context.Context, msg string, keysAndValues Fields) {
 	if l.V(DebugLevel) {
-		l.log.With(ExtractContextAttributes(ctx)...).Debugw(msg, serializeMap(keysAndValues)...)
+		l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Debugw(msg, serializeMap(keysAndValues)...)
 	}
 }
 
 // Info logs a message at level Info on the standard logger.
 func (l clogger) Info(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Info(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Info(args...)
 }
 
 // Infoln logs a message at level Info on the standard logger with a line feed. Default in any case.
 func (l clogger) Infoln(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Info(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Info(args...)
 	//msg := fmt.Sprintln(args...)
 	//l.sourced().Info(msg[:len(msg)-1])
 }
 
 // Infof logs a message at level Info on the standard logger.
 func (l clogger) Infof(ctx context.Context, format string, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Infof(format, args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Infof(format, args...)
 }
 
 // Infow logs a message with some additional context. The variadic key-value
 // pairs are treated as they are in With.
 func (l clogger) Infow(ctx context.Context, msg string, keysAndValues Fields) {
 	if l.V(InfoLevel) {
-		l.log.With(ExtractContextAttributes(ctx)...).Infow(msg, serializeMap(keysAndValues)...)
+		l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Infow(msg, serializeMap(keysAndValues)...)
 	}
 }
 
 // Warn logs a message at level Warn on the standard logger.
 func (l clogger) Warn(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Warn(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Warn(args...)
 }
 
 // Warnln logs a message at level Warn on the standard logger with a line feed. Default in any case.
 func (l clogger) Warnln(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Warn(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Warn(args...)
 }
 
 // Warnf logs a message at level Warn on the standard logger.
 func (l clogger) Warnf(ctx context.Context, format string, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Warnf(format, args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Warnf(format, args...)
 }
 
 // Warnw logs a message with some additional context. The variadic key-value
 // pairs are treated as they are in With.
 func (l clogger) Warnw(ctx context.Context, msg string, keysAndValues Fields) {
 	if l.V(WarnLevel) {
-		l.log.With(ExtractContextAttributes(ctx)...).Warnw(msg, serializeMap(keysAndValues)...)
+		l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Warnw(msg, serializeMap(keysAndValues)...)
 	}
 }
 
 // Error logs a message at level Error on the standard logger.
 func (l clogger) Error(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Error(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Error(args...)
 }
 
 // Errorln logs a message at level Error on the standard logger with a line feed. Default in any case.
 func (l clogger) Errorln(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Error(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Error(args...)
 }
 
 // Errorf logs a message at level Error on the standard logger.
 func (l clogger) Errorf(ctx context.Context, format string, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Errorf(format, args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Errorf(format, args...)
 }
 
 // Errorw logs a message with some additional context. The variadic key-value
 // pairs are treated as they are in With.
 func (l clogger) Errorw(ctx context.Context, msg string, keysAndValues Fields) {
 	if l.V(ErrorLevel) {
-		l.log.With(ExtractContextAttributes(ctx)...).Errorw(msg, serializeMap(keysAndValues)...)
+		l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Errorw(msg, serializeMap(keysAndValues)...)
 	}
 }
 
 // Fatal logs a message at level Fatal on the standard logger.
 func (l clogger) Fatal(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Fatal(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Fatal(args...)
 }
 
 // Fatalln logs a message at level Fatal on the standard logger with a line feed. Default in any case.
 func (l clogger) Fatalln(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Fatal(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Fatal(args...)
 }
 
 // Fatalf logs a message at level Fatal on the standard logger.
 func (l clogger) Fatalf(ctx context.Context, format string, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Fatalf(format, args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Fatalf(format, args...)
 }
 
 // Fatalw logs a message with some additional context. The variadic key-value
 // pairs are treated as they are in With.
 func (l clogger) Fatalw(ctx context.Context, msg string, keysAndValues Fields) {
 	if l.V(FatalLevel) {
-		l.log.With(ExtractContextAttributes(ctx)...).Fatalw(msg, serializeMap(keysAndValues)...)
+		l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Fatalw(msg, serializeMap(keysAndValues)...)
 	}
 }
 
 // Warning logs a message at level Warn on the standard logger.
 func (l clogger) Warning(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Warn(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Warn(args...)
 }
 
 // Warningln logs a message at level Warn on the standard logger with a line feed. Default in any case.
 func (l clogger) Warningln(ctx context.Context, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Warn(args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Warn(args...)
 }
 
 // Warningf logs a message at level Warn on the standard logger.
 func (l clogger) Warningf(ctx context.Context, format string, args ...interface{}) {
-	l.log.With(ExtractContextAttributes(ctx)...).Warnf(format, args...)
+	l.log.With(GetGlobalLFM().ExtractContextAttributes(ctx)...).Warnf(format, args...)
 }
 
 // V reports whether verbosity level l is at least the requested verbose level.
diff --git a/pkg/log/utils.go b/pkg/log/utils.go
index b10ff07..82c3d7d 100644
--- a/pkg/log/utils.go
+++ b/pkg/log/utils.go
@@ -155,7 +155,7 @@
 	defer lfm.lock.Unlock()
 
 	if isEnabled == lfm.isLogCorrelationEnabled {
-		defaultLogger.Debugf(context.Background(), "Ignoring Log Correlation Set operation with value %t; current Status same as desired", isEnabled)
+		logger.Debugf(context.Background(), "Ignoring Log Correlation Set operation with value %t; current Status same as desired", isEnabled)
 		return
 	}
 
@@ -165,7 +165,7 @@
 		if _, ok := opentracing.GlobalTracer().(opentracing.NoopTracer); ok {
 			tracer, _, err := lfm.constructJaegerTracer(lfm.isTracePublishingEnabled, lfm.activeTraceAgentAddress, false)
 			if err != nil {
-				defaultLogger.Warnf(context.Background(), "Log Correlation Enable operation failed with error: %s", err.Error())
+				logger.Warnf(context.Background(), "Log Correlation Enable operation failed with error: %s", err.Error())
 				return
 			}
 
@@ -173,7 +173,7 @@
 		}
 
 		lfm.isLogCorrelationEnabled = true
-		defaultLogger.Info(context.Background(), "Log Correlation has been enabled")
+		logger.Info(context.Background(), "Log Correlation has been enabled")
 
 	} else {
 		// Switch to NoopTracer when Log Correlation has been disabled and Tracing Publish is already disabled
@@ -182,7 +182,7 @@
 		}
 
 		lfm.isLogCorrelationEnabled = false
-		defaultLogger.Info(context.Background(), "Log Correlation has been disabled")
+		logger.Info(context.Background(), "Log Correlation has been disabled")
 	}
 }
 
@@ -198,7 +198,7 @@
 	defer lfm.lock.Unlock()
 
 	if isEnabled == lfm.isTracePublishingEnabled {
-		defaultLogger.Debugf(context.Background(), "Ignoring Trace Publishing Set operation with value %t; current Status same as desired", isEnabled)
+		logger.Debugf(context.Background(), "Ignoring Trace Publishing Set operation with value %t; current Status same as desired", isEnabled)
 		return
 	}
 
@@ -208,13 +208,13 @@
 		// Disable-Enable of Tracing
 		tracer, _, err := lfm.constructJaegerTracer(isEnabled, lfm.activeTraceAgentAddress, false)
 		if err != nil {
-			defaultLogger.Warnf(context.Background(), "Trace Publishing Enable operation failed with error: %s", err.Error())
+			logger.Warnf(context.Background(), "Trace Publishing Enable operation failed with error: %s", err.Error())
 			return
 		}
 		lfm.replaceActiveTracer(tracer)
 
 		lfm.isTracePublishingEnabled = true
-		defaultLogger.Info(context.Background(), "Tracing Publishing has been enabled")
+		logger.Info(context.Background(), "Tracing Publishing has been enabled")
 	} else {
 		// Switch to NoopTracer when Tracing Publish has been disabled and Log Correlation is already disabled
 		if !lfm.isLogCorrelationEnabled {
@@ -223,14 +223,14 @@
 			// Else construct a new Jaeger Instance with publishing disabled
 			tracer, _, err := lfm.constructJaegerTracer(isEnabled, lfm.activeTraceAgentAddress, false)
 			if err != nil {
-				defaultLogger.Warnf(context.Background(), "Trace Publishing Disable operation failed with error: %s", err.Error())
+				logger.Warnf(context.Background(), "Trace Publishing Disable operation failed with error: %s", err.Error())
 				return
 			}
 			lfm.replaceActiveTracer(tracer)
 		}
 
 		lfm.isTracePublishingEnabled = false
-		defaultLogger.Info(context.Background(), "Tracing Publishing has been disabled")
+		logger.Info(context.Background(), "Tracing Publishing has been disabled")
 	}
 }
 
@@ -249,7 +249,7 @@
 
 	// Attempt Trace Agent Address first; will fallback to Loopback IP if it fails
 	jReporterConfig = jcfg.ReporterConfig{LocalAgentHostPort: traceAgentAddress, LogSpans: true}
-	jReporterCfgOption, err = jReporterConfig.NewReporter(lfm.componentName, jtracing.NewNullMetrics(), traceLogger{logger: defaultLogger})
+	jReporterCfgOption, err = jReporterConfig.NewReporter(lfm.componentName, jtracing.NewNullMetrics(), traceLogger{logger: logger.(*clogger)})
 
 	if err != nil {
 		if !fallbackToLoopbackAllowed {
@@ -299,8 +299,8 @@
 // Additionally, any tags present in Span are also extracted to use as log fields e.g. device-id.
 //
 // If no Span is found associated with context, blank slice is returned without any log fields
-func ExtractContextAttributes(ctx context.Context) []interface{} {
-	if !GetGlobalLFM().GetLogCorrelationStatus() {
+func (lfm *LogFeaturesManager) ExtractContextAttributes(ctx context.Context) []interface{} {
+	if !lfm.isLogCorrelationEnabled {
 		return make([]interface{}, 0)
 	}