How to parse the below stack trace in log file:-
Below is the stack trace:-
2012-08-10 08:19:17 java.lang.NullPointerException
2012-08-10 08:19:17 at net.minecraft.server.World.tickEntities(World.java:1146)
2012-08-10 08:19:17 at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:567)
2012-08-10 08:19:17 at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
2012-08-10 08:19:17 at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
2012-08-10 08:19:17 at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
2012-08-10 08:19:17 at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
How to parse only the stack trace using regex? If i have put the stacktrace to a separate log file, what config needs to be done in log4j to capture only the stack trace?
Why? Log files are for humans, and the very occasional analysis program. If you are writing any software at all to read log files you are almost certainly doing something wrong already, and if you're searching for a regex to analysis a stack trace at runtime you are 99.999% likely to be barking up the wrong tree.
> How to parse only the stack trace using regex?
From the entire file? I doubt it is possible.
Log files are normally rather large. You would need to read the entire file into memory, then apply a multiline regex which means it is going to be scanning an rescanning multiple times. If it doesn't just die it would probably take a long time.
Better to just build a parser that reads each line and does it.
And of course the given example presumes that NO threads are in use. If they are then the it is not deterministically possible to correctly the parse the file because there is no thread indicator.