X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.auditlogging%2Fsrc%2Forg%2Fsimantics%2Faudit%2Fclient%2FAuditLoggingClient.java;h=63045fdcfe7a3f598751a7207b2d2d12c2a01950;hp=e31a6ab214531a967fee0a06d3d41cd12fb7e573;hb=87590104a1ecf5e0b2edb82c0b49601cc8f97488;hpb=da4210cb095e4acd25ddba55a86aa6fe0b18301d diff --git a/bundles/org.simantics.auditlogging/src/org/simantics/audit/client/AuditLoggingClient.java b/bundles/org.simantics.auditlogging/src/org/simantics/audit/client/AuditLoggingClient.java index e31a6ab21..63045fdcf 100644 --- a/bundles/org.simantics.auditlogging/src/org/simantics/audit/client/AuditLoggingClient.java +++ b/bundles/org.simantics.auditlogging/src/org/simantics/audit/client/AuditLoggingClient.java @@ -21,29 +21,36 @@ public class AuditLoggingClient { private AuditLoggingAPIClient apiClient; - private AuditLoggingClient() throws AuditLoggingException { + private AuditLoggingClient(String serverAddress) throws AuditLoggingException { // Read config from sysargs - System.out.println("asd"); - String serverAddress = System.getProperty(AUDIT_SERVER_ADDRESS); - if (serverAddress != null && !serverAddress.isEmpty()) { - apiClient = new AuditLoggingAPIClient("testlog", serverAddress); - - } else { - LOGGER.warn("No {} system property defined so client not configured", AUDIT_SERVER_ADDRESS); - } + apiClient = new AuditLoggingAPIClient("testlog", serverAddress); + } + + private static AuditLoggingClient fromEnv() throws AuditLoggingException { + return fromProps(System.getProperties()); } - private static AuditLoggingClient instance() throws AuditLoggingException { + + public static AuditLoggingClient fromProps(Map properties) throws AuditLoggingException { if (INSTANCE == null) { synchronized (AuditLoggingClient.class) { if (INSTANCE == null) { - INSTANCE = new AuditLoggingClient(); + String serverAddress = (String) properties.get(AUDIT_SERVER_ADDRESS); + if (serverAddress != null && !serverAddress.isEmpty()) { + INSTANCE = new AuditLoggingClient(serverAddress); + } else { + LOGGER.warn("No {} system property defined so client not configured", AUDIT_SERVER_ADDRESS); + } } } } return INSTANCE; } + public static String getUUID() throws AuditLoggingException { + return fromEnv().apiClient.getUuid(); + } + public static void sendLog(List keyValues) throws AuditLoggingException { commit(Level.INFO, toMap(keyValues.toArray())); } @@ -84,7 +91,7 @@ public class AuditLoggingClient { private static void commit(Level level, Map message) throws AuditLoggingException { try { - AuditLoggingAPIClient client = instance().apiClient; + AuditLoggingAPIClient client = fromEnv().apiClient; if (client == null) { // No can do - at least log to file LOGGER.warn("Audit logging server not configured - printing event to log");