// Copyright 2020 Google LLC
// 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
// https://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 com.google.error_analyzer.servlets;

import com.google.error_analyzer.backend.StoreLogs;
import com.google.error_analyzer.data.constant.FileConstants;
import com.google.error_analyzer.data.constant.LogFields;
import com.google.error_analyzer.data.constant.PageConstants;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import org.apache.http.HttpHost;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.common.xcontent.XContentType;

/*This class is for storing the logs entered by the user as 
plain text to the database*/
@WebServlet("/StorePlainTextLogServlet")
public class TextServlet extends HttpServlet {
    public static final StoreLogs storeLog = new StoreLogs();

    @Override
    public void doPost(HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {
        try {
            response.setContentType(FileConstants.TEXT_HTML_CONTENT_TYPE);
            String log = request.getParameter(LogFields.LOG);
            String fileName = request.getParameter(LogFields.FILE_NAME);
            request.getSession();
            InputStream inputStream =
                new ByteArrayInputStream(log.getBytes());
            boolean isUrl = false;
            String status = storeLog.checkAndStoreLog(
                request, fileName, inputStream, isUrl);
            response.getWriter().println(status);
            RequestDispatcher requestDispatcher =
                request.getRequestDispatcher(PageConstants.LANDING_PAGE);
            requestDispatcher.include(request, response);
        } catch (Exception e) {
            logger.error("Could not store file", e);
            response.getWriter().println(String.format(
                storeLogs.ERROR_TEMPLATE_RESPONSE, e));
            RequestDispatcher requestDispatcher =
                request.getRequestDispatcher(PageConstants.LANDING_PAGE);
            requestDispatcher.include(request, response);
        }
    }
}
@@ -1225,24 +1225,108 @@
 p.HttpHost;%0A
+import org.apache.logging.log4j.Logger;%0Aimport org.apache.logging.log4j.LogManager;%0A
 import org.e
@@ -1643,16 +1643,107 @@
 rvlet %7B%0A
+    private static final Logger logger =%0A         LogManager.getLogger(TextServlet.class);%0A
     publ
@@ -2836,17 +2836,16 @@
 storeLog
-s
 .ERROR_T

add logger