A Regex that search for lines that contains a string, and not contains another string - regex

I want to analyze an error log. So I decided to search for all the error header in the error log using Notepad++ so I can get all the first line of the errors on search result (which contains short description about the error) to determine if I need to look deeper into it. But the error log apparently is full of 'useless' error log from one kind of event, like 90% of it, so it kinds of hide the real error, like searching a needle in haystack.
So from this example made up error log:
ERROR on Server1: Network connection reset.
DETAIL: The client is gone.
ERROR on Server2: Network connection reset.
DETAIL: The client is gone.
ERROR on Server1: Network connection reset.
DETAIL: The client is gone.
ERROR on Server1: Null Pointer Error.
DETAIL: Object 'Cart' does not exists.
STACKTRACE:
at UpdateCart function
at AddProducttoCart function
ERROR on Server2: Network connection reset.
DETAIL: The client is gone.
ERROR on Server2: IO Error
DETAIL: The resource on URL (www.example.com/data.xls) does not exists.
ERROR on Server2: Network connection reset.
DETAIL: The client is gone.
I want to create a regex on Notepad++ search that search for line that contains string "ERROR on" but does not contain "Network connection reset", so the search result will only contain:
ERROR on Server1: Null Pointer Error.
ERROR on Server2: IO Error
How can I do that? I've read somewhere that inverse matching on regex is somewhat hard and unusual, but it's possible. Thanks.
Btw, I've tried some other way to do this, like finding for "ERROR on" + (.*) + "Network connection reset", then replace it with empty string, so that next time I search for "ERROR on", they will not appear. But the error log becomes scrambled with weird symbols after the search and replace, and Notepad++ kinda crashing after that. I don't know. I never have any luck search and replace on Notepad++ using regex.

I would use negative lookahead.
^(?!.*?\bNetwork connection reset\b).*\bERROR on\b.*

^ERROR on (?:(?!Network connection reset).)*$
You can use a lookahead in your regex.See demo.
https://regex101.com/r/pV0fH2/1

Related

Filebeat regex for tomcat

I'm having trouble to get the correct regex for filebeat when using tomcat and log4j.
For this log:
21/10/2022 16:04:37 ERROR en Clase: ExceptionLogger - MSN: test
Exception.Class: BUSINESS EXCEPTION
ErrorCode: 0
Usuario: test
StackTrace:
at ar.com.test.conf.Monitor.monitorTest(ImpBusCaja.java:1213)
at ar.com.test.delegators.Monitor.m(Cajas.java:595)
I've configured this pattern: '^[[:space:]]' with negate=false and match=after (as the documentation says) but it doesn't work.
Even if I use the go playground, it should work: https://go.dev/play/p/JGV8ZDPtHwt
Here's what we have for configuration for log4j-based files with a slightly different pattern, but you should be able to adapt it to your situation:
multiline.type: pattern
multiline.pattern: '^\d{4}-\d{2}-'
multiline.negate: true
multiline.match: after
Here's an example standard log4j log line:
2022-10-22 13:55:34,932 [pool-8-thread-1] TRACE fully.qualified.class.Name- Here's the raw message
Here's an example exception message:
2022-10-21 20:14:42,442 [catalina-exec-6] ERROR fully.qualified.class.Name- Main error message
fully.qualified.exception.Type: Exception error message
at stack.trace.class.method(Source.java:103)
at stack.trace.class.method(Source.java:203)
at stack.trace.class.method(Source.java:303)
at stack.trace.class.method(Source.java:403)
So we are just looking for log lines starting with dddd-dd- and assuming that those are always "new log entries". We could certainly confuse things with a log line that was a continuation of something previous which started with that same pattern, but that's very rare.

GATE_Using for Thesis_Run-time Error

