Add payload to policy logs

pull/136/head
prathabanKavin 1 year ago
parent d28008f806
commit b7b31c855c

@ -22,75 +22,75 @@ import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
public class PolicyLogContext extends LogContext {
private final String policyName;
private final String payloadVersion;
private final String payload;
private final String tenantID;
private final String profileID;
private final String tenantDomain;
private PolicyLogContext(Builder builder) {
this.policyName = builder.policyName;
this.payloadVersion = builder.payloadVersion;
this.payload = builder.payload;
this.tenantID = builder.tenantID;
this.profileID = builder.profileID;
this.tenantDomain = builder.tenantDomain;
}
public String getPolicyName() {
return policyName;
}
public String getPayloadVersion() {
return payloadVersion;
public String getPayload() {
return payload;
}
public String getTenantID() {
return tenantID;
}
public String getProfileID() {
return profileID;
public String getTenantDomain() {
return tenantDomain;
}
public static class Builder {
private String policyName;
private String payloadVersion;
private String payload;
private String tenantID;
private String profileID;
private String tenantDomain;
public Builder() {
}
public String getTenantID() {
return tenantID;
public String getPolicyName() {
return policyName;
}
public Builder setTenantID(String tenantID) {
this.tenantID = tenantID;
public Builder setPolicyName(String policyName) {
this.policyName = policyName;
return this;
}
public String getProfileID() {
return profileID;
public String getPayload() {
return payload;
}
public Builder setProfileID(String profileID) {
this.profileID = profileID;
public Builder setPayload(String payload) {
this.payload = payload;
return this;
}
public String getPolicyName() {
return policyName;
public String getTenantID() {
return tenantID;
}
public Builder setPolicyName(String policyName) {
this.policyName = policyName;
public Builder setTenantID(String tenantID) {
this.tenantID = tenantID;
return this;
}
public String getPayloadVersion() {
return payloadVersion;
public String getTenantDomain() {
return tenantDomain;
}
public Builder setPayloadVersion(String payloadVersion) {
this.payloadVersion = payloadVersion;
public Builder setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
return this;
}

@ -66,11 +66,11 @@ public final class MDCContextUtil {
if (mdcContext.getPolicyName() != null) {
MDC.put("PolicyName", mdcContext.getPolicyName());
}
if (mdcContext.getPayloadVersion() != null) {
MDC.put("PayloadVersion", mdcContext.getPayloadVersion());
if (mdcContext.getPayload() != null) {
MDC.put("Payload", mdcContext.getPayload());
}
if (mdcContext.getProfileID() != null) {
MDC.put("ProfileId", mdcContext.getProfileID());
if (mdcContext.getTenantDomain() != null) {
MDC.put("TenantDomain", mdcContext.getTenantDomain());
}
if (mdcContext.getTenantID() != null) {
MDC.put("TenantId", mdcContext.getTenantID());

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.policy.mgt.core.mgt.impl;
import com.google.gson.Gson;
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;
@ -94,6 +95,7 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
public Policy addPolicy(Policy policy) throws PolicyManagementException {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
try {
PolicyManagementDAOFactory.beginTransaction();
if (policy.getProfile() != null && policy.getProfile().getProfileId() == 0) {
@ -175,13 +177,15 @@ 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());
String stringPayload = new Gson().toJson(policy);
log.info("Policy Created", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setTenantID(tenantId).setTenantDomain(tenantDomain).build());
return policy;
}
@Override
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
try {
// Previous policy needs to be obtained before beginning the transaction
Policy previousPolicy = this.getPolicy(policy.getId());
@ -323,7 +327,8 @@ public class PolicyManagerImpl implements PolicyManager {
} finally {
PolicyManagementDAOFactory.closeConnection();
}
log.info("Policy Updated", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayloadVersion(policy.getPolicyPayloadVersion()).setTenantID(tenantId).setProfileID(String.valueOf(policy.getProfileId())).build());
String stringPayload = new Gson().toJson(policy);
log.info("Policy Updated", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setTenantID(tenantId).setTenantDomain(tenantDomain).build());
return policy;
}

Loading…
Cancel
Save