summaryrefslogtreecommitdiffstats
path: root/common-logging/src/main
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-06-09 09:43:41 -0500
committerJorge Hernandez <jh1730@att.com>2017-06-09 09:55:34 -0500
commitbd4272c9ed550bd68ccaa3a850f1295bca583ed5 (patch)
tree8f3e81112f9fde8db37fdfdf31c472eaec88d074 /common-logging/src/main
parentb429e762a77e18a78f3f4862996d3885e5715a04 (diff)
[POLICY-8 POLICY-9] cleaning logging issues
A bit of a messy area to clean up without redoing. This is an attempt to clean warnings and being a little more friendly to the callers. policy-9: sonar blocker with dereferencing null pointers in flex logger. policy-8: clean up other warnings from eclipse and sonar. Change-Id: I7aa175673c22490909ae6b40a911a03931961ae3 Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'common-logging/src/main')
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java42
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/FlexLogger.java92
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger.java5
3 files changed, 51 insertions, 88 deletions
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
index ed03f9a9..8cc73743 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
@@ -52,9 +52,6 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class PolicyLogger {
- private static EELFLogger applicationLogger = EELFManager.getInstance()
- .getApplicationLogger();
-
private static EELFLogger errorLogger = EELFManager.getInstance()
.getErrorLogger();
@@ -1147,27 +1144,34 @@ public class PolicyLogger {
/**
* Loads all the attributes from policyLogger.properties file
*/
- public static LoggerType init(Properties properties) throws Exception {
- // read in properties
- Properties logger_properties = properties;
+ public static LoggerType init(Properties properties) {
+
+ Properties loggerProperties;
+ if (properties != null) {
+ loggerProperties = properties;
+ } else {
+ System.err.println("PolicyLogger cannot find its configuration - continue");
+ loggerProperties = new Properties();
+ }
+
LoggerType logger_type = LoggerType.EELF;
// fetch and verify definitions of some properties
try{
- int timerDelayTime = Integer.parseInt(logger_properties.getProperty("timer.delay.time"));
- int checkInterval = Integer.parseInt(logger_properties.getProperty("check.interval"));
- int expiredDate = Integer.parseInt(logger_properties.getProperty("event.expired.time"));
- int concurrentHashMapLimit = Integer.parseInt(logger_properties.getProperty("concurrentHashMap.limit"));
- int stopCheckPoint = Integer.parseInt(logger_properties.getProperty("stop.check.point"));
- String loggerType = logger_properties.getProperty("logger.type");
+ int timerDelayTime = Integer.parseInt(loggerProperties.getProperty("timer.delay.time", ""+1000));
+ int checkInterval = Integer.parseInt(loggerProperties.getProperty("check.interval", ""+30000));
+ int expiredDate = Integer.parseInt(loggerProperties.getProperty("event.expired.time",""+86400));
+ int concurrentHashMapLimit = Integer.parseInt(loggerProperties.getProperty("concurrentHashMap.limit", ""+5000));
+ int stopCheckPoint = Integer.parseInt(loggerProperties.getProperty("stop.check.point",""+2500));
+ String loggerType = loggerProperties.getProperty("logger.type",logger_type.toString());
- String debugLevel = logger_properties.getProperty("debugLogger.level");
- String metricsLevel = logger_properties.getProperty("metricsLogger.level");
- String auditLevel = logger_properties.getProperty("error.level");
- String errorLevel = logger_properties.getProperty("audit.level");
- component = logger_properties.getProperty("policy.component");
- String overrideLogbackLevel = logger_properties.getProperty("override.logback.level.setup");
+ String debugLevel = loggerProperties.getProperty("debugLogger.level","INFO");
+ String metricsLevel = loggerProperties.getProperty("metricsLogger.level","ON");
+ String auditLevel = loggerProperties.getProperty("error.level","ON");
+ String errorLevel = loggerProperties.getProperty("audit.level","ON");
+ component = loggerProperties.getProperty("policy.component","DROOLS");
+ String overrideLogbackLevel = loggerProperties.getProperty("override.logback.level.setup");
if(overrideLogbackLevel != null && !overrideLogbackLevel.isEmpty()) {
if(overrideLogbackLevel.equalsIgnoreCase("TRUE")){
@@ -1212,7 +1216,7 @@ public class PolicyLogger {
}
isEventTrackerRunning = false;
- debugLogger.info("timerDelayTiime value: " + timerDelayTime);
+ debugLogger.info("timerDelayTime value: " + timerDelayTime);
debugLogger.info("checkInterval value: " + checkInterval);
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/FlexLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/FlexLogger.java
index 4748e34f..3db40f1e 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/FlexLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/FlexLogger.java
@@ -29,7 +29,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.openecomp.policy.common.logging.eelf.PolicyLogger;
-import org.openecomp.policy.common.logging.flexlogger.PropertyUtil;
import org.openecomp.policy.common.logging.flexlogger.PropertyUtil.Listener;
/**
@@ -40,7 +39,6 @@ import org.openecomp.policy.common.logging.flexlogger.PropertyUtil.Listener;
public class FlexLogger extends SecurityManager{
private static LoggerType loggerType = LoggerType.EELF;
- private static boolean initLoggerCalled = false;
private static ConcurrentHashMap<String, Logger4J> logger4JMap = new ConcurrentHashMap<String, Logger4J>();
private static ConcurrentHashMap<String, EelfLogger> eelfLoggerMap = new ConcurrentHashMap<String, EelfLogger>();
private static ConcurrentHashMap<String, SystemOutLogger> systemOutMap = new ConcurrentHashMap<String, SystemOutLogger>();
@@ -53,11 +51,7 @@ public class FlexLogger extends SecurityManager{
* Returns an instance of Logger
* @param clazz
*/
- static public Logger getLogger(Class clazz) {
-
- if (initLoggerCalled == false) {
- loggerType = initlogger();
- }
+ static public Logger getLogger(Class<?> clazz) {
Logger logger = null;
System.out.println("FlexLogger:getLogger : loggerType = " + loggerType);
switch (loggerType) {
@@ -81,11 +75,7 @@ public class FlexLogger extends SecurityManager{
* Returns an instance of Logger
* @param s
*/
- static public Logger getLogger(String s) {
-
- if (initLoggerCalled == false) {
- loggerType = initlogger();
- }
+ static public Logger getLogger(String s) {
Logger logger = null;
System.out.println("FlexLogger:getLogger : loggerType = " + loggerType);
switch (loggerType) {
@@ -110,11 +100,7 @@ public class FlexLogger extends SecurityManager{
* @param clazz
* @param isNewTransaction
*/
- static public Logger getLogger(Class clazz, boolean isNewTransaction) {
-
- if (initLoggerCalled == false) {
- loggerType = initlogger();
- }
+ static public Logger getLogger(Class<?> clazz, boolean isNewTransaction) {
Logger logger = null;
System.out.println("FlexLogger:getLogger : loggerType = " + loggerType);
switch (loggerType) {
@@ -140,10 +126,6 @@ public class FlexLogger extends SecurityManager{
* @param isNewTransaction
*/
static public Logger getLogger(String s, boolean isNewTransaction) {
-
- if (initLoggerCalled == false) {
- loggerType = initlogger();
- }
Logger logger = null;
System.out.println("FlexLogger:getLogger : loggerType = " + loggerType);
switch (loggerType) {
@@ -174,7 +156,7 @@ public class FlexLogger extends SecurityManager{
* Returns an instance of Logger4J
* @param clazz
*/
- private static Logger4J getLog4JLogger(Class clazz){
+ private static Logger4J getLog4JLogger(Class<?> clazz){
String className = new FlexLogger().getClassName();
if(!logger4JMap.containsKey(className)){
@@ -206,7 +188,7 @@ public class FlexLogger extends SecurityManager{
* @param clazz
* @param isNewTransaction
*/
- private static EelfLogger getEelfLogger(Class clazz, boolean isNewTransaction){
+ private static EelfLogger getEelfLogger(Class<?> clazz, boolean isNewTransaction){
String className = "";
EelfLogger logger = null;
@@ -239,7 +221,7 @@ public class FlexLogger extends SecurityManager{
* Returns an instance of SystemOutLogger
* @param clazz
*/
- private static SystemOutLogger getSystemOutLogger(Class clazz){
+ private static SystemOutLogger getSystemOutLogger(Class<?> clazz){
String className = new FlexLogger().getClassName();
@@ -257,59 +239,41 @@ public class FlexLogger extends SecurityManager{
private static LoggerType initlogger() {
LoggerType loggerType = LoggerType.EELF;
String overrideLogbackLevel = "FALSE";
- String logger_Type = "";
+ String loggerTypeString = "";
+ Properties properties = null;
+
try {
-
- Properties properties = null;
- properties = PropertyUtil.getProperties(
- "config/policyLogger.properties");
+ properties = PropertyUtil.getProperties("config/policyLogger.properties");
System.out.println("FlexLogger:properties => " + properties);
if(properties != null) {
overrideLogbackLevel = properties.getProperty("override.logback.level.setup");
System.out.println("FlexLogger:overrideLogbackLevel => " + overrideLogbackLevel);
- logger_Type = properties.getProperty("logger.type");
- if (logger_Type != null){
-
- if (logger_Type.equalsIgnoreCase("EELF")){
-
+ loggerTypeString = properties.getProperty("logger.type");
+ if (loggerTypeString != null){
+ if (loggerTypeString.equalsIgnoreCase("EELF")){
loggerType = LoggerType.EELF;
-
- }else if (logger_Type.equalsIgnoreCase("LOG4J")){
-
- loggerType = LoggerType.LOG4J;
-
- }else if (logger_Type.equalsIgnoreCase("SYSTEMOUT")){
-
- loggerType = LoggerType.SYSTEMOUT;
-
+ if (overrideLogbackLevel != null &&
+ overrideLogbackLevel.equalsIgnoreCase("TRUE")) {
+ System.out.println("FlexLogger: start listener.");
+ properties = PropertyUtil.getProperties
+ ("config/policyLogger.properties",
+ new PropertiesCallBack("FlexLogger-CallBack"));
+ }
+ }else if (loggerTypeString.equalsIgnoreCase("LOG4J")){
+ loggerType = LoggerType.LOG4J;
+ }else if (loggerTypeString.equalsIgnoreCase("SYSTEMOUT")){
+ loggerType = LoggerType.SYSTEMOUT;
}
- System.out.println("FlexLogger.logger_Type value: " + logger_Type);
+ System.out.println("FlexLogger.logger_Type value: " + loggerTypeString);
}
}
- //--- only use reload policyLogger.properties file listener for logger type EEFL and overrideLogbackLevel flag is true
- if(logger_Type.equalsIgnoreCase("EELF") && overrideLogbackLevel != null && overrideLogbackLevel.equalsIgnoreCase("TRUE")){
-
- System.out.println("FlexLogger: start listener.");
- properties = PropertyUtil.getProperties(
- "config/policyLogger.properties", new PropertiesCallBack(
- "FlexLogger-CallBack"));
- }else{
- System.out.println("FlexLogger: no listener needed.");
- }
-
- try {
-
- loggerType = PolicyLogger.init(properties);
- initLoggerCalled = true;
-
- } catch (Exception e) {
- System.out.println("initlogger" + e);
- }
-
} catch (IOException e1) {
System.out.println("initlogger" + e1);
+ } finally {
+ // OK to pass no properties (null)
+ loggerType = PolicyLogger.init(properties);
}
return loggerType;
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger.java
index ae210081..8cfee16c 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger.java
@@ -20,13 +20,8 @@
package org.openecomp.policy.common.logging.flexlogger;
-import static org.openecomp.policy.common.logging.eelf.Configuration.STATUS_CODE;
-
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
import java.util.UUID;
-import org.slf4j.MDC;
-
import org.openecomp.policy.common.logging.eelf.MessageCodes;
/**