--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Modifications Copyright (c) 2019 Samsung\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.oran.otf.common.utility.logger;\r
+\r
+import ch.qos.logback.classic.Level;\r
+import ch.qos.logback.classic.LoggerContext;\r
+import ch.qos.logback.classic.spi.LoggerContextListener;\r
+import ch.qos.logback.core.Context;\r
+import ch.qos.logback.core.spi.ContextAwareBase;\r
+import ch.qos.logback.core.spi.LifeCycle;\r
+import java.net.InetAddress;\r
+import java.net.UnknownHostException;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.springframework.stereotype.Component;\r
+\r
+@Component\r
+public class LoggerStartupListener extends ContextAwareBase\r
+ implements LoggerContextListener, LifeCycle {\r
+\r
+ private static final Logger logger = LoggerFactory.getLogger(LoggerStartupListener.class);\r
+ private boolean started = false;\r
+\r
+ @Override\r
+ public void start() {\r
+ if (started) {\r
+ return;\r
+ }\r
+ InetAddress addr = null;\r
+ try {\r
+ addr = InetAddress.getLocalHost();\r
+ } catch (UnknownHostException e) {\r
+ logger.error("UnknownHostException", e);\r
+ }\r
+ Context context = getContext();\r
+ if (addr != null) {\r
+ context.putProperty("server.name", addr.getHostName());\r
+ }\r
+ started = true;\r
+ }\r
+\r
+ @Override\r
+ public void stop() {\r
+ }\r
+\r
+ @Override\r
+ public boolean isStarted() {\r
+ return started;\r
+ }\r
+\r
+ @Override\r
+ public boolean isResetResistant() {\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public void onReset(LoggerContext arg0) {\r
+ }\r
+\r
+ @Override\r
+ public void onStart(LoggerContext arg0) {\r
+ }\r
+\r
+ @Override\r
+ public void onStop(LoggerContext arg0) {\r
+ }\r
+\r
+ @Override\r
+ public void onLevelChange(ch.qos.logback.classic.Logger logger, Level level) {\r
+ }\r
+}\r