- private static void startAPIRestLogParser(File fileLog){
- try{
- if(logFile != null && !logFile.isEmpty()){
-
- // pull the last line number
- String dataFileName = type.toLowerCase()+"-rest.log";
- String filesRead = PullLastLineRead(fileLog, dataFileName);
- if (filesRead!= null){
- filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "<br />");
- lastNumberRead= Integer.parseInt(filesRead.trim());
- }else{
- lastNumberRead = 0;
- }
- startFileSize = countLines(logFile);
- if (startFileSize < lastNumberRead ){
- logger.error("Filed Rolled: set Last number read to 0");
- lastNumberRead = 0;
- }
-
- isMissingLogFile = false;
- Path filePath = Paths.get(logFile);
- File file = new File(logFile);
- startFileSize = file.length();
- // start process pap/pdp-rest.log file
- Runnable runnable = new Runnable () {
- boolean isStop = false;
- public void run(){
- while (!isStop){
-
- if (file.isFile()){
- // log4jlogger must use .info
- Stream<String> lines = null;;
- try {
- lines = Files.lines(filePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + lastNumberRead)).skip(lastNumberRead);
- lines.forEachOrdered(line -> process(line, type, LOGTYPE.INFO));
- } catch (IOException e) {
- logger.error("Error processing line in " + dataFileName + ":" + e);
- logger.error("break the loop.");
- isStop = true;
- }finally{
- if(lines != null){
- lines.close();
- }
- }
- }
- try {
- Thread.sleep(sleepTimer);
- startFileSize = countLines(logFile);
- } catch (InterruptedException | IOException e) {
- logger.error("Error processing line in " + dataFileName + ":" + e);
- logger.error("break the loop.");
- isStop = true;
- }
-
- logger.debug("File Line Count of " + dataFileName+": " + startFileSize + " value read in: " + lastNumberRead);
- if (startFileSize < lastNumberRead ){
- logger.debug("Failed Rolled: set Last number read to 0");
- lastNumberRead = 0;
- }
- }
- }
- };
-
- Thread thread = new Thread(runnable);
- thread.start();
- }
- }catch(Exception e){
- logger.error("Exception occured in StartAPIRestLogParser" +e);
- }
+ private static void startAPIRestLogParser(File fileLog) throws IOException{
+
+ if(logFile != null && !logFile.isEmpty()){
+
+ // pull the last line number
+ String dataFileName = type.toLowerCase()+"-rest.log";
+ String filesRead = pullLastLineRead(fileLog, dataFileName);
+ if (filesRead!= null){
+ filesRead = filesRead.replaceAll(lineFormat, br);
+ lastNumberRead= Integer.parseInt(filesRead.trim());
+ }else{
+ lastNumberRead = 0;
+ }
+ startFileSize = countLines(logFile);
+ if (startFileSize < lastNumberRead ){
+ logger.error("Filed Rolled: set Last number read to 0");
+ lastNumberRead = 0;
+ }
+
+ isMissingLogFile = false;
+ Path filePath = Paths.get(logFile);
+ File file = new File(logFile);
+ startFileSize = file.length();
+ // start process pap/pdp-rest.log file
+ processAPIRestLog(file, filePath, dataFileName);
+ }