Add custom loggers (#136)

* Fixes https://roadmap.entgra.net/issues/10117

* Added custom logs for below cases:
1. Device connectivity events
2. Policy payload change events
3. Device enrollment history events
4. App install events

**1. Device connectivity logs** - logs for newly added operations and calls for pending operations

Pattern :
{DateTime} {LogLevel} - {ActionTag} {OperationCode} {DeviceId} {DeviceType} {TenantDomain} {TenantId} {UserName} - log_message

```
[2023-06-15 00:12:09,093]  INFO - [ADD_OPERATION] [DEVICE_LOCATION] [97] [android] [carbon.super] [-1234] [admin]- Operation added
[2023-06-15 00:12:10,344]  INFO - [PENDING_OPERATION] [DEVICE_LOCATION] [675c60a9d31492d6] [android] [carbon.super] [-1234] [admin]- Device Connected
[2023-06-15 00:13:49,755]  INFO - [ADD_OPERATION] [DEVICE_LOCK] [97] [android] [carbon.super] [-1234] [admin]- Operation added
[2023-06-15 00:13:56,513]  INFO - [ADD_OPERATION] [DEVICE_MUTE] [97] [android] [carbon.super] [-1234] [admin]- Operation added
[2023-06-15 00:14:23,839]  INFO - [PENDING_OPERATION] [DEVICE_MUTE]
[2023-06-15 00:15:12,549]  INFO - [ADD_OPERATION] [INSTALL_APPLICATION] [97] [android] [carbon.super] [-1234] [admin]- Operation added
[2023-06-15 00:15:29,703]  INFO - [PENDING_OPERATION] [INSTALL_APPLICATION] [675c60a9d31492d6] [android] [carbon.super] [-1234] [admin]- Device Connected
```
**2. Policy payload change events** - logs for creating policy, updating policy, deleting policy, change policy priorities and apply changes to device logs

Pattern :
{DateTime} {LogLevel} - {ActionTag} {PolicyName} {TenantDomain} {TenantId} {Payload} {UserName} - log_message

```
[2023-06-15 00:15:53,264]  INFO - [UPDATE_POLICY] [passcodeios] [carbon.super] [-1234] [{"policyPayloadVersion":"2.0","id":33,"priorityId":1,"profile":{"profileId":33,"profileName":"passcodeios","tenantId":0,"deviceType":"ios","updatedDate":"Jun 15, 2023 12:15:53 AM","profileFeaturesList":[{"id":33,"featureCode":"PASSCODE_POLICY","profileId":0,"deviceType":"ios","content":"{\"forcePIN\":true,\"allowSimple\":true,\"requireAlphanumeric\":true,\"minLength\":7.0,\"minComplexChars\":4.0,\"pinHistory\":\"\"}","correctiveActions":[]}]},"policyName":"passcodeios","generic":false,"roles":["ANY"],"devices":[],"users":[],"active":false,"updated":false,"description":"test","compliance":"enforce","tenantId":-1234,"profileId":33,"policyType":"GENERAL"}] [admin] - Policy updated
[2023-06-15 00:34:38,980]  INFO - [ADD_POLICY] [application management policy] [carbon.super] [-1234] [{"policyPayloadVersion":"2.0","id":65,"priorityId":0,"profile":{"profileId":65,"profileName":"application management policy","tenantId":0,"deviceType":"windows","createdDate":"Jun 15, 2023 12:34:38 AM","updatedDate":"Jun 15, 2023 12:34:38 AM","profileFeaturesList":[{"id":65,"featureCode":"ALLOW_ALL_TRUSTED_APPS","profileId":0,"deviceType":"windows","content":"{\"enabled\":true}","correctiveActions":[]},{"id":73,"featureCode":"RESTRICT_APP_TO_SYSTEM_VOLUME","profileId":0,"deviceType":"windows","content":"{\"enabled\":false}","correctiveActions":[]}]},"policyName":"application management policy","generic":false,"roles":["ANY"],"devices":[],"users":[],"active":false,"updated":false,"description":"test","compliance":"enforce","tenantId":-1234,"profileId":0,"policyType":"GENERAL"}] [admin] - Policy created
[2023-06-15 00:35:05,420]  INFO - [DELETE_POLICY] [passcodeios] [carbon.super] [-1234] [{"policyPayloadVersion":"2.0","id":33,"priorityId":1,"profile":{"profileId":33,"profileName":"passcodeios","tenantId":-1234,"deviceType":"ios","createdDate":"Jun 13, 2023 10:24:30 PM","updatedDate":"Jun 15, 2023 12:15:53 AM","profileFeaturesList":[{"id":33,"featureCode":"PASSCODE_POLICY","profileId":33,"deviceType":"ios","content":"{\"forcePIN\":true,\"allowSimple\":true,\"requireAlphanumeric\":true,\"minLength\":7.0,\"minComplexChars\":4.0,\"pinHistory\":\"\"}","correctiveActions":[]}]},"policyName":"passcodeios","generic":false,"roles":["ANY"],"devices":[],"users":[],"active":false,"updated":true,"description":"test","compliance":"enforce","policyCriterias":[],"tenantId":-1234,"profileId":33,"deviceGroups":[],"policyType":"GENERAL"}] [admin] - Policy deleted
[2023-06-15 00:35:12,768]  INFO - [UPDATE_POLICY_PRIORITIES] [] [carbon.super] [-1234] [[{"id":65,"priorityId":1,"generic":false,"active":false,"updated":false,"tenantId":0,"profileId":0},{"id":34,"priorityId":2,"generic":false,"active":false,"updated":false,"tenantId":0,"profileId":0}]] [admin] - Policy priorities updated
[2023-06-15 00:35:25,395]  INFO - [PUBLISH_CHANGES] [] [carbon.super] [-1234] [] [admin] - Apply changes to device
```
**3. Device enrollment history events** - logs for device enrollment and dis-enrollment

Pattern :
{DateTime} {LogLevel} - {DeviceId} {DeviceType} {Owner} {Ownership} {TenantId} {TenantDomain} {UserName} - log_message

```
[2023-06-15 00:12:09,078]  INFO - [97] [android] [admin] [BYOD] [-1234] [carbon.super] [admin] - Device enrolled successfully
[2023-06-15 00:47:36,278]  INFO - [97] [android] [admin] [BYOD] [-1234] [carbon.super] [admin] - Device disenrolled successfully
```

**4. App install events** - logs for app installation and uninstallation

Pattern :
{DateTime} {LogLevel} - {AppId} {AppName} {AppType} {SubType} {Action} {Device} {TenantId} {TenantDomain} {UserName} - log_message

```
[2023-06-15 00:15:12,550]  INFO - [1] [Calculator] [PUBLIC] [DEVICE] [install] [deviceId {id='675c60a9d31492d6', type='android'}] [-1234] [carbon.super] [admin] - App install triggered
[2023-06-15 00:46:24,454]  INFO - [2] [Sololearn] [ENTERPRISE] [DEVICE] [install] [deviceId {id='675c60a9d31492d6', type='android'}] [-1234] [carbon.super] [admin] - App install triggered
[2023-06-15 00:46:40,498]  INFO - [3] [Engineering] [WEB_CLIP] [DEVICE] [install] [deviceId {id='675c60a9d31492d6', type='android'}] [-1234] [carbon.super] [admin] - Web app install triggered
```

* proprietary/product-uem#6

Co-authored-by: prathabanKavin <kavinprathaban025@gmail.com>
Co-authored-by: Pahansith Gunathilake <pahansith@entgra.io>
Reviewed-on: community/device-mgt-core#136
Co-authored-by: Kavin Prathaban <kavin@entgra.io>
Co-committed-by: Kavin Prathaban <kavin@entgra.io>
remotes/1725563413541109883/master
Kavin Prathaban 2 years ago committed by pasindu
parent 74e06047f1
commit 7ad3a0e21b

@ -19,6 +19,10 @@
package io.entgra.device.mgt.core.application.mgt.core.impl;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraAppInstallLoggerImpl;
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
import io.entgra.device.mgt.core.application.mgt.common.*;
@ -87,8 +91,8 @@ import java.util.stream.Collectors;
* This is the default implementation for the Subscription Manager.
*/
public class SubscriptionManagerImpl implements SubscriptionManager {
private static final Log log = LogFactory.getLog(SubscriptionManagerImpl.class);
AppInstallLogContext.Builder appInstallLogContextBuilder = new AppInstallLogContext.Builder();
private static final EntgraLogger log = new EntgraAppInstallLoggerImpl(SubscriptionManagerImpl.class);
private SubscriptionDAO subscriptionDAO;
private ApplicationDAO applicationDAO;
private LifecycleStateManager lifecycleStateManager;
@ -620,7 +624,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
Properties properties,
boolean isOperationReExecutingDisabled)
throws ApplicationManagementException {
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
//Get app subscribing info of each device
SubscribingDeviceIdHolder subscribingDeviceIdHolder = getSubscribingDeviceIdHolder(devices,
applicationDTO.getApplicationReleaseDTOs().get(0).getId());
@ -670,10 +676,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
Activity activity = addAppOperationOnDevices(applicationDTO, new ArrayList<>(entry.getValue()),
entry.getKey(), action, properties);
activityList.add(activity);
for (DeviceIdentifier identifier : deviceIdentifiers) {
log.info(String.format("Web app %s triggered", action), appInstallLogContextBuilder.setAppId(String.valueOf(applicationDTO.getId())).setAppName(applicationDTO.getName()).setAppType(applicationDTO.getType()).setSubType(subType).setTenantId(tenantId).setTenantDomain(tenantDomain).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.setAppId(String.valueOf(applicationDTO.getId())).setAppName(applicationDTO.getName()).setAppType(applicationDTO.getType()).setSubType(subType).setTenantId(tenantId).setTenantDomain(tenantDomain).setDevice(String.valueOf(identifier)).setUserName(username).setAction(action).build());
}
}
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();

@ -19,6 +19,23 @@
package io.entgra.device.mgt.core.device.mgt.core.operation.mgt;
import io.entgra.device.mgt.core.device.mgt.common.*;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.DeviceConnectivityLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraDeviceConnectivityLoggerImpl;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraPolicyLoggerImpl;
import org.apache.commons.lang.StringUtils;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.ActivityPaginationRequest;
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;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.MonitoringOperation;
import io.entgra.device.mgt.core.device.mgt.common.OperationMonitoringTaskConfig;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.InvalidDeviceException;
@ -68,7 +85,8 @@ import java.util.concurrent.ThreadPoolExecutor;
*/
public class OperationManagerImpl implements OperationManager {
private static final Log log = LogFactory.getLog(OperationManagerImpl.class);
DeviceConnectivityLogContext.Builder deviceConnectivityLogContextBuilder = new DeviceConnectivityLogContext.Builder();
private static final EntgraLogger log = new EntgraDeviceConnectivityLoggerImpl(OperationManagerImpl.class);
private static final int CACHE_VALIDITY_PERIOD = 5 * 60 * 1000;
private static final String NOTIFIER_TYPE_LOCAL = "LOCAL";
private static final String SYSTEM = "system";
@ -151,6 +169,8 @@ public class OperationManagerImpl implements OperationManager {
}
}
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
if (!validDeviceIds.isEmpty()) {
@ -227,6 +247,10 @@ public class OperationManagerImpl implements OperationManager {
activity.setActivityStatus(
this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
}
for (DeviceIdentifier deviceId : authorizedDeviceIds) {
device = getDevice(deviceId);
log.info("Operation added", deviceConnectivityLogContextBuilder.setDeviceId(String.valueOf(device.getId())).setDeviceType(deviceType).setActionTag("ADD_OPERATION").setTenantDomain(tenantDomain).setTenantId(tenantId).setUserName(initiatedBy).setOperationCode(operationCode).build());
}
return activity;
} catch (OperationManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction();
@ -673,7 +697,9 @@ public class OperationManagerImpl implements OperationManager {
if (log.isDebugEnabled()) {
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for the given device Identifier:" +
@ -686,16 +712,18 @@ public class OperationManagerImpl implements OperationManager {
case INACTIVE:
case UNREACHABLE:
this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE);
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceCacheManagerImpl.getInstance().removeDeviceFromCache(deviceId, tenantId);
break;
}
log.info("Device Connected", deviceConnectivityLogContextBuilder.setDeviceId(deviceId.getId()).setDeviceType(deviceId.getType()).setActionTag("PENDING_OPERATION").setTenantDomain(tenantDomain).setTenantId(String.valueOf(tenantId)).setUserName(userName).build());
return getOperations(deviceId, Operation.Status.PENDING, enrolmentId);
}
@Override
public List<? extends Operation> getPendingOperations(Device device) throws OperationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo();
if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for the given device Identifier:" +
@ -713,10 +741,10 @@ public class OperationManagerImpl implements OperationManager {
this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE);
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
device.setEnrolmentInfo(enrolmentInfo);
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceCacheManagerImpl.getInstance().addDeviceToCache(deviceIdentifier, device, tenantId);
break;
}
log.info("Device Connected", deviceConnectivityLogContextBuilder.setDeviceId(device.getDeviceIdentifier()).setDeviceType(device.getType()).setActionTag("PENDING_OPERATION").setTenantDomain(tenantDomain).setTenantId(String.valueOf(tenantId)).setUserName(userName).build());
return getOperations(deviceIdentifier, Operation.Status.PENDING, enrolmentId);
}

@ -21,6 +21,30 @@ package io.entgra.device.mgt.core.device.mgt.core.service;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.DeviceEnrolmentLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraDeviceEnrolmentLoggerImpl;
import org.apache.commons.collections.map.SingletonMap;
import org.apache.commons.lang.StringUtils;
import io.entgra.device.mgt.core.device.mgt.common.ActivityPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.Billing;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceEnrollmentInfoNotification;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.DeviceManager;
import io.entgra.device.mgt.core.device.mgt.common.DeviceNotification;
import io.entgra.device.mgt.core.device.mgt.common.DevicePropertyNotification;
import io.entgra.device.mgt.core.device.mgt.common.DeviceTransferRequest;
import io.entgra.device.mgt.core.device.mgt.common.DynamicTaskContext;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.FeatureManager;
import io.entgra.device.mgt.core.device.mgt.common.InitialOperationConfig;
import io.entgra.device.mgt.core.device.mgt.common.MonitoringOperation;
import io.entgra.device.mgt.core.device.mgt.common.OperationMonitoringTaskConfig;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.common.StartupOperationConfig;
import io.entgra.device.mgt.core.device.mgt.common.BillingResponse;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.*;
@ -117,7 +141,9 @@ import java.util.stream.Collectors;
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
PluginInitializationListener {
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
DeviceEnrolmentLogContext.Builder deviceEnrolmentLogContextBuilder = new DeviceEnrolmentLogContext.Builder();
private static final EntgraLogger log = new EntgraDeviceEnrolmentLoggerImpl(DeviceManagementProviderServiceImpl.class);
private static final String OPERATION_RESPONSE_EVENT_STREAM_DEFINITION = "org.wso2.iot.OperationResponseStream";
private final DeviceManagementPluginRepository pluginRepository;
@ -205,6 +231,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
return false;
}
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
EnrollmentConfiguration enrollmentConfiguration = DeviceManagerUtil.getEnrollmentConfigurationEntry();
String deviceSerialNumber = null;
if (enrollmentConfiguration != null) {
@ -291,6 +319,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
device.getType() + " upon the user '" + device.getEnrolmentInfo().getOwner() +
"'");
}
log.info("Device enrolled successfully", deviceEnrolmentLogContextBuilder.setDeviceId(String.valueOf(existingDevice.getId())).setDeviceType(String.valueOf(existingDevice.getType())).setOwner(newEnrolmentInfo.getOwner()).setOwnership(String.valueOf(newEnrolmentInfo.getOwnership())).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).setUserName(userName).build());
status = true;
} else {
log.warn("Unable to update device enrollment for device : " + device.getDeviceIdentifier() +
@ -327,6 +356,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
device.setEnrolmentInfo(enrollment);
DeviceManagementDAOFactory.commitTransaction();
log.info("Device enrolled successfully", deviceEnrolmentLogContextBuilder.setDeviceId(String.valueOf(device.getId())).setDeviceType(String.valueOf(device.getType())).setOwner(enrollment.getOwner()).setOwnership(String.valueOf(enrollment.getOwnership())).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).setUserName(userName).build());
} else {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceManagementException("No device type registered with name - " + device.getType()
@ -515,7 +545,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
int tenantId = this.getTenantId();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Device device = this.getDevice(deviceId, false);
if (device == null) {
if (log.isDebugEnabled()) {
@ -549,7 +580,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
}
//procees to dis-enroll a device from traccar ends
log.info("Device disenrolled successfully", deviceEnrolmentLogContextBuilder.setDeviceId(String.valueOf(device.getId())).setDeviceType(String.valueOf(device.getType())).setOwner(device.getEnrolmentInfo().getOwner()).setOwnership(String.valueOf(device.getEnrolmentInfo().getOwnership())).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).setUserName(userName).build());
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while dis-enrolling '" + deviceId.getType() +

@ -0,0 +1,181 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
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 appType;
private final String subType;
private final String tenantId;
private final String tenantDomain;
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.appType = builder.appType;
this.subType = builder.subType;
this.tenantId = builder.tenantId;
this.tenantDomain = builder.tenantDomain;
this.device = builder.device;
this.userName = builder.userName;
this.action = builder.action;
}
public String getAppId() {
return appId;
}
public String getAppName() {
return appName;
}
public String getAppType() {
return appType;
}
public String getSubType() {
return subType;
}
public String getTenantId() {
return tenantId;
}
public String getTenantDomain() {
return tenantDomain;
}
public String getDevice() {
return device;
}
public String getUserName() {
return userName;
}
public String getAction() {
return action;
}
public static class Builder {
private String appId;
private String appName;
private String appType;
private String subType;
private String tenantId;
private String tenantDomain;
private String device;
private String userName;
private String action;
public Builder() {
}
public String getUserName() {
return userName;
}
public Builder setUserName(String userName) {
this.userName = userName;
return this;
}
public String getAppId() {
return appId;
}
public Builder setAppId(String appId) {
this.appId = appId;
return this;
}
public String getAppName() {
return appName;
}
public Builder setAppName(String appName) {
this.appName = appName;
return this;
}
public String getAppType() {
return appType;
}
public Builder setAppType(String appType) {
this.appType = appType;
return this;
}
public String getSubType() {
return subType;
}
public Builder setSubType(String subType) {
this.subType = subType;
return this;
}
public String getTenantDomain() {
return tenantDomain;
}
public Builder setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
return this;
}
public String getTenantId() {
return tenantId;
}
public Builder setTenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
public String getDevice() {
return device;
}
public Builder setDevice(String device) {
this.device = device;
return this;
}
public String getAction() {
return action;
}
public Builder setAction(String action) {
this.action = action;
return this;
}
public AppInstallLogContext build() {
return new AppInstallLogContext(this);
}
}
}

