Remove fixed "testlog" as client id and read from system property 64/1464/2
authorjsimomaa <jani.simomaa@gmail.com>
Thu, 15 Feb 2018 08:53:18 +0000 (10:53 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 15 Feb 2018 10:41:03 +0000 (12:41 +0200)
refs #7768

Change-Id: I673f29eccc06c8375811fe5da557d506737209c2

bundles/org.simantics.auditlogging/src/org/simantics/audit/client/AuditLoggingClient.java

index e9043187d76db1c28b5325292b4ce38a7848412c..769ebb0862f1abe7892eed45a1a59ae565e42b03 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 import org.simantics.audit.AuditLogging;
 import org.simantics.audit.AuditLogging.Level;
@@ -14,6 +15,7 @@ import org.slf4j.LoggerFactory;
 public class AuditLoggingClient {
 
     private static final String AUDIT_SERVER_ADDRESS = "org.simantics.audit.serverAddress";
+    private static final String AUDIT_CLIENT_ID = "org.simantics.audit.clientId";
     
     private static final Logger LOGGER = LoggerFactory.getLogger(AuditLoggingClient.class);
     
@@ -21,9 +23,8 @@ public class AuditLoggingClient {
 
     private AuditLoggingAPIClient apiClient;
 
-    private AuditLoggingClient(String serverAddress) throws AuditLoggingException {
-        // Read config from sysargs
-        apiClient = new AuditLoggingAPIClient("testlog", serverAddress);
+    private AuditLoggingClient(String clientId, String serverAddress) throws AuditLoggingException {
+        apiClient = new AuditLoggingAPIClient(clientId, serverAddress);
     }
 
     private static AuditLoggingClient fromEnv() throws AuditLoggingException {
@@ -36,8 +37,11 @@ public class AuditLoggingClient {
             synchronized (AuditLoggingClient.class) {
                 if (INSTANCE == null) {
                     String serverAddress = (String) properties.get(AUDIT_SERVER_ADDRESS);
+                    String clientId = (String) properties.get(AUDIT_CLIENT_ID);
+                    if (clientId == null || clientId.isEmpty())
+                        clientId = UUID.randomUUID().toString();
                     if (serverAddress != null && !serverAddress.isEmpty()) {
-                        INSTANCE = new AuditLoggingClient(serverAddress);
+                        INSTANCE = new AuditLoggingClient(clientId, serverAddress);
                     } else {
                         LOGGER.warn("No {} system property defined so client not configured", AUDIT_SERVER_ADDRESS);
                     }