When I am trying to run corpus pipeline on language resources. It is throwing the below (even though I follow the order as Document reset, english tokeniser, sentence splitter)
Can someone help me with the process to debug this run-time error
Error:
gate.creole.ExecutionException: No sentences or tokens to process in document Password_Safe-window1.txt_0003E
Please run a sentence splitter and tokeniser first!
at gate.creole.POSTagger.execute(POSTagger.java:257)
at gate.util.Benchmark.executeWithBenchmarking(Benchmark.java:291)
at gate.creole.SerialController.runComponent(SerialController.java:225)
at gate.creole.SerialController.executeImpl(SerialController.java:157)
at gate.creole.SerialAnalyserController.executeImpl(SerialAnalyserController.java:223)
at gate.creole.SerialAnalyserController.execute(SerialAnalyserController.java:126)
at gate.util.Benchmark.executeWithBenchmarking(Benchmark.java:291)
at gate.gui.SerialControllerEditor$RunAction$1.run(SerialControllerEditor.java:1759)
at java.lang.Thread.run(Thread.java:745)
Edit:
The files are not empty. As i tried to implement #dedek's suggestion, it has thrown no errors. But raised one more problem as follows:
Exception in thread "ApplicationViewer1" java.lang.OutOfMemoryError: Java heap space
I think it is because your document is empty.
Can you confirm that?
There is a run-time param failOnMissingInputAnnotations of the POSTagger, set it to false and it should be ok.
See also the docs:
failOnMissingInputAnnotations - if set to false, the PR will not fail with an ExecutionException if no input Annotations are found and instead only log a single warning message per session and a debug message per document that has no input annotations (run-time, default = true).
Concerning the OutOfMemoryError: Java heap space
See following questions:
Getting OOM while using GATE on large data set
GATE PersistenceManager.loadObjectFromFile outofmemory error while loading .gapp files
JAVA PermGem memory

Response message is failed-Assertion Failed

When I am using jmeter it gives the message as "Account created successfully". So I added this message in Response assertion-->Response Message-->Contains.
But assertion is failed when giving the correct credential.When opening the assertion result, it shows the message as "/Account created successfully/".
Now how to remove the "/" from this message.
1.Please check that there is no extra space in your message
2. Make sure you are coping the message from text response only,Please look below snapshot for reference only
3. "/" is not a problem it will come before your message when assertion fail

Logback pattern - do replace if message doesn't contain a word

This is a follow-up question for How to prevent logback/slf4j from parsing a new line character
I use following pattern to avoid strings with \n breaking into new line. But after using this pattern, my stacktraces come up with \n in the beginning which looks awkward.
<pattern>[%d{dd MMM yyyy HH:mm:ss,SSS}] [%5p] [%X{sid}] [%-20C{0} %25M]:[%-4L] - %replace(%m){'\n', '\\n'}%n</pattern>
Result stacktrace:
[21 Feb 2015 23:14:24] [ERROR] [21181422764] [myclass mymethod]:[221] - Socket exception occured while sending request for user. Stacktrace:= java.net.ConnectException: Connection refused: connect
\n at java.net.DualStackPlainSocketImpl.connect0(Native Method)
I've to change the replace to match only those %m that do not have "Exception" word in them. Not sure how to accomplish this in pattern. Also, I'm concerned about how this overall match and replace is adding to logging time cost and if it is acceptable cost.
It looks like you're manually formatting the exception as part of your message, but logback does this for you if you include the exception as an argument of the log call (see SLF4J API). I recommend using that API instead of attempting to include it in your message.
final Logger log = LoggerFactory.getLogger(Foo.class);
try {
// ...
} catch (IOException e) {
log.error("Socket exception occurred while sending request for user.", e);
}
If you're concerned with performance, note that by default, logback includes packaging information for each method in the stacktrace, which could be expensive, especially if your application frequently logs exceptions. To skip the package-info lookup, append %ex to your pattern layout.
In your example:
<pattern>... %replace(%m){'\n', '\\n'}%n%ex</pattern>

How to extract the pattern " [xxxxxxx] ERROR " for splunk?

2013-11-22 08:58:43,724 [pool-2-thread-2] ERROR
org.apache.catalina.loader.WebappClassLoader- The web application
[/probe] appears to have started a thread named [scheduler_Worker-4]
but has failed to stop it. This is very likely to create a memory
leak.
2013-11-22 08:58:43,495 [pool-2-thread-2] ERROR
org.apache.catalina.loader.WebappClassLoader- The web application
[/ults] created a ThreadLocal with key of type
[com.opensymphony.xwork2.inject.ContainerImpl$10] (value
[com.opensymphony.xwork2.inject.ContainerImpl$10#188bf463]) and a
value of type [java.lang.Object[]] (value
[[Ljava.lang.Object;#18be8037]) but failed to remove it when the web
application was stopped. Threads are going to be renewed over time to
try and avoid a probable memory leak.
I want to extract the pattern string "[xxxxxxxxxxxxx] ERROR " , but don't know what is the rex?
This is the regex you need:
\[[^\]]*] ERROR