@ -0,0 +1,150 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.notification.logger;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
public class DeviceConnectivityLogContext extends LogContext {
private final String deviceId;
private final String deviceType;
private final String actionTag;
private final String operationCode;
private final String tenantId;
private final String tenantDomain;
private final String userName;
private DeviceConnectivityLogContext(Builder builder) {
this.deviceId = builder.deviceId;
this.deviceType = builder.deviceType;
this.actionTag = builder.actionTag;
this.operationCode = builder.operationCode;
this.tenantId = builder.tenantId;
this.tenantDomain = builder.tenantDomain;
this.userName = builder.userName;
}
public String getDeviceId() {
return deviceId;
}
public String getDeviceType() {
return deviceType;
}
public String getActionTag() {
return actionTag;
}
public String getOperationCode() {
return operationCode;
}
public String getTenantId() {
return tenantId;
}
public String getTenantDomain() {
return tenantDomain;
}
public String getUserName() {
return userName;
}
public static class Builder {
private String deviceId;
private String deviceType;
private String operationCode;
private String actionTag;
private String tenantId;
private String tenantDomain;
private String userName;
public Builder() {
}
public String getDeviceId() {
return deviceId;
}
public Builder setDeviceId(String deviceId) {
this.deviceId = deviceId;
return this;
}
public String getDeviceType() {
return deviceType;
}
public Builder setDeviceType(String deviceType) {
this.deviceType = deviceType;
return this;
}
public String getOperationCode() {
return operationCode;
}
public Builder setOperationCode(String operationCode) {
this.operationCode = operationCode;
return this;
}
public String getTenantId() {
return tenantId;
}
public Builder setTenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}
public String getTenantDomain() {
return tenantDomain;
}
public Builder setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
return this;
}
public String getUserName() {
return userName;
}
public Builder setUserName(String userName) {
this.userName = userName;
return this;
}
public String getActionTag() {
return actionTag;
}
public Builder setActionTag(String actionTag) {
this.actionTag = actionTag;
return this;
}
public DeviceConnectivityLogContext build() {
return new DeviceConnectivityLogContext(this);
}
}
}

