Add app id to app install logs

pull/136/head
prathabanKavin 2 years ago
parent b7b31c855c
commit 472d000c9e

@ -650,6 +650,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
boolean isOperationReExecutingDisabled)
throws ApplicationManagementException {
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
//Get app subscribing info of each device
SubscribingDeviceIdHolder subscribingDeviceIdHolder = getSubscribingDeviceIdHolder(devices,
applicationDTO.getApplicationReleaseDTOs().get(0).getId());
@ -700,14 +701,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
entry.getKey(), action, properties);
activityList.add(activity);
for (DeviceIdentifier identifier : deviceIdentifiers) {
log.info(String.format("Web app %s triggered", action), appInstallLogContextBuilder.setAppName(applicationDTO.getName()).setDevice(String.valueOf(identifier)).setUserName(username).setAction(action).build());
log.info(String.format("Web app %s triggered", action), appInstallLogContextBuilder.setAppId(String.valueOf(applicationDTO.getId())).setAppName(applicationDTO.getName()).setTenantId(tenantId).setDevice(String.valueOf(identifier)).setUserName(username).setAction(action).build());
}
}
} else {
Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action, properties);
activityList.add(activity);
for (DeviceIdentifier identifier : deviceIdentifiers) {
log.info(String.format("App %s triggered", action), appInstallLogContextBuilder.setAppName(applicationDTO.getName()).setDevice(String.valueOf(identifier)).setUserName(username).setAction(action).build());
log.info(String.format("App %s triggered", action), appInstallLogContextBuilder.setAppId(String.valueOf(applicationDTO.getId())).setAppName(applicationDTO.getName()).setTenantId(tenantId).setDevice(String.valueOf(identifier)).setUserName(username).setAction(action).build());
}
}

@ -21,22 +21,34 @@ package io.entgra.device.mgt.core.notification.logger;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
public class AppInstallLogContext extends LogContext {
private final String appId;
private final String appName;
private final String tenantId;
private final String device;
private final String userName;
private final String action;
private AppInstallLogContext(Builder builder) {
this.appId = builder.appId;
this.appName = builder.appName;
this.tenantId = builder.tenantId;
this.device = builder.device;
this.userName = builder.userName;
this.action = builder.action;
}
public String getAppId() {
return appId;
}
public String getAppName() {
return appName;
}
public String getTenantId() {
return tenantId;
}
public String getDevice() {
return device;
}
@ -50,7 +62,9 @@ public class AppInstallLogContext extends LogContext {
}
public static class Builder {
private String appId;
private String appName;
private String tenantId;
private String device;
private String userName;
private String action;
@ -67,6 +81,15 @@ public class AppInstallLogContext extends LogContext {
return this;
}
public String getAppId() {
return appId;
}
public Builder setAppId(String appId) {
this.appId = appId;
return this;
}
public String getAppName() {
return appName;
}
@ -76,6 +99,15 @@ public class AppInstallLogContext extends LogContext {
return this;
}
public String getTenantId() {
return tenantId;
}
public Builder setTenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
public String getDevice() {
return device;
}

@ -78,12 +78,18 @@ public final class MDCContextUtil {
}
public static void populateAppInstallMDCContext(final AppInstallLogContext mdcContext) {
if (mdcContext.getAppId() != null) {
MDC.put("AppId", mdcContext.getAppId());
}
if (mdcContext.getAppName() != null) {
MDC.put("AppName", mdcContext.getAppName());
}
if (mdcContext.getDevice() != null) {
MDC.put("Device", mdcContext.getDevice());
}
if (mdcContext.getTenantId() != null) {
MDC.put("TenantId", mdcContext.getTenantId());
}
if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName());
}

Loading…
Cancel
Save