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<Object, Object> 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<Object> keyValues) throws AuditLoggingException {
commit(Level.INFO, toMap(keyValues.toArray()));
}
private static void commit(Level level, Map<String, Object> message) throws AuditLoggingException {
try {
- AuditLoggingAPIClient client = instance().apiClient;
- if (client == null) {
+ AuditLoggingClient client = fromEnv();
+ if (client == null || client.apiClient == null) {
// No can do - at least log to file
LOGGER.warn("Audit logging server not configured - printing event to log");
LOGGER.info(message.toString());
} else {
+ AuditLoggingAPIClient apiClient = client.apiClient;
switch (level) {
case INFO:
- client.log(message);
+ apiClient.log(message);
break;
case ERROR:
- client.error(message);
+ apiClient.error(message);
break;
case TRACE:
- client.trace(message);
+ apiClient.trace(message);
break;
default:
break;