@ -0,0 +1,149 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.notification.logger;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
public class DeviceEnrolmentLogContext extends LogContext {
private final String deviceId;
private final String deviceType;
private final String owner;
private final String ownership;
private final String tenantID;
private final String tenantDomain;
private final String userName;
private DeviceEnrolmentLogContext(Builder builder) {
this.deviceId = builder.deviceId;
this.deviceType = builder.deviceType;
this.owner = builder.owner;
this.ownership = builder.ownership;
this.tenantID = builder.tenantID;
this.tenantDomain = builder.tenantDomain;
this.userName = builder.userName;
}
public String getTenantID() {
return tenantID;
}
public String getDeviceId() {
return deviceId;
}
public String getOwner() {
return owner;
}
public String getDeviceType() {
return deviceType;
}
public String getOwnership() {
return ownership;
}
public String getTenantDomain() {
return tenantDomain;
}
public String getUserName() {
return userName;
}
public static class Builder {
private String deviceId;
private String deviceType;
private String owner;
private String ownership;
private String tenantID;
private String tenantDomain;
private String userName;
public Builder() {
}
public String getDeviceType() {
return deviceType;
}
public Builder setDeviceType(String deviceType) {
this.deviceType = deviceType;
return this;
}
public String getTenantID() {
return tenantID;
}
public Builder setTenantID(String tenantID) {
this.tenantID = tenantID;
return this;
}
public String getTenantDomain() {
return tenantDomain;
}
public Builder setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
return this;
}
public String getUserName() {
return userName;
}
public Builder setUserName(String userName) {
this.userName = userName;
return this;
}
public String getDeviceId() {
return deviceId;
}
public Builder setDeviceId(String deviceId) {
this.deviceId = deviceId;
return this;
}
public String getOwner() {
return owner;
}
public Builder setOwner(String owner) {
this.owner = owner;
return this;
}
public String getOwnership() {
return ownership;
}
public Builder setOwnership(String ownership) {
this.ownership = ownership;
return this;
}
public DeviceEnrolmentLogContext build() {
return new DeviceEnrolmentLogContext(this);
}
}
}

