Skip to content

Commit

Permalink
🚸 logStat squash same key #46
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed Sep 18, 2024
1 parent 532d397 commit a3367e4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/pro/fessional/mirana/stat/LogStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ public static Stat buildStat(String log, long from, Collection<? extends Word> k
int viewLen = 0;
int sectLen = 0;
int kwc = 1;
Word lwd = null;
byte[] kwh = SectionHead.getBytes();
byte[] kwb = SectionWord.getBytes();
byte[] kwt = SectionFoot.getBytes();
Expand Down Expand Up @@ -384,7 +385,7 @@ public static Stat buildStat(String log, long from, Collection<? extends Word> k

if (viewLen-- <= 0) {
findLen = 0;
viewLen = 0;
// viewLen = 0;
}
}
}
Expand All @@ -393,12 +394,15 @@ public static Stat buildStat(String log, long from, Collection<? extends Word> k
if (len >= keyMax) {
Word m = find(buff, i, lineEnd, keys);
if (m != null) {
fos.write(kwh);
fos.write(String.valueOf(kwc++).getBytes());
fos.write(kwb);
fos.write(m.bytes);
fos.write(kwt);
fos.write('\n');
if (lwd == null || viewLen < 0 || !Arrays.equals(lwd.bytes, m.bytes)) {
fos.write(kwh);
fos.write(String.valueOf(kwc++).getBytes());
fos.write(kwb);
fos.write(m.bytes);
fos.write(kwt);
fos.write('\n');
}
lwd = m;
findLen = m.bytes.length;
viewLen = preview;
i = i + findLen - 1;
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/pro/fessional/mirana/stat/LogStatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void stat() throws IOException {
+ "######### #3 KEYWORD: WARN #########\n"
+ "2021-07-11 00:42:42.244 WARN 24430 --- [pool-1358-thread-3] c.j.b.c.s.f.w.rate.FedexRateService : PAYOR_ACCOUNT_SHIPMENT:TotalBase=64.0,TotalSur=5.95,TotalNet=69.95\n"
+ "c11111111111111111\n"
+ "2021-07-11 00:42:42.244 WARN 24430 --- [pool-1358-thread-3] should squash to the previous line\n"
+ "c11111111111111111\n"
+ "c22222222222222222\n"
+ "######### #4 KEYWORD: ERROR #########\n"
+ "2021-07-11 00:42:42.244 ERROR 24430 --- [pool-1358-thread-3] c.j.b.c.s.f.w.rate.FedexRateService : PAYOR_ACCOUNT_SHIPMENT:TotalBase=64.0,TotalSur=5.95,TotalNet=69.95\n";
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/log-stat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ b88888888888888888
b99999999999999999
2021-07-11 00:42:42.244 WARN 24430 --- [pool-1358-thread-3] c.j.b.c.s.f.w.rate.FedexRateService : PAYOR_ACCOUNT_SHIPMENT:TotalBase=64.0,TotalSur=5.95,TotalNet=69.95
c11111111111111111
2021-07-11 00:42:42.244 WARN 24430 --- [pool-1358-thread-3] should squash to the previous line
c11111111111111111
c22222222222222222
2021-07-11 00:42:42.244 ERROR 24430 --- [pool-1358-thread-3] c.j.b.c.s.f.w.rate.FedexRateService : PAYOR_ACCOUNT_SHIPMENT:TotalBase=64.0,TotalSur=5.95,TotalNet=69.95

0 comments on commit a3367e4

Please sign in to comment.