Fix issues with PolicyLog

pull/136/head
prathabanKavin 2 years ago
parent 1b3a8d4245
commit fe4c6466b9

@ -94,9 +94,8 @@ public class PolicyLogContext extends LogContext {
return this;
}
public Throwable build() {
return new Throwable(this.build());
public PolicyLogContext build() {
return new PolicyLogContext(this);
}
}
}

@ -67,7 +67,6 @@ public final class MDCContextUtil {
public static void populatePolicyMDCContext(final PolicyLogContext mdcContext) {
if (mdcContext.getPolicyName() != null) {
MDC.put("PolicyName", mdcContext.getPolicyName());
System.out.println(mdcContext.getPolicyName());
}
if (mdcContext.getPayloadVersion() != null) {
MDC.put("PayloadVersion", mdcContext.getPayloadVersion());

@ -22,10 +22,7 @@ import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.PolicyLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraPolicyLoggerImpl;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraUserLoggerImpl;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.DynamicTaskContext;
@ -96,6 +93,7 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
public Policy addPolicy(Policy policy) throws PolicyManagementException {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
try {
PolicyManagementDAOFactory.beginTransaction();
if (policy.getProfile() != null && policy.getProfile().getProfileId() == 0) {
@ -177,6 +175,7 @@ public class PolicyManagerImpl implements PolicyManager {
} finally {
PolicyManagementDAOFactory.closeConnection();
}
log.info("Policy Created", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayloadVersion(policy.getPolicyPayloadVersion()).setTenantID(tenantId).setProfileID(String.valueOf(policy.getProfileId())).build());
return policy;
}
@ -324,7 +323,7 @@ public class PolicyManagerImpl implements PolicyManager {
} finally {
PolicyManagementDAOFactory.closeConnection();
}
log.info("Policy Update", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayloadVersion(policy.getPolicyPayloadVersion()).setTenantID(tenantId).setProfileID(String.valueOf(policy.getProfileId())).build());
log.info("Policy Updated", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayloadVersion(policy.getPolicyPayloadVersion()).setTenantID(tenantId).setProfileID(String.valueOf(policy.getProfileId())).build());
return policy;
}

Loading…
Cancel
Save