@ -0,0 +1,133 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.notification.logger;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
public class PolicyLogContext extends LogContext {
private final String policyName;
private final String payload;
private final String actionTag;
private final String userName;
private final String tenantID;
private final String tenantDomain;
private PolicyLogContext(Builder builder) {
this.policyName = builder.policyName;
this.payload = builder.payload;
this.actionTag = builder.actionTag;
this.userName = builder.userName;
this.tenantID = builder.tenantID;
this.tenantDomain = builder.tenantDomain;
}
public String getPolicyName() {
return policyName;
}
public String getPayload() {
return payload;
}
public String getActionTag() {
return actionTag;
}
public String getUserName() {
return userName;
}
public String getTenantID() {
return tenantID;
}
public String getTenantDomain() {
return tenantDomain;
}
public static class Builder {
private String policyName;
private String payload;
private String actionTag;
private String userName;
private String tenantID;
private String tenantDomain;
public Builder() {
}
public String getPolicyName() {
return policyName;
}
public Builder setPolicyName(String policyName) {
this.policyName = policyName;
return this;
}
public String getPayload() {
return payload;
}
public Builder setPayload(String payload) {
this.payload = payload;
return this;
}
public String getActionTag() {
return actionTag;
}
public Builder setActionTag(String actionTag) {
this.actionTag = actionTag;
return this;
}
public String getUserName() {
return userName;
}
public Builder setUserName(String userName) {
this.userName = userName;
return this;
}
public String getTenantID() {
return tenantID;
}
public Builder setTenantID(String tenantID) {
this.tenantID = tenantID;
return this;
}
public String getTenantDomain() {
return tenantDomain;
}
public Builder setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
return this;
}
public PolicyLogContext build() {
return new PolicyLogContext(this);
}
}
}

