Search This Blog

Thursday 16 June 2011

extract Java stack traces from log4j logs

here is described a solution to retrieve from a Windows machine any errors and stack traces in log4j log files saved on a Solaris machine.
Results are filtered out by a given date, in this example 2011-06-16

1. download plink.exe and put in a new folder
2. in the same folder create a batch file with the following content

@echo off
plink.exe -v -ssh 127.0.0.1 -P 24 -l username -pw password -m cmd.txt > output.txt

3. in the same folder create the file cmd.txt with the following content

for file in `find logFolder -name "logfile.log*" -print`
do
echo $file
awk '{ if(($1 == "2011-06-16") && ($4 == "ERROR")){print $0; gl = getline row; while(gl > 0 && row !~ /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/){print row; gl = getline row;}} }' $file
done

No comments:

Post a Comment