33import java .time .LocalDate ;
44import java .util .ArrayList ;
55import java .util .List ;
6+ import java .util .StringTokenizer ;
67
78import lombok .extern .slf4j .Slf4j ;
89import root .common .server .implement .JschServer ;
@@ -33,7 +34,14 @@ public int getAlertLogFileLineCount(AlertLogCommand alc) {
3334 try {
3435 String command = String .format ("find /v /c \" \" %s" , alc .getReadFilePath ());
3536 String executeResult = jsch .executeCommand (command );
36- fileLineCnt = Integer .parseInt (executeResult );
37+ StringTokenizer st = new StringTokenizer (executeResult );
38+ String lastToken = "0" ;
39+ while (st .hasMoreTokens ()) {
40+ lastToken = st .nextToken ();
41+ }
42+
43+ fileLineCnt = Integer .parseInt (lastToken );
44+ log .debug (String .format ("alert log file line count: %s, %d" , alc .getReadFilePath (), fileLineCnt ));
3745 } catch (Exception e ) {
3846 log .error (e .getMessage ());
3947 }
@@ -45,12 +53,13 @@ public int getAlertLogFileLineCount(AlertLogCommand alc) {
4553 public String checkAlertLog (AlertLogCommand alc ) {
4654 String result = "" ;
4755 try {
48- String command = String .format ("tail %d %s" , alc .getReadLine (), alc .getReadFilePath ());
56+ String command = String .format ("tail - %d %s" , alc .getReadLine (), alc .getReadFilePath ());
4957 result = jsch .executeCommand (command );
5058 } catch (Exception e ) {
5159 log .error (e .getMessage ());
5260 }
5361
62+ log .debug (alc .toString ());
5463 return result ;
5564 }
5665
@@ -62,7 +71,7 @@ public AlertLog checkAlertLogDuringPeriod(AlertLogCommand alc, String startDate,
6271
6372 try {
6473 // 조회기간동안의 로그만을 취하여 StringBuffer에 저장한다.
65- String [] lines = fullAlertLogString .split (" \n " );
74+ String [] lines = fullAlertLogString .split (System . lineSeparator () );
6675
6776 boolean isStartDate = false ;
6877 boolean isEndDate = false ;
@@ -76,13 +85,15 @@ public AlertLog checkAlertLogDuringPeriod(AlertLogCommand alc, String startDate,
7685
7786 for (int i = 0 ; i < lines .length ; i ++) {
7887 String line = lines [i ];
79-
8088 // 조회시작일자 찾기
8189 if (!isStartDate ) {
8290 LocalDate parsedDate = DateUtils .parse (line );
83- if (parsedDate != null && DateUtils .convertDateFormat ("yyyy-MM-dd" , parsedDate ).equals (startDate )) {
84- isStartDate = true ;
85- readStartIndex = i ;
91+ if (parsedDate != null ) {
92+ String parsedDateString = DateUtils .convertDateFormat ("yyyy-MM-dd" , parsedDate );
93+ if (DateUtils .getDateDiffTime ("yyyy-MM-dd" , parsedDateString , startDate ) >= 0 ) {
94+ isStartDate = true ;
95+ readStartIndex = i ;
96+ }
8697 }
8798 }
8899
@@ -98,7 +109,7 @@ public AlertLog checkAlertLogDuringPeriod(AlertLogCommand alc, String startDate,
98109
99110 if (i == readStartIndex ) {
100111 logTimeStamp = line ;
101- }
112+ }
102113
103114 if (i != readStartIndex && !isEndDate ) {
104115 alertLog .addLog (new Log (logTimeStamp , logContents ));
@@ -127,7 +138,6 @@ public AlertLog checkAlertLogDuringPeriod(AlertLogCommand alc, String startDate,
127138 } catch (Exception e ) {
128139 log .error (e .getMessage ());
129140 }
130-
131141 return alertLog ;
132142 }
133143
@@ -143,7 +153,7 @@ private String getAlertLogStringFromCertainDate(AlertLogCommand alc, String star
143153
144154 // 조회시작일자의 로그를 모두 포함하도록 readLine 수를 점진적으로 늘리면서 읽는다.
145155 while (true ) {
146- String [] lines = fullAlertLogString .split (" \n " );
156+ String [] lines = fullAlertLogString .split (System . lineSeparator () );
147157
148158 // 현재 Read Line 수가 파일 최대 Line 수를 초과했을 시, 파일 전체를 읽고 반환한다.
149159 if (lines .length >= alertLogFileLineCnt ) {
@@ -159,8 +169,8 @@ private String getAlertLogStringFromCertainDate(AlertLogCommand alc, String star
159169 break ;
160170 }
161171 }
162-
163- if (logDate == null || logDate .equals ("" )) {
172+
173+ if (logDate == null || logDate .equals ("" )) {
164174 break ;
165175 }
166176
0 commit comments