@ -0,0 +1,318 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext;
import io.entgra.device.mgt.core.notification.logger.util.MDCContextUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraAppInstallLoggerImpl implements EntgraLogger {
private static Log log = null;
public EntgraAppInstallLoggerImpl(Class<?> clazz) {
log = LogFactory.getLog(clazz);
}
public void info(String message) {
log.info(message);
}
public void info(String message, Throwable t) {
log.info(message, t);
}
@Override
public void info(Object o) {
log.info(o);
}
@Override
public void info(Object o, Throwable throwable) {
log.info(o, throwable);
}
@Override
public void info(String message, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.info(message);
}
@Override
public void info(Object object, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.info(object);
}
@Override
public void info(Object object, Throwable t, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.info(object, t);
}
public void debug(String message) {
log.debug(message);
}
public void debug(String message, Throwable t) {
log.debug(message, t);
}
@Override
public void debug(Object o) {
log.debug(o);
}
@Override
public void debug(Object o, Throwable throwable) {
log.debug(o, throwable);
}
@Override
public void debug(String message, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.debug(message);
}
@Override
public void debug(Object object, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.debug(object);
}
@Override
public void debug(Object object, Throwable t, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.debug(object, t);
}
public void error(String message) {
log.error(message);
}
public void error(String message, Throwable t) {
log.error(message, t);
}
@Override
public void error(Object o) {
log.error(o);
}
@Override
public void error(Object o, Throwable throwable) {
log.error(o, throwable);
}
@Override
public void error(String message, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.error(message);
}
@Override
public void error(String message, Throwable t, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.error(message, t);
}
@Override
public void error(Object object, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.error(object);
}
@Override
public void error(Object object, Throwable t, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.error(object, t);
}
public void warn(String message) {
log.warn(message);
}
public void warn(String message, Throwable t) {
log.warn(message, t);
}
@Override
public void warn(Object o) {
log.warn(o);
}
@Override
public void warn(Object o, Throwable throwable) {
log.warn(o, throwable);
}
@Override
public void warn(String message, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.warn(message);
}
@Override
public void warn(String message, Throwable t, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.warn(message, t);
}
@Override
public void warn(Object object, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.warn(object);
}
@Override
public void warn(Object object, Throwable t, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.warn(object, t);
}
public void trace(String message) {
log.trace(message);
}
public void trace(String message, Throwable t) {
log.trace(message, t);
}
@Override
public void trace(Object o) {
log.trace(o);
}
@Override
public void trace(Object o, Throwable throwable) {
log.trace(o, throwable);
}
@Override
public void trace(String message, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.trace(message);
}
@Override
public void trace(Object object, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.trace(object);
}
@Override
public void trace(Object object, Throwable t, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.trace(object, t);
}
public void fatal(String message) {
log.fatal(message);
}
public void fatal(String message, Throwable t) {
log.fatal(message, t);
}
@Override
public void fatal(Object o) {
log.fatal(0);
}
@Override
public void fatal(Object o, Throwable throwable) {
log.fatal(0, throwable);
}
@Override
public void fatal(String message, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.fatal(message);
}
@Override
public void fatal(Object object, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.fatal(object);
}
@Override
public void fatal(Object object, Throwable t, LogContext logContext) {
AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext;
MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext);
log.fatal(object, t);
}
@Override
public boolean isDebugEnabled() {
return log.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return log.isErrorEnabled();
}
@Override
public boolean isFatalEnabled() {
return log.isFatalEnabled();
}
@Override
public boolean isInfoEnabled() {
return log.isInfoEnabled();
}
@Override
public boolean isTraceEnabled() {
return log.isTraceEnabled();
}
@Override
public boolean isWarnEnabled() {
return log.isWarnEnabled();
}
@Override
public void clearLogContext() {
MDC.clear();
}
}

@ -0,0 +1,318 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.DeviceConnectivityLogContext;
import io.entgra.device.mgt.core.notification.logger.util.MDCContextUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraDeviceConnectivityLoggerImpl implements EntgraLogger {
private static Log log = null;
public EntgraDeviceConnectivityLoggerImpl(Class<?> clazz) {
log = LogFactory.getLog(clazz);
}
public void info(String message) {
log.info(message);
}
public void info(String message, Throwable t) {
log.info(message, t);
}
@Override
public void info(Object o) {
log.info(o);
}
@Override
public void info(Object o, Throwable throwable) {
log.info(o, throwable);
}
@Override
public void info(String message, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.info(message);
}
@Override
public void info(Object object, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.info(object);
}
@Override
public void info(Object object, Throwable t, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.info(object, t);
}
public void debug(String message) {
log.debug(message);
}
public void debug(String message, Throwable t) {
log.debug(message, t);
}
@Override
public void debug(Object o) {
log.debug(o);
}
@Override
public void debug(Object o, Throwable throwable) {
log.debug(o, throwable);
}
@Override
public void debug(String message, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.debug(message);
}
@Override
public void debug(Object object, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.debug(object);
}
@Override
public void debug(Object object, Throwable t, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.debug(object, t);
}
public void error(String message) {
log.error(message);
}
public void error(String message, Throwable t) {
log.error(message, t);
}
@Override
public void error(Object o) {
log.error(o);
}
@Override
public void error(Object o, Throwable throwable) {
log.error(o, throwable);
}
@Override
public void error(String message, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.error(message);
}
@Override
public void error(String message, Throwable t, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.error(message, t);
}
@Override
public void error(Object object, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.error(object);
}
@Override
public void error(Object object, Throwable t, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.error(object, t);
}
public void warn(String message) {
log.warn(message);
}
public void warn(String message, Throwable t) {
log.warn(message, t);
}
@Override
public void warn(Object o) {
log.warn(o);
}
@Override
public void warn(Object o, Throwable throwable) {
log.warn(o, throwable);
}
@Override
public void warn(String message, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.warn(message);
}
@Override
public void warn(String message, Throwable t, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.warn(message, t);
}
@Override
public void warn(Object object, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.warn(object);
}
@Override
public void warn(Object object, Throwable t, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.warn(object, t);
}
public void trace(String message) {
log.trace(message);
}
public void trace(String message, Throwable t) {
log.trace(message, t);
}
@Override
public void trace(Object o) {
log.trace(o);
}
@Override
public void trace(Object o, Throwable throwable) {
log.trace(o, throwable);
}
@Override
public void trace(String message, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.trace(message);
}
@Override
public void trace(Object object, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.trace(object);
}
@Override
public void trace(Object object, Throwable t, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.trace(object, t);
}
public void fatal(String message) {
log.fatal(message);
}
public void fatal(String message, Throwable t) {
log.fatal(message, t);
}
@Override
public void fatal(Object o) {
log.fatal(0);
}
@Override
public void fatal(Object o, Throwable throwable) {
log.fatal(0, throwable);
}
@Override
public void fatal(String message, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.fatal(message);
}
@Override
public void fatal(Object object, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.fatal(object);
}
@Override
public void fatal(Object object, Throwable t, LogContext logContext) {
DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext;
MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext);
log.fatal(object, t);
}
@Override
public boolean isDebugEnabled() {
return log.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return log.isErrorEnabled();
}
@Override
public boolean isFatalEnabled() {
return log.isFatalEnabled();
}
@Override
public boolean isInfoEnabled() {
return log.isInfoEnabled();
}
@Override
public boolean isTraceEnabled() {
return log.isTraceEnabled();
}
@Override
public boolean isWarnEnabled() {
return log.isWarnEnabled();
}
@Override
public void clearLogContext() {
MDC.clear();
}
}

