Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. import java.io.BufferedReader;
  2.  
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. import java.util.HashMap;
  7. import java.util.Set;
  8.  
  9. public class Main {
  10.  
  11.  
  12. public static void main (String[] args) throws IOException {
  13.  
  14.  
  15. try {
  16.  
  17. FileReader fileReader = new FileReader("C://Users//mk920519//Desktop//hello.txt");
  18.  
  19. BufferedReader bufferedReader = new BufferedReader(fileReader);
  20.  
  21. String line;
  22.  
  23. PrintWriter printWriter = new PrintWriter("C://Users//mk920519//Desktop//loging.txt");
  24.  
  25. String logErrorInfo = "INFO";
  26. String logErrorWarn = "WARN";
  27. String logErrorError = "ERROR";
  28. String logErrorDebug = "DEBUG";
  29. String logErrorFatal = "FATAL";
  30.  
  31. int countInfoLog = 0;
  32. int countWarnLog = 0;
  33. int countErrorLog = 0;
  34. int countDebugLog = 0;
  35. int countFatalLog = 0;
  36.  
  37. HashMap<String, Integer> myMap = new HashMap<>();
  38.  
  39. while((line = bufferedReader.readLine()) != null ){
  40.  
  41. if(line.startsWith("2")) {
  42.  
  43. String logErrorSubstring = line.substring(24, 30);
  44.  
  45.  
  46. if(logErrorSubstring.contains(logErrorInfo)) {
  47.  
  48. myMap.put("INFO", 1);
  49.  
  50. }else if (logErrorSubstring.contains(logErrorWarn)) {
  51.  
  52. myMap.put("WARN",2);
  53.  
  54. }else if (logErrorSubstring.contains(logErrorError)) {
  55.  
  56. myMap.put("ERROR",3);
  57.  
  58. }else if (logErrorSubstring.contains(logErrorDebug)) {
  59.  
  60. myMap.put("DEBUG", 4);
  61.  
  62. }else if(logErrorSubstring.contains(logErrorFatal)) {
  63.  
  64. myMap.put("FATAL",5);
  65.  
  66. }
  67.  
  68. if(myMap.get("INFO").equals(1)) {
  69.  
  70. countInfoLog++;
  71.  
  72. }else if(myMap.get("WARN").equals(2)) {
  73.  
  74. countWarnLog++;
  75.  
  76. }else if(myMap.get("ERROR").equals(3)) {
  77.  
  78. countErrorLog++;
  79.  
  80. }else if(myMap.get("DEBUG").equals(4)) {
  81.  
  82. countDebugLog++;
  83.  
  84. }else if(myMap.get("FATAL").equals(5)) {
  85.  
  86. countFatalLog++;
  87. }
  88.  
  89. }else {
  90.  
  91. bufferedReader.readLine();
  92.  
  93. }}
  94.  
  95. System.out.println("INFO LOG : " + countInfoLog);
  96. System.out.println("WARN LOG : " + countWarnLog);
  97. System.out.println("ERROR LOG : " + countErrorLog);
  98. System.out.println("DEBUG LOG : " + countDebugLog);
  99. System.out.println("FATAL LOG : " + countFatalLog);
  100.  
  101. }catch (Exception e) {
  102. e.printStackTrace();
  103. }
  104.  
  105.  
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement