Отфильтровать исключения и маршрутизацию в файл на основе экземпляра - PullRequest
0 голосов
/ 27 сентября 2019

У меня есть сценарий, в котором мне нужно подготовить / записать исключения в файл из файла журнала, выделив имя экземпляра и записав все связанные с ним исключения в Instance.txt

пример test-dom-01.txt, test-dom-01.txt, test-dom-04.txt ... и т. д. с соответствующими ошибками

out.log

Performing Health Check for Instance : test-dom-01
test-dom-01 Instance is----->  Running
****Existing Exceptions***** on instance: test-dom-01
catalina.0.log:INFO: Error parsing HTTP request header
catalina.0.log:java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
catalina.0.log:java.lang.IllegalArgumentException: Invalid character found in the HTTP protocol
catalina.0.log:java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in 
catalina.0.log:SEVERE: Exception when trying to read white list from  probably because file list is empty

--> Health Check for Instance :test-dom-01 is completed

Performing Health Check for Instance : tests-rs-dom2-1
tests-rs-dom2-1 Instance is----->  Running
****Existing Exceptions***** on instance: tests-rs-dom2-1 
catalina.0.log:INFO: Error parsing HTTP request header
catalina.0.log:java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
catalina.out:   at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)2019-09-19 15:23:03.266 [xxxx BACK END TCPLink Reader (Server-555)]
catalina.out:   at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)2019-09-19 15:28:53 INFO
catalina.0.log:Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
catalina.0.log:org.apache.catalina.LifecycleException: Failed to initialize component [Connector[AJP/1.3-7002]]
catalina.out:Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [StandardServer[-1]]
catalina.out:Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [StandardService[Catalina]]
catalina.out:Caused by: org.apache.catalina.LifecycleException: Failed to initialize connector [Connector[AJP/1.3-7002]]
catalina.out:java.lang.Error: org.apache.catalina.LifecycleException: Failed to initialize component [StandardServer[-1]]


--> Health Check for Instance :tests-rs-dom2-1 is completed

Performing Health Check for Instance : test-dom-04
test-dom-04 Instance is----->  Running
****Existing Exceptions***** on instance: test-dom-04
catalina.0.log:Caused by: java.net.BindException: Address already in use
catalina.0.log:Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
catalina.0.log:org.apache.catalina.LifecycleException: Failed to initialize component [Connector[AJP/1.3-7002]]
catalina.out:Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [StandardServer[-1]]
catalina.out:Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [StandardService[Catalina]]
catalina.out:Caused by: org.apache.catalina.LifecycleException: Failed to initialize connector [Connector[AJP/1.3-7002]]
catalina.out:java.lang.Error: org.apache.catalina.LifecycleException: Failed to initialize component [StandardServer[-1]]


--> Health Check for Instance :test-dom-04 is completed

Спросите, нужно ли мне перемещать существующие исключения в каждый файл, игнорируя остальные строки, только исключения должны быть перемещены в отдельный файл

Ожидаемый вывод для test-dom-01 файла равен test-dom-01.tx t и содержимое

catalina.0.log:INFO: Error parsing HTTP request header
catalina.0.log:java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
catalina.0.log:java.lang.IllegalArgumentException: Invalid character found in the HTTP protocol
catalina.0.log:java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in 
catalina.0.log:SEVERE: Exception when trying to read white list from  probably because file list is empty

Ожидаемый результат для tests-rs-dom2-1 - tests-rs-dom2-1.txt

catalina.0.log:INFO: Error parsing HTTP request header
catalina.0.log:java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
catalina.out:   at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)2019-09-19 15:23:03.266 [xxxx BACK END TCPLink Reader (Server-555)]
catalina.out:   at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)2019-09-19 15:28:53 INFO
catalina.0.log:Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
catalina.0.log:org.apache.catalina.LifecycleException: Failed to initialize component [Connector[AJP/1.3-7002]]
catalina.out:Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [StandardServer[-1]]
catalina.out:Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [StandardService[Catalina]]
catalina.out:Caused by: org.apache.catalina.LifecycleException: Failed to initialize connector [Connector[AJP/1.3-7002]]
catalina.out:java.lang.Error: org.apache.catalina.LifecycleException: Failed to initialize component [StandardServer[-1]]

Пробовал:

awk '/on instance: test-dom-01/,/ /' out.log > test-dom-01.txt

но не повезло

1 Ответ

2 голосов
/ 27 сентября 2019

Вы можете использовать это awk:

awk '/ on instance: /{fn=$NF ".txt"; next} !NF{close(fn); fn=""} fn{print > fn}' out.log
...