@ -0,0 +1,318 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.DeviceEnrolmentLogContext;
import io.entgra.device.mgt.core.notification.logger.util.MDCContextUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraDeviceEnrolmentLoggerImpl implements EntgraLogger {
private static Log log = null;
public EntgraDeviceEnrolmentLoggerImpl(Class<?> clazz) {
log = LogFactory.getLog(clazz);
}
public void info(String message) {
log.info(message);
}
public void info(String message, Throwable t) {
log.info(message, t);
}
@Override
public void info(Object o) {
log.info(o);
}
@Override
public void info(Object o, Throwable throwable) {
log.info(o, throwable);
}
@Override
public void info(String message, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.info(message);
}
@Override
public void info(Object object, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.info(object);
}
@Override
public void info(Object object, Throwable t, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.info(object, t);
}
public void debug(String message) {
log.debug(message);
}
public void debug(String message, Throwable t) {
log.debug(message, t);
}
@Override
public void debug(Object o) {
log.debug(o);
}
@Override
public void debug(Object o, Throwable throwable) {
log.debug(o, throwable);
}
@Override
public void debug(String message, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.debug(message);
}
@Override
public void debug(Object object, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.debug(object);
}
@Override
public void debug(Object object, Throwable t, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.debug(object, t);
}
public void error(String message) {
log.error(message);
}
public void error(String message, Throwable t) {
log.error(message, t);
}
@Override
public void error(Object o) {
log.error(o);
}
@Override
public void error(Object o, Throwable throwable) {
log.error(o, throwable);
}
@Override
public void error(String message, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.error(message);
}
@Override
public void error(String message, Throwable t, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.error(message, t);
}
@Override
public void error(Object object, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.error(object);
}
@Override
public void error(Object object, Throwable t, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.error(object, t);
}
public void warn(String message) {
log.warn(message);
}
public void warn(String message, Throwable t) {
log.warn(message, t);
}
@Override
public void warn(Object o) {
log.warn(o);
}
@Override
public void warn(Object o, Throwable throwable) {
log.warn(o, throwable);
}
@Override
public void warn(String message, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.warn(message);
}
@Override
public void warn(String message, Throwable t, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.warn(message, t);
}
@Override
public void warn(Object object, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.warn(object);
}
@Override
public void warn(Object object, Throwable t, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.warn(object, t);
}
public void trace(String message) {
log.trace(message);
}
public void trace(String message, Throwable t) {
log.trace(message, t);
}
@Override
public void trace(Object o) {
log.trace(o);
}
@Override
public void trace(Object o, Throwable throwable) {
log.trace(o, throwable);
}
@Override
public void trace(String message, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.trace(message);
}
@Override
public void trace(Object object, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.trace(object);
}
@Override
public void trace(Object object, Throwable t, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.trace(object, t);
}
public void fatal(String message) {
log.fatal(message);
}
public void fatal(String message, Throwable t) {
log.fatal(message, t);
}
@Override
public void fatal(Object o) {
log.fatal(0);
}
@Override
public void fatal(Object o, Throwable throwable) {
log.fatal(0, throwable);
}
@Override
public void fatal(String message, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.fatal(message);
}
@Override
public void fatal(Object object, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.fatal(object);
}
@Override
public void fatal(Object object, Throwable t, LogContext logContext) {
DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext;
MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext);
log.fatal(object, t);
}
@Override
public boolean isDebugEnabled() {
return log.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return log.isErrorEnabled();
}
@Override
public boolean isFatalEnabled() {
return log.isFatalEnabled();
}
@Override
public boolean isInfoEnabled() {
return log.isInfoEnabled();
}
@Override
public boolean isTraceEnabled() {
return log.isTraceEnabled();
}
@Override
public boolean isWarnEnabled() {
return log.isWarnEnabled();
}
@Override
public void clearLogContext() {
MDC.clear();
}
}

