// Path: components/logging/org.wso2.carbon.logging.view/src/main/java/org/wso2/carbon/logging/view/appenders/LoggingAppender.java
// public class LoggingAppender implements PaxAppender {
// 
//     private CircularBuffer<LogEvent> circularBuffer;
//     private static String ip;
// 
//     static {
//         try {
//             InetAddress localHost = InetAddress.getLocalHost();
//             ip = localHost.getHostAddress();
//         } catch (UnknownHostException var3) {
//             ip = "127.0.0.1";
//         }
//     }
// 
//     public LoggingAppender(CircularBuffer<LogEvent> logBuffer) {
// 
//         this.circularBuffer = logBuffer;
//     }
// 
//     public void doAppend(PaxLoggingEvent paxLoggingEvent) {
// 
//         LogEvent logEvent = new LogEvent();
//         logEvent.setMessage(paxLoggingEvent.getMessage());
//         logEvent.setLogger(paxLoggingEvent.getLoggerName());
//         logEvent.setPriority(paxLoggingEvent.getLevel().toString());
//         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
//         logEvent.setLogTime(simpleDateFormat.format(paxLoggingEvent.getTimeStamp()));
//         logEvent.setServerName(getServerName());
//         logEvent.setTenantId(getTenantId());
//         logEvent.setIp(ip);
//         logEvent.setAppName(getAppName());
//         if (paxLoggingEvent.getThrowableStrRep() != null) {
//             logEvent.setStacktrace(String.join("\n", paxLoggingEvent.getThrowableStrRep()));
//         } else {
//             logEvent.setStacktrace("");
//         }
//         circularBuffer.append(logEvent);
//     }
// 
//     private String getServerName() {
// 
//         return AccessController.doPrivileged((PrivilegedAction<String>) () -> ServerConfiguration.getInstance().getFirstProperty("ServerKey"));
//     }
// 
//     private String getIp() {
// 
//         try {
//             InetAddress localHost = InetAddress.getLocalHost();
//             return localHost.getHostAddress();
//         } catch (UnknownHostException var3) {
//             return "127.0.0.1";
//         }
//     }
// 
//     private String getTenantId() {
// 
//         int tenantId =
//                 AccessController.doPrivileged((PrivilegedAction<Integer>) () -> CarbonContext.getThreadLocalCarbonContext().getTenantId());
//         return String.valueOf(tenantId);
//     }
// 
//     private String getAppName() {
// 
//         String appName = CarbonContext.getThreadLocalCarbonContext().getApplicationName();
//         return appName != null ? appName : "";
//     }
// 
// }


import org.ops4j.pax.logging.spi.PaxAppender;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.wso2.carbon.logging.view.appenders.LoggingAppender;
import java.util.Hashtable;
/*
 * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. 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 org.wso2.carbon.logging.view.internal;



/**
 * Log Viewer Service Component.
 */
@Component(name = "org.wso2.carbon.logging.view.component", immediate = true)
public class CarbonLoggingViewServiceComponent {

    @Activate
    protected void activate(ComponentContext componentContext) {

// Path: components/logging/org.wso2.carbon.logging.view/src/main/java/org/wso2/carbon/logging/view/appenders/LoggingAppender.java
// public class LoggingAppender implements PaxAppender {
// 
//     private CircularBuffer<LogEvent> circularBuffer;
//     private static String ip;
// 
//     static {
//         try {
//             InetAddress localHost = InetAddress.getLocalHost();
//             ip = localHost.getHostAddress();
//         } catch (UnknownHostException var3) {
//             ip = "127.0.0.1";
//         }
//     }
// 
//     public LoggingAppender(CircularBuffer<LogEvent> logBuffer) {
// 
//         this.circularBuffer = logBuffer;
//     }
// 
//     public void doAppend(PaxLoggingEvent paxLoggingEvent) {
// 
//         LogEvent logEvent = new LogEvent();
//         logEvent.setMessage(paxLoggingEvent.getMessage());
//         logEvent.setLogger(paxLoggingEvent.getLoggerName());
//         logEvent.setPriority(paxLoggingEvent.getLevel().toString());
//         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
//         logEvent.setLogTime(simpleDateFormat.format(paxLoggingEvent.getTimeStamp()));
//         logEvent.setServerName(getServerName());
//         logEvent.setTenantId(getTenantId());
//         logEvent.setIp(ip);
//         logEvent.setAppName(getAppName());
//         if (paxLoggingEvent.getThrowableStrRep() != null) {
//             logEvent.setStacktrace(String.join("\n", paxLoggingEvent.getThrowableStrRep()));
//         } else {
//             logEvent.setStacktrace("");
//         }
//         circularBuffer.append(logEvent);
//     }
// 
//     private String getServerName() {
// 
//         return AccessController.doPrivileged((PrivilegedAction<String>) () -> ServerConfiguration.getInstance().getFirstProperty("ServerKey"));
//     }
// 
//     private String getIp() {
// 
//         try {
//             InetAddress localHost = InetAddress.getLocalHost();
//             return localHost.getHostAddress();
//         } catch (UnknownHostException var3) {
//             return "127.0.0.1";
//         }
//     }
// 
//     private String getTenantId() {
// 
//         int tenantId =
//                 AccessController.doPrivileged((PrivilegedAction<Integer>) () -> CarbonContext.getThreadLocalCarbonContext().getTenantId());
//         return String.valueOf(tenantId);
//     }
// 
//     private String getAppName() {
// 
//         String appName = CarbonContext.getThreadLocalCarbonContext().getApplicationName();
//         return appName != null ? appName : "";
//     }
// 
// }


// Path: components/logging/org.wso2.carbon.logging.view/src/main/java/org/wso2/carbon/logging/view/internal/CarbonLoggingViewServiceComponent.java
import org.ops4j.pax.logging.spi.PaxAppender;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.wso2.carbon.logging.view.appenders.LoggingAppender;
import java.util.Hashtable;

/*
 * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. 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 org.wso2.carbon.logging.view.internal;



/**
 * Log Viewer Service Component.
 */
@Component(name = "org.wso2.carbon.logging.view.component", immediate = true)
public class CarbonLoggingViewServiceComponent {

    @Activate
    protected void activate(ComponentContext componentContext) {

        LoggingAppender loggingAppender = new LoggingAppender(DataHolder.getInstance().getLogBuffer());