aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging/src/main/java/org/onap/policy/common/logging/nsa
diff options
context:
space:
mode:
Diffstat (limited to 'common-logging/src/main/java/org/onap/policy/common/logging/nsa')
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContext.java69
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContextFactory.java44
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/nsa/SharedLoggingContext.java24
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java45
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java80
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/nsa/package-info.java5
6 files changed, 124 insertions, 143 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContext.java b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContext.java
index 0786febd..a8dde087 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContext.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContext.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,41 +21,44 @@
package org.onap.policy.common.logging.nsa;
/**
- * An interface for providing data into the underlying logging context. Systems should use
- * this interface rather than log system specific MDC solutions in order to reduce dependencies.
+ * An interface for providing data into the underlying logging context. Systems should use this
+ * interface rather than log system specific MDC solutions in order to reduce dependencies.
*
- * A LoggingContext is specific to the calling thread.
+ * <p>A LoggingContext is specific to the calling thread.
*
*/
-public interface LoggingContext
-{
- /**
- * Put a key/value pair into the logging context, replacing an entry with the same key.
- * @param key
- * @param value
- */
- void put ( String key, String value );
+public interface LoggingContext {
+ /**
+ * Put a key/value pair into the logging context, replacing an entry with the same key.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ void put(String key, String value);
- /**
- * Put a key/value pair into the logging context, replacing an entry with the same key.
- * @param key
- * @param value
- */
- void put ( String key, long value );
+ /**
+ * Put a key/value pair into the logging context, replacing an entry with the same key.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ void put(String key, long value);
- /**
- * Get a string value, returning the default value if the value is missing.
- * @param key
- * @param defaultValue
- * @return a string value
- */
- String get ( String key, String defaultValue );
-
- /**
- * Get a long value, returning the default value if the value is missing or not a long.
- * @param key
- * @param defaultValue
- * @return a long value
- */
- long get ( String key, long defaultValue );
+ /**
+ * Get a string value, returning the default value if the value is missing.
+ *
+ * @param key the key
+ * @param defaultValue the default value
+ * @return a string value
+ */
+ String get(String key, String defaultValue);
+
+ /**
+ * Get a long value, returning the default value if the value is missing or not a long.
+ *
+ * @param key the key
+ * @param defaultValue the default value
+ * @return a long value
+ */
+ long get(String key, long defaultValue);
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContextFactory.java b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContextFactory.java
index b2ad76ca..85600671 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContextFactory.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/LoggingContextFactory.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,37 +20,31 @@
package org.onap.policy.common.logging.nsa;
-
import org.onap.policy.common.logging.nsa.impl.SharedContext;
import org.onap.policy.common.logging.nsa.impl.Slf4jLoggingContext;
/**
- * A factory for setting up a LoggingContext
+ * A factory for setting up a LoggingContext.
*
*/
-public class LoggingContextFactory
-{
- public static class Builder
- {
+public class LoggingContextFactory {
+ public static class Builder {
+
+ private LoggingContext baseContext = null;
+ private boolean forShared = false;
- private LoggingContext fBase = null;
- private boolean fShared = false;
-
- public Builder withBaseContext ( LoggingContext lc )
- {
- fBase = lc;
- return this;
- }
+ public Builder withBaseContext(LoggingContext lc) {
+ baseContext = lc;
+ return this;
+ }
- public Builder forSharing ()
- {
- fShared = true;
- return this;
- }
+ public Builder forSharing() {
+ forShared = true;
+ return this;
+ }
- public LoggingContext build ()
- {
- return fShared ? new SharedContext ( fBase ) : new Slf4jLoggingContext ( fBase );
- }
- }
+ public LoggingContext build() {
+ return forShared ? new SharedContext(baseContext) : new Slf4jLoggingContext(baseContext);
+ }
+ }
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/SharedLoggingContext.java b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/SharedLoggingContext.java
index af0cc393..1d844fa0 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/SharedLoggingContext.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/SharedLoggingContext.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,17 +21,17 @@
package org.onap.policy.common.logging.nsa;
/**
- * A logging context must be thread-specific. Contexts that implement SharedLoggingContext
- * are expected to be shared across threads, and they have to be able to populate another
- * logging context with their data.
+ * A logging context must be thread-specific. Contexts that implement SharedLoggingContext are
+ * expected to be shared across threads, and they have to be able to populate another logging
+ * context with their data.
*
*/
-public interface SharedLoggingContext extends LoggingContext
-{
- /**
- * Copy this context's data to the given context. This must work across threads so that
- * a base context can be shared in another thread.
- * @param lc
- */
- void transferTo ( SharedLoggingContext lc );
+public interface SharedLoggingContext extends LoggingContext {
+ /**
+ * Copy this context's data to the given context. This must work across threads so that a base
+ * context can be shared in another thread.
+ *
+ * @param lc the shared logging context
+ */
+ void transferTo(SharedLoggingContext lc);
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java
index 97f61699..e5f5e65b 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,32 +27,27 @@ import org.onap.policy.common.logging.nsa.LoggingContext;
import org.onap.policy.common.logging.nsa.SharedLoggingContext;
/**
- * A shared logging context for SLF4J
+ * A shared logging context for SLF4J.
*
*/
-public class SharedContext extends Slf4jLoggingContext implements SharedLoggingContext
-{
- private final HashMap<String,String> fMap;
-
- public SharedContext ( LoggingContext base )
- {
- super ( base );
- fMap = new HashMap<> ();
- }
+public class SharedContext extends Slf4jLoggingContext implements SharedLoggingContext {
+ private final HashMap<String, String> contextMap;
- @Override
- public void put ( String key, String value )
- {
- super.put ( key, value );
- fMap.put ( key, value );
- }
+ public SharedContext(LoggingContext base) {
+ super(base);
+ contextMap = new HashMap<>();
+ }
- @Override
- public void transferTo ( SharedLoggingContext lc )
- {
- for ( Entry<String,String> e : fMap.entrySet () )
- {
- lc.put ( e.getKey(), e.getValue() );
- }
- }
+ @Override
+ public void put(String key, String value) {
+ super.put(key, value);
+ contextMap.put(key, value);
+ }
+
+ @Override
+ public void transferTo(SharedLoggingContext lc) {
+ for (Entry<String, String> e : contextMap.entrySet()) {
+ lc.put(e.getKey(), e.getValue());
+ }
+ }
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java
index 628d4b9e..80bb2383 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,54 +20,42 @@
package org.onap.policy.common.logging.nsa.impl;
-import org.slf4j.MDC;
-
import org.onap.policy.common.logging.nsa.LoggingContext;
+import org.slf4j.MDC;
/**
- * A logging context for SLF4J
+ * A logging context for SLF4J.
*
*/
-public class Slf4jLoggingContext implements LoggingContext
-{
- public Slf4jLoggingContext ( LoggingContext base )
- {
- }
-
- @Override
- public void put ( String key, String value )
- {
- MDC.put ( key, value );
- }
-
- @Override
- public void put ( String key, long value )
- {
- put ( key, Long.toString(value));
- }
-
- @Override
- public String get ( String key, String defaultValue )
- {
- String result = MDC.get ( key );
- if ( result == null )
- {
- result = defaultValue;
- }
- return result;
- }
-
- @Override
- public long get ( String key, long defaultValue )
- {
- final String str = get ( key, Long.toString(defaultValue));
- try
- {
- return Long.parseLong ( str );
- }
- catch ( NumberFormatException x )
- {
- return defaultValue;
- }
- }
+public class Slf4jLoggingContext implements LoggingContext {
+ public Slf4jLoggingContext(LoggingContext base) {}
+
+ @Override
+ public void put(String key, String value) {
+ MDC.put(key, value);
+ }
+
+ @Override
+ public void put(String key, long value) {
+ put(key, Long.toString(value));
+ }
+
+ @Override
+ public String get(String key, String defaultValue) {
+ String result = MDC.get(key);
+ if (result == null) {
+ result = defaultValue;
+ }
+ return result;
+ }
+
+ @Override
+ public long get(String key, long defaultValue) {
+ final String str = get(key, Long.toString(defaultValue));
+ try {
+ return Long.parseLong(str);
+ } catch (NumberFormatException x) {
+ return defaultValue;
+ }
+ }
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/package-info.java b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/package-info.java
index 6f58bb0f..76554c49 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/package-info.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/package-info.java
@@ -19,9 +19,10 @@
*/
/**
- * This package provides a logging context infrastructure and a corresponding
- * implementation based on the SLF4J/Log4j "MDC" (Mapped Diagnostic Context) feature.
+ * This package provides a logging context infrastructure and a corresponding implementation based
+ * on the SLF4J/Log4j "MDC" (Mapped Diagnostic Context) feature.
*
*/
+
package org.onap.policy.common.logging.nsa;