@ -17,7 +17,6 @@
*/
package io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.DeviceLogContext;
@ -26,7 +25,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraDeviceLoggerImpl implements EntgraLogger {
private static Log log = null;
@ -74,7 +72,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger {
log.info(object, t);
}
public void debug(String message) {
log.debug(message);
}
@ -114,7 +111,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger {
log.debug(object, t);
}
public void error(String message) {
log.error(message);
}
@ -161,7 +157,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger {
log.error(object, t);
}
public void warn(String message) {
log.warn(message);
}
@ -208,7 +203,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger {
log.warn(object, t);
}
public void trace(String message) {
log.trace(message);
}
@ -248,7 +242,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger {
log.trace(object, t);
}
public void fatal(String message) {
log.fatal(message);
}

@ -0,0 +1,318 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
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.util.MDCContextUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraPolicyLoggerImpl implements EntgraLogger {
private static Log log = null;
public EntgraPolicyLoggerImpl(Class<?> clazz) {
log = LogFactory.getLog(clazz);
}
public void info(String message) {
log.info(message);
}
public void info(String message, Throwable t) {
log.info(message, t);
}
@Override
public void info(Object o) {
log.info(o);
}
@Override
public void info(Object o, Throwable throwable) {
log.info(o, throwable);
}
@Override
public void info(String message, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.info(message);
}
@Override
public void info(Object object, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.info(object);
}
@Override
public void info(Object object, Throwable t, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.info(object, t);
}
public void debug(String message) {
log.debug(message);
}
public void debug(String message, Throwable t) {
log.debug(message, t);
}
@Override
public void debug(Object o) {
log.debug(o);
}
@Override
public void debug(Object o, Throwable throwable) {
log.debug(o, throwable);
}
@Override
public void debug(String message, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.debug(message);
}
@Override
public void debug(Object object, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.debug(object);
}
@Override
public void debug(Object object, Throwable t, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.debug(object, t);
}
public void error(String message) {
log.error(message);
}
public void error(String message, Throwable t) {
log.error(message, t);
}
@Override
public void error(Object o) {
log.error(o);
}
@Override
public void error(Object o, Throwable throwable) {
log.error(o, throwable);
}
@Override
public void error(String message, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.error(message);
}
@Override
public void error(String message, Throwable t, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.error(message, t);
}
@Override
public void error(Object object, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.error(object);
}
@Override
public void error(Object object, Throwable t, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.error(object, t);
}
public void warn(String message) {
log.warn(message);
}
public void warn(String message, Throwable t) {
log.warn(message, t);
}
@Override
public void warn(Object o) {
log.warn(o);
}
@Override
public void warn(Object o, Throwable throwable) {
log.warn(o, throwable);
}
@Override
public void warn(String message, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.warn(message);
}
@Override
public void warn(String message, Throwable t, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.warn(message, t);
}
@Override
public void warn(Object object, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.warn(object);
}
@Override
public void warn(Object object, Throwable t, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.warn(object, t);
}
public void trace(String message) {
log.trace(message);
}
public void trace(String message, Throwable t) {
log.trace(message, t);
}
@Override
public void trace(Object o) {
log.trace(o);
}
@Override
public void trace(Object o, Throwable throwable) {
log.trace(o, throwable);
}
@Override
public void trace(String message, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.trace(message);
}
@Override
public void trace(Object object, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.trace(object);
}
@Override
public void trace(Object object, Throwable t, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.trace(object, t);
}
public void fatal(String message) {
log.fatal(message);
}
public void fatal(String message, Throwable t) {
log.fatal(message, t);
}
@Override
public void fatal(Object o) {
log.fatal(0);
}
@Override
public void fatal(Object o, Throwable throwable) {
log.fatal(0, throwable);
}
@Override
public void fatal(String message, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.fatal(message);
}
@Override
public void fatal(Object object, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.fatal(object);
}
@Override
public void fatal(Object object, Throwable t, LogContext logContext) {
PolicyLogContext policyLogContext = (PolicyLogContext) logContext;
MDCContextUtil.populatePolicyMDCContext(policyLogContext);
log.fatal(object, t);
}
@Override
public boolean isDebugEnabled() {
return log.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return log.isErrorEnabled();
}
@Override
public boolean isFatalEnabled() {
return log.isFatalEnabled();
}
@Override
public boolean isInfoEnabled() {
return log.isInfoEnabled();
}
@Override
public boolean isTraceEnabled() {
return log.isTraceEnabled();
}
@Override
public boolean isWarnEnabled() {
return log.isWarnEnabled();
}
@Override
public void clearLogContext() {
MDC.clear();
}
}

@ -17,7 +17,6 @@
*/
package io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.UserLogContext;
@ -26,7 +25,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraUserLoggerImpl implements EntgraLogger {
private static Log log = null;

@ -17,8 +17,7 @@
*/
package io.entgra.device.mgt.core.notification.logger.util;
import io.entgra.device.mgt.core.notification.logger.DeviceLogContext;
import io.entgra.device.mgt.core.notification.logger.UserLogContext;
import io.entgra.device.mgt.core.notification.logger.*;
import org.apache.log4j.MDC;
public final class MDCContextUtil {
@ -62,6 +61,105 @@ public final class MDCContextUtil {
}
}
public static void populatePolicyMDCContext(final PolicyLogContext mdcContext) {
if (mdcContext.getPolicyName() != null) {
MDC.put("PolicyName", mdcContext.getPolicyName());
}
if (mdcContext.getPayload() != null) {
MDC.put("Payload", mdcContext.getPayload());
}
if (mdcContext.getActionTag() != null) {
MDC.put("ActionTag", mdcContext.getActionTag());
}
if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName());
}
if (mdcContext.getTenantDomain() != null) {
MDC.put("TenantDomain", mdcContext.getTenantDomain());
}
if (mdcContext.getTenantID() != null) {
MDC.put("TenantId", mdcContext.getTenantID());
}
}
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.getAppType() != null) {
MDC.put("AppType", mdcContext.getAppType());
}
if (mdcContext.getSubType() != null) {
MDC.put("SubType", mdcContext.getSubType());
}
if (mdcContext.getDevice() != null) {
MDC.put("Device", mdcContext.getDevice());
}
if (mdcContext.getTenantDomain() != null) {
MDC.put("TenantDomain", mdcContext.getTenantDomain());
}
if (mdcContext.getTenantId() != null) {
MDC.put("TenantId", mdcContext.getTenantId());
}
if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName());
}
if (mdcContext.getAction() != null) {
MDC.put("Action", mdcContext.getAction());
}
}
public static void populateDeviceConnectivityMDCContext(final DeviceConnectivityLogContext mdcContext) {
if (mdcContext.getDeviceId() != null) {
MDC.put("DeviceId", mdcContext.getDeviceId());
}
if (mdcContext.getDeviceType() != null) {
MDC.put("DeviceType", mdcContext.getDeviceType());
}
if (mdcContext.getOperationCode() != null) {
MDC.put("OperationCode", mdcContext.getOperationCode());
}
if (mdcContext.getTenantDomain() != null) {
MDC.put("TenantDomain", mdcContext.getTenantDomain());
}
if (mdcContext.getTenantId() != null) {
MDC.put("TenantId", mdcContext.getTenantId());
}
if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName());
}
if (mdcContext.getActionTag() != null) {
MDC.put("ActionTag", mdcContext.getActionTag());
}
}
public static void populateDeviceEnrolmentMDCContext(final DeviceEnrolmentLogContext mdcContext) {
if (mdcContext.getDeviceId() != null) {
MDC.put("DeviceId", mdcContext.getDeviceId());
}
if (mdcContext.getDeviceType() != null) {
MDC.put("DeviceType", mdcContext.getDeviceType());
}
if (mdcContext.getOwner() != null) {
MDC.put("Owner", mdcContext.getOwner());
}
if (mdcContext.getOwnership() != null) {
MDC.put("Ownership", mdcContext.getOwnership());
}
if (mdcContext.getTenantID() != null) {
MDC.put("TenantId", mdcContext.getTenantID());
}
if (mdcContext.getTenantDomain() != null) {
MDC.put("TenantDomain", mdcContext.getTenantDomain());
}
if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName());
}
}
}

