This is an automated email from the ASF dual-hosted git repository.

oleewere pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ambari-logsearch.git


The following commit(s) were added to refs/heads/master by this push:
     new e7d3dd1  Push logs from FileUtil to a different log file
e7d3dd1 is described below

commit e7d3dd189a6839cd84a6bc2ae2af9ec941e61e78
Author: Oliver Szabo <oleew...@gmail.com>
AuthorDate: Thu Dec 6 18:40:57 2018 +0100

    Push logs from FileUtil to a different log file
---
 .../org/apache/ambari/logfeeder/util/FileUtil.java | 45 ++--------------------
 .../src/main/resources/log4j2.yml                  | 16 ++++++++
 2 files changed, 20 insertions(+), 41 deletions(-)

diff --git 
a/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/util/FileUtil.java
 
b/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/util/FileUtil.java
index 8e2b2c9..06fd07c 100644
--- 
a/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/util/FileUtil.java
+++ 
b/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/util/FileUtil.java
@@ -21,7 +21,6 @@ package org.apache.ambari.logfeeder.util;
 
 import java.io.File;
 import java.io.IOException;
-import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -33,33 +32,20 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.io.FileUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.tools.ant.DirectoryScanner;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
 
 public class FileUtil {
   private static final Logger logger = LogManager.getLogger(FileUtil.class);
+  private static final Logger fileMonitorLogger = 
LogManager.getLogger("logfeeder.file.monitor");
+
   private static final String FOLDER_SEPARATOR = "/";
 
   private FileUtil() {
     throw new UnsupportedOperationException();
   }
 
-  public static List<File> getAllFileFromDir(File directory, String extension, 
boolean checkInSubDir) {
-    if (!directory.exists()) {
-      logger.error(directory.getAbsolutePath() + " is not exists ");
-    } else if (!directory.isDirectory()) {
-      logger.error(directory.getAbsolutePath() + " is not Directory ");
-    } else {
-      return (List<File>) FileUtils.listFiles(directory, new 
String[]{extension}, checkInSubDir);
-    }
-    return new ArrayList<File>();
-  }
-
-
   public static Object getFileKey(File file) {
     try {
       Path fileFullPath = Paths.get(file.getAbsolutePath());
@@ -73,29 +59,6 @@ public class FileUtil {
     return file.toString();
   }
 
-  public static File getFileFromClasspath(String filename) {
-    URL fileCompleteUrl = 
Thread.currentThread().getContextClassLoader().getResource(filename);
-    logger.debug("File Complete URI :" + fileCompleteUrl);
-    File file = null;
-    try {
-      file = new File(fileCompleteUrl.toURI());
-    } catch (Exception exception) {
-      logger.debug(exception.getMessage(), exception.getCause());
-    }
-    return file;
-  }
-
-  public static HashMap<String, Object> readJsonFromFile(File jsonFile) {
-    ObjectMapper mapper = new ObjectMapper();
-    try {
-      HashMap<String, Object> jsonmap = mapper.readValue(jsonFile, new 
TypeReference<HashMap<String, Object>>() {});
-      return jsonmap;
-    } catch (IOException e) {
-      logger.error("{}", e);
-    }
-    return new HashMap<String, Object>();
-  }
-
   public static File[] getInputFilesByPattern(String searchPath) {
     File searchFile = new File(searchPath);
     if (searchFile.isFile()) {
@@ -121,11 +84,11 @@ public class FileUtil {
             return files;
           }
         } catch (Exception e) {
-          logger.info("Input file was not found by pattern (exception thrown); 
{}, message: {}", searchPath, e.getMessage());
+          fileMonitorLogger.info("Input file was not found by pattern 
(exception thrown); {}, message: {}", searchPath, e.getMessage());
         }
 
       } else {
-        logger.debug("Input file config was not found by pattern; {}", 
searchPath);
+        fileMonitorLogger.debug("Input file config was not found by pattern; 
{}", searchPath);
       }
       return new File[]{};
     }
diff --git a/ambari-logsearch-logfeeder/src/main/resources/log4j2.yml 
b/ambari-logsearch-logfeeder/src/main/resources/log4j2.yml
index 8b43c35..154ba0b 100644
--- a/ambari-logsearch-logfeeder/src/main/resources/log4j2.yml
+++ b/ambari-logsearch-logfeeder/src/main/resources/log4j2.yml
@@ -61,6 +61,16 @@ Configutation:
           size: 10 MB
       DefaultRollOverStrategy:
         max: 10
+    - name: InputFile_Appender
+      fileName: ${log-path}/logfeeder-file-monitor.log
+      filePattern: "logfeeder-file-monitor.log.%d{yyyy-MM-dd-hh-mm}.gz"
+      PatternLayout:
+        pattern: "%d [%t] %-5p %C{6} (%F:%L) - %m%n"
+      Policies:
+        SizeBasedTriggeringPolicy:
+          size: 10 MB
+      DefaultRollOverStrategy:
+        max: 3
 
   Loggers:
 
@@ -87,4 +97,10 @@ Configutation:
       level: info
       AppenderRef:
       - ref: MetricsFile_Appender
+      - ref: Console_Appender
+    - name: logfeeder.file.monitor
+      additivity: false
+      level: info
+      AppenderRef:
+      - ref: MetricsFile_Appender
       - ref: Console_Appender
\ No newline at end of file

Reply via email to