diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java index c959eb4885b..2ffa6ffa8d8 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java @@ -48,6 +48,22 @@ public interface EntgraLogger extends Log { void warn(Object object, Throwable t, LogContext logContext); + void info(String message, LogContext logContext); + + void debug(String message, LogContext logContext); + + void error(String message, LogContext logContext); + + void error(String message, Throwable t, LogContext logContext); + + void warn(String message, LogContext logContext); + + void warn(String message, Throwable t, LogContext logContext); + + void trace(String message, LogContext logContext); + + void fatal(String message, LogContext logContext); + void clearLogContext(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index cb9d37a5b41..e0ce6e82a7c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -113,7 +113,9 @@ org.wso2.carbon.event.processor.stub, org.wso2.carbon.identity.jwt.client.extension.service, org.apache.commons.codec.binary, - io.entgra.server.bootup.heartbeat.beacon + io.entgra.server.bootup.heartbeat.beacon, + io.entgra.device.mgt.extensions.logger.*, + io.entgra.notification.logger.* !org.wso2.carbon.device.mgt.core.internal, @@ -352,6 +354,10 @@ org.wso2.carbon.devicemgt io.entgra.task.mgt.common + + org.wso2.carbon.devicemgt + io.entgra.notification.logger + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java index 3371f8d8048..4770f9fee49 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java @@ -18,8 +18,9 @@ package org.wso2.carbon.device.mgt.core.notification.mgt; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.notification.logger.DeviceLogContext; +import io.entgra.notification.logger.impl.EntgraDeviceLoggerImpl; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; @@ -45,8 +46,8 @@ import java.util.List; */ public class NotificationManagementServiceImpl implements NotificationManagementService { - private static final Log log = LogFactory.getLog(NotificationManagementServiceImpl.class); - + private static final EntgraLogger log = new EntgraDeviceLoggerImpl(NotificationManagementServiceImpl.class); + DeviceLogContext.Builder deviceLogContexBuilder = new DeviceLogContext.Builder(); private NotificationDAO notificationDAO; public NotificationManagementServiceImpl() { diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml new file mode 100644 index 00000000000..6044056d1d0 --- /dev/null +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -0,0 +1,88 @@ + + + + + 4.0.0 + + + org.wso2.carbon.devicemgt + logger + 5.0.21-SNAPSHOT + + + io.entgra.notification.logger + Entgra - Notification Logger + bundle + http://entgra.io + + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.testng + testng + + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.extensions.logger + + + + + 8 + 8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Device Notification Logger Bundle + + io.entgra.device.mgt.extensions.logger.*, + org.apache.commons.logging;version="[1.2,2)", + org.apache.log4j;version="[1.2,2)", + org.wso2.carbon.context;version="[4.4,5) + + + io.entgra.notification.logger.* + + + + + + + + \ No newline at end of file diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/DeviceLogContext.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/DeviceLogContext.java new file mode 100644 index 00000000000..3becd28b9c1 --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/DeviceLogContext.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://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.notification.logger; + +import io.entgra.device.mgt.extensions.logger.LogContext; + +public class DeviceLogContext extends LogContext { + private final String deviceName; + private final String operationCode; + private final String deviceType; + private final String tenantID; + + private DeviceLogContext(Builder builder) { + this.operationCode = builder.operationCode; + this.deviceName = builder.deviceName; + this.deviceType = builder.deviceType; + this.tenantID = builder.tenantID; + } + + public String getTenantID() { + return tenantID; + } + + public String getDeviceName() { + return deviceName; + } + + public String getOperationCode() { + return operationCode; + } + + public String getDeviceType() { + return deviceType; + } + + + public static class Builder { + private String deviceName; + private String operationCode; + private String deviceType; + private String tenantID; + + 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 getDeviceName() { + return deviceName; + } + + public Builder setDeviceName(String deviceName) { + this.deviceName = deviceName; + return this; + } + + public String getOperationCode() { + return operationCode; + } + + public Builder setOperationCode(String operationCode) { + this.operationCode = operationCode; + return this; + } + + public DeviceLogContext build() { + return new DeviceLogContext(this); + } + + } +} diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java new file mode 100644 index 00000000000..13702d570b8 --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://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.notification.logger; + +import io.entgra.device.mgt.extensions.logger.LogContext; + +public class UserLogContext extends LogContext { + private final String userName; + private final String userEmail; + private final String metaInfo; + private final String tenantID; + + private UserLogContext(Builder builder) { + this.userEmail = builder.userEmail; + this.userName = builder.userName; + this.metaInfo = builder.metaInfo; + this.tenantID = builder.tenantID; + } + + public String getTenantID() { + return tenantID; + } + + public String getUserName() { + return userName; + } + + public String getUserEmail() { + return userEmail; + } + + public String getMetaInfo() { + return metaInfo; + } + + + public static class Builder { + private String userName; + private String userEmail; + private String metaInfo; + private String tenantID; + + public Builder() { + } + + public String getMetaInfo() { + return metaInfo; + } + + public Builder setMetaInfo(String metaInfo) { + this.metaInfo = metaInfo; + return this; + } + + public String getTenantID() { + return tenantID; + } + + public Builder setTenantID(String tenantID) { + this.tenantID = tenantID; + return this; + } + + public String getUserName() { + return userName; + } + + public Builder setUserName(String userName) { + this.userName = userName; + return this; + } + + public String getUserEmail() { + return userEmail; + } + + public Builder setUserEmail(String userEmail) { + this.userEmail = userEmail; + return this; + } + + public UserLogContext build() { + return new UserLogContext(this); + } + + } +} diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraDeviceLoggerImpl.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraDeviceLoggerImpl.java new file mode 100644 index 00000000000..f1360ae6c3d --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraDeviceLoggerImpl.java @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://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.notification.logger.impl; + + +import io.entgra.device.mgt.extensions.logger.LogContext; +import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.notification.logger.DeviceLogContext; +import io.entgra.notification.logger.util.MDCContextUtil; +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; + + public EntgraDeviceLoggerImpl(Class clazz) { + log = LogFactory.getLog(clazz); + } + + @Override + public void info(Object object, LogContext logContext) { + } + + @Override + public void info(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void debug(Object object, LogContext logContext) { + } + + @Override + public void debug(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void error(Object object, LogContext logContext) { + } + + @Override + public void error(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void fatal(Object object, LogContext logContext) { + } + + @Override + public void fatal(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void trace(Object object, LogContext logContext) { + + } + + @Override + public void trace(Object object, Throwable t, LogContext logContext) { + + } + + @Override + public void warn(Object object, LogContext logContext) { + } + + @Override + public void warn(Object object, Throwable t, LogContext logContext) { + } + + public void info(String message) { + } + + public void info(String message, Throwable t) { + log.info(message, t); + } + + @Override + public void info(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.info(message); + } + + + public void debug(String message) { + log.debug(message); + } + + + public void debug(String message, Throwable t) { + log.debug(message, t); + } + + @Override + public void debug(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.debug(message); + } + + public void error(String message) { + log.error(message); + } + + + public void error(String message, Throwable t) { + log.error(message, t); + } + + @Override + public void error(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.error(message); + } + + @Override + public void error(String message, Throwable t, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.error(message, t); + } + + + public void warn(String message) { + log.warn(message); + } + + + public void warn(String message, Throwable t) { + log.warn(message, t); + } + + @Override + public void warn(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.warn(message); + } + + @Override + public void warn(String message, Throwable t, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.warn(message, t); + } + + + public void trace(String message) { + log.trace(message); + } + + + public void trace(String message, Throwable t) { + log.trace(message, t); + } + + @Override + public void trace(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.trace(message); + } + + + public void fatal(String message) { + log.fatal(message); + } + + + public void fatal(String message, Throwable t) { + log.fatal(message, t); + } + + @Override + public void fatal(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.fatal(message); + } + + @Override + public void debug(Object o) { + log.debug(o); + } + + @Override + public void debug(Object o, Throwable throwable) { + log.debug(o, throwable); + } + + @Override + public void error(Object o) { + log.error(o); + } + + @Override + public void error(Object o, Throwable throwable) { + log.error(o, throwable); + } + + @Override + public void fatal(Object o) { + log.fatal(0); + } + + @Override + public void fatal(Object o, Throwable throwable) { + log.fatal(0, throwable); + } + + @Override + public void info(Object o) { + log.info(o); + } + + @Override + public void info(Object o, Throwable throwable) { + log.info(o, throwable); + } + + @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 trace(Object o) { + log.trace(o); + } + + @Override + public void trace(Object o, Throwable throwable) { + log.trace(o, throwable); + } + + @Override + public void warn(Object o) { + log.warn(o); + } + + @Override + public void warn(Object o, Throwable throwable) { + log.warn(o, throwable); + } + + @Override + public void clearLogContext() { + MDC.clear(); + } +} diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraUserLoggerImpl.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraUserLoggerImpl.java new file mode 100644 index 00000000000..92beeabb2ff --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraUserLoggerImpl.java @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://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.notification.logger.impl; + + +import io.entgra.device.mgt.extensions.logger.LogContext; +import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.notification.logger.UserLogContext; +import io.entgra.notification.logger.util.MDCContextUtil; +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; + + public EntgraUserLoggerImpl(Class clazz) { + log = LogFactory.getLog(clazz); + } + + @Override + public void info(Object object, LogContext logContext) { + } + + @Override + public void info(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void debug(Object object, LogContext logContext) { + } + + @Override + public void debug(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void error(Object object, LogContext logContext) { + } + + @Override + public void error(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void fatal(Object object, LogContext logContext) { + } + + @Override + public void fatal(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void trace(Object object, LogContext logContext) { + + } + + @Override + public void trace(Object object, Throwable t, LogContext logContext) { + + } + + @Override + public void warn(Object object, LogContext logContext) { + } + + @Override + public void warn(Object object, Throwable t, LogContext logContext) { + } + + public void info(String message) { + } + + public void info(String message, Throwable t) { + log.info(message, t); + } + + @Override + public void info(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.info(message); + } + + + public void debug(String message) { + log.debug(message); + } + + + public void debug(String message, Throwable t) { + log.debug(message, t); + } + + @Override + public void debug(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.debug(message); + } + + public void error(String message) { + log.error(message); + } + + + public void error(String message, Throwable t) { + log.error(message, t); + } + + @Override + public void error(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.error(message); + } + + @Override + public void error(String message, Throwable t, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.error(message, t); + } + + + public void warn(String message) { + log.warn(message); + } + + + public void warn(String message, Throwable t) { + log.warn(message, t); + } + + @Override + public void warn(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.warn(message); + } + + @Override + public void warn(String message, Throwable t, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.warn(message, t); + } + + + public void trace(String message) { + log.trace(message); + } + + + public void trace(String message, Throwable t) { + log.trace(message, t); + } + + @Override + public void trace(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.trace(message); + } + + + public void fatal(String message) { + log.fatal(message); + } + + + public void fatal(String message, Throwable t) { + log.fatal(message, t); + } + + @Override + public void fatal(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.fatal(message); + } + + @Override + public void debug(Object o) { + log.debug(o); + } + + @Override + public void debug(Object o, Throwable throwable) { + log.debug(o, throwable); + } + + @Override + public void error(Object o) { + log.error(o); + } + + @Override + public void error(Object o, Throwable throwable) { + log.error(o, throwable); + } + + @Override + public void fatal(Object o) { + log.fatal(0); + } + + @Override + public void fatal(Object o, Throwable throwable) { + log.fatal(0, throwable); + } + + @Override + public void info(Object o) { + log.info(o); + } + + @Override + public void info(Object o, Throwable throwable) { + log.info(o, throwable); + } + + @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 trace(Object o) { + log.trace(o); + } + + @Override + public void trace(Object o, Throwable throwable) { + log.trace(o, throwable); + } + + @Override + public void warn(Object o) { + log.warn(o); + } + + @Override + public void warn(Object o, Throwable throwable) { + log.warn(o, throwable); + } + + @Override + public void clearLogContext() { + MDC.clear(); + } +} diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java new file mode 100644 index 00000000000..fd78c26dba3 --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://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.notification.logger.util; + +import io.entgra.notification.logger.DeviceLogContext; +import io.entgra.notification.logger.UserLogContext; +import org.apache.log4j.MDC; + +public final class MDCContextUtil { + + public static void populateDeviceMDCContext(final DeviceLogContext mdcContext) { + if (mdcContext.getDeviceName() != null) { + MDC.put("DeviceName", mdcContext.getDeviceName()); + } + if (mdcContext.getDeviceType() != null) { + MDC.put("DeviceType", mdcContext.getDeviceType()); + } + if (mdcContext.getOperationCode() != null) { + MDC.put("OperationCode", mdcContext.getOperationCode()); + } + if (mdcContext.getTenantID() != null) { + MDC.put("TenantId", mdcContext.getTenantID()); + } + } + + public static void populateUserMDCContext(final UserLogContext mdcContext) { + if (mdcContext.getUserName() != null) { + MDC.put("UserName", mdcContext.getUserName()); + } + if (mdcContext.getUserEmail() != null) { + MDC.put("UserEmail", mdcContext.getUserEmail()); + } + if (mdcContext.getMetaInfo() != null) { + MDC.put("MetaInfo", mdcContext.getMetaInfo()); + } + if (mdcContext.getTenantID() != null) { + MDC.put("TenantId", mdcContext.getTenantID()); + } + } +} + + diff --git a/components/logger/io.entgra.notification.logger/src/test/resources/log4j.properties b/components/logger/io.entgra.notification.logger/src/test/resources/log4j.properties new file mode 100644 index 00000000000..b174b35e366 --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/test/resources/log4j.properties @@ -0,0 +1,32 @@ +# +# Copyright 2023 Entgra Pvt. Ltd.. (http://entgra.io) +# +# Licensed 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. +# + +# +# This is the log4j configuration file used by Entgra Pvt. Ltd. +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=DEBUG, STD_OUT + +# Redirect log messages to console +log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender +log4j.appender.STD_OUT.Target=System.out +log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout +log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/components/logger/pom.xml b/components/logger/pom.xml new file mode 100644 index 00000000000..f0884c2238d --- /dev/null +++ b/components/logger/pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + + + carbon-devicemgt + org.wso2.carbon.devicemgt + 5.0.21-SNAPSHOT + ../../pom.xml + + + logger + pom + Entgra - Notification Logger Component + http://entgra.io + + + io.entgra.notification.logger + + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/features/logger/io.entgra.notification.logger.feature/pom.xml b/features/logger/io.entgra.notification.logger.feature/pom.xml new file mode 100644 index 00000000000..be7f7146f23 --- /dev/null +++ b/features/logger/io.entgra.notification.logger.feature/pom.xml @@ -0,0 +1,116 @@ + + + + + + + + org.wso2.carbon.devicemgt + logger-feature + 5.0.21-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.notification.logger.feature + pom + Entgra - Notification logger + http://entgra.io + + This feature bundles for the Entgra Notification logger + + + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.testng + testng + + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.extensions.logger + + + org.wso2.carbon.devicemgt + io.entgra.notification.logger + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + io.entgra.notification.logger + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:true + + + + + org.wso2.carbon.devicemgt:io.entgra.notification.logger:${carbon.device.mgt.version} + + + + + + + + + diff --git a/features/logger/io.entgra.notification.logger.feature/src/main/resources/build.properties b/features/logger/io.entgra.notification.logger.feature/src/main/resources/build.properties new file mode 100644 index 00000000000..e98fb2729fb --- /dev/null +++ b/features/logger/io.entgra.notification.logger.feature/src/main/resources/build.properties @@ -0,0 +1,20 @@ +# +# Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved. +# +# Unauthorised copying/redistribution of this file, via any medium is strictly prohibited. +# +# Licensed under the Entgra Commercial License, Version 1.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://entgra.io/licenses/entgra-commercial/1.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. +# + +custom = true diff --git a/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf b/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf new file mode 100644 index 00000000000..7ab37b9d7d7 --- /dev/null +++ b/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf @@ -0,0 +1 @@ +instructions.configure = \ \ No newline at end of file diff --git a/features/logger/pom.xml b/features/logger/pom.xml new file mode 100644 index 00000000000..10fc1b3f0b4 --- /dev/null +++ b/features/logger/pom.xml @@ -0,0 +1,40 @@ + + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 5.0.21-SNAPSHOT + ../../pom.xml + + + 4.0.0 + logger-feature + pom + Entgra - Logger Feature + http://entgra.io + + + io.entgra.notification.logger.feature + + + diff --git a/pom.xml b/pom.xml index cf130f5b406..09590375ba1 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ components/transport-mgt components/analytics-mgt components/webapp-authenticator-framework + components/logger components/task-mgt features/device-mgt features/apimgt-extensions @@ -59,6 +60,7 @@ features/transport-mgt features/analytics-mgt features/webapp-authenticator-framework + features/logger features/task-mgt @@ -356,6 +358,11 @@ org.wso2.carbon.apimgt.keymgt.extension ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + io.entgra.notification.logger + ${carbon.device.mgt.version} +