@ -19,6 +19,9 @@
package io.entgra.device.mgt.core.policy.mgt.core.impl;
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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -54,7 +57,8 @@ import java.util.Set;
public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
private static final Log log = LogFactory.getLog(PolicyAdministratorPointImpl.class);
PolicyLogContext.Builder policyLogContextBuilder = new PolicyLogContext.Builder();
private static final EntgraLogger log = new EntgraPolicyLoggerImpl(PolicyAdministratorPointImpl.class);
private PolicyManager policyManager;
private ProfileManager profileManager;
@ -135,6 +139,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
if (log.isDebugEnabled()) {
@ -168,11 +174,13 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
properties, triggerInfo);
taskManager.registerTask(taskInfo);
taskManager.scheduleTask(taskInfo.getName());
log.info("Apply changes to device", policyLogContextBuilder.setActionTag("PUBLISH_CHANGES").setUserName(userName).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).build());
} else {
if (!taskManager.isTaskScheduled(taskName)) {
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.DELEGATION_TASK_CLAZZ,
properties, triggerInfo);
taskManager.scheduleTask(taskInfo.getName());
log.info("Apply changes to device", policyLogContextBuilder.setActionTag("PUBLISH_CHANGES").setUserName(userName).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).build());
} else {
throw new PolicyManagementException("There is a task already running for policy changes. Please try " +
"to apply " +

@ -18,6 +18,10 @@
package io.entgra.device.mgt.core.policy.mgt.core.mgt.impl;
import com.google.gson.Gson;
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.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
@ -48,6 +52,7 @@ import io.entgra.device.mgt.core.policy.mgt.core.util.PolicyManagerUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.SQLException;
import java.sql.Timestamp;
@ -55,12 +60,13 @@ import java.util.*;
public class PolicyManagerImpl implements PolicyManager {
PolicyLogContext.Builder policyLogContextBuilder = new PolicyLogContext.Builder();
private final PolicyDAO policyDAO;
private final ProfileDAO profileDAO;
private final FeatureDAO featureDAO;
private final ProfileManager profileManager;
private final PolicyConfiguration policyConfiguration;
private static final Log log = LogFactory.getLog(PolicyManagerImpl.class);
private static final EntgraLogger log = new EntgraPolicyLoggerImpl(PolicyManagerImpl.class);
public PolicyManagerImpl() {
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
@ -72,6 +78,9 @@ 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());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
try {
PolicyManagementDAOFactory.beginTransaction();
if (policy.getProfile() != null && policy.getProfile().getProfileId() == 0) {
@ -153,11 +162,16 @@ public class PolicyManagerImpl implements PolicyManager {
} finally {
PolicyManagementDAOFactory.closeConnection();
}
String stringPayload = new Gson().toJson(policy);
log.info("Policy created", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setActionTag("ADD_POLICY").setUserName(userName).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());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
try {
// Previous policy needs to be obtained before beginning the transaction
Policy previousPolicy = this.getPolicy(policy.getId());
@ -299,6 +313,8 @@ public class PolicyManagerImpl implements PolicyManager {
} finally {
PolicyManagementDAOFactory.closeConnection();
}
String stringPayload = new Gson().toJson(policy);
log.info("Policy updated", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setActionTag("UPDATE_POLICY").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build());
return policy;
}
@ -488,6 +504,10 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
String stringPayload = new Gson().toJson(policies);
boolean bool;
try {
List<Policy> existingPolicies;
@ -516,18 +536,24 @@ public class PolicyManagerImpl implements PolicyManager {
} finally {
PolicyManagementDAOFactory.closeConnection();
}
log.info("Policy priorities updated", policyLogContextBuilder.setPayload(stringPayload).setActionTag("UPDATE_POLICY_PRIORITIES").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build());
return bool;
}
@Override
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
try {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
PolicyManagementDAOFactory.beginTransaction();
policyDAO.deleteAllPolicyRelatedConfigs(policy.getId());
policyDAO.deletePolicy(policy.getId());
featureDAO.deleteFeaturesOfProfile(policy.getProfileId());
profileDAO.deleteProfile(policy.getProfileId());
PolicyManagementDAOFactory.commitTransaction();
String stringPayload = new Gson().toJson(policy);
log.info("Policy deleted", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setActionTag("DELETE_POLICY").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build());
return true;
} catch (PolicyManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction();
@ -548,6 +574,9 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
public boolean deletePolicy(int policyId) throws PolicyManagementException {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
boolean bool;
List<Policy> policies = this.getPolicies();
Policy pol = null;
@ -578,6 +607,8 @@ public class PolicyManagerImpl implements PolicyManager {
featureDAO.deleteFeaturesOfProfile(policy.getProfileId());
profileDAO.deleteProfile(policy.getProfileId());
PolicyManagementDAOFactory.commitTransaction();
String stringPayload = new Gson().toJson(policy);
log.info("Policy deleted", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setActionTag("DELETE_POLICY").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build());
return bool;
} catch (PolicyManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction();
@ -636,6 +667,9 @@ public class PolicyManagerImpl implements PolicyManager {
List<Device> deviceList = new ArrayList<>();
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
.getInstance().getDeviceManagementService();
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) {
try {
Device device = deviceManagementService.getDevice(deviceIdentifier, false);
@ -664,6 +698,9 @@ public class PolicyManagerImpl implements PolicyManager {
}
policy.setDevices(deviceList);
}
String policyPayload = new Gson().toJson(policy);
String deviceListPayload = new Gson().toJson(deviceList);
log.info("Policy added to devices", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(" Policy: " + policyPayload + " DeviceList: " + deviceListPayload).setActionTag("ADD_POLICY_TO_DEVICE").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build());
} catch (PolicyManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction();
throw new PolicyManagementException("Error occurred while adding the policy ("

Loading…
Cancel
Save