Log all configuration(add/modify/delete) changes to a new log file audit.log
[controller.git] / opendaylight / northbound / commons / src / main / java / org / opendaylight / controller / northbound / commons / utils / NorthboundUtils.java
index f98189319becc8ccae7557a7028378f38843b72e..9f47e0c9718f542f49d6bea3079045c482359230 100644 (file)
@@ -13,6 +13,8 @@ import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
 import org.opendaylight.controller.usermanager.IUserManager;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
 import org.opendaylight.controller.usermanager.IUserManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class NorthboundUtils {
 
 
 public class NorthboundUtils {
 
@@ -37,6 +39,10 @@ public class NorthboundUtils {
         }
     };
 
         }
     };
 
+    private static final String AUDIT = "audit";
+
+    private static final Logger logger = LoggerFactory.getLogger(AUDIT);
+
     // Suppress default constructor for noninstantiability
     private NorthboundUtils() {
     }
     // Suppress default constructor for noninstantiability
     private NorthboundUtils() {
     }
@@ -114,4 +120,20 @@ public class NorthboundUtils {
         return true;
     }
 
         return true;
     }
 
+    public static void auditlog(String moduleName, String user, String action, String resource,
+            String containerName) {
+        String auditMsg = "";
+        String mode = "REST";
+        if (containerName != null) {
+            auditMsg = "Mode: " + mode + " User " + user + " "  + action + " " + moduleName + " " + resource + " in container "
+                    + containerName;
+        } else {
+            auditMsg = "Mode: " + mode + " User " + user + " "  + action + " " + moduleName + " " + resource;
+        }
+        logger.info(auditMsg);
+    }
+
+    public static void auditlog(String moduleName, String user, String action, String resource) {
+        auditlog(moduleName, user, action, resource, null);
+    }
 }
 }