Basically my requirement/need is to capture some snippet of the logs from a log file (or in other words parse log file)and then check if that portion is a valid JSON also.
Any pointers?
2 Answers
Use awk
to search that portion for:
- open brace,
- key value pairs
- close brace
That's for just 1 level, you'll need to develop it for more levels such as shown at
Nothing to do with selenium for log parsing. you need to use java/perl/python which ever language your are using for writing selenium test scripts. But i implemented this kind of funtionality to check application logs. While implementing this you need to check following: 1. whether your application logs are generated with proper delimiters to indicate each row ? 2. Selenium test script and the application runs on same machine or different machine? 3. application runs on linux machine or windows?
in general any application or any server logs will use some rotation feature to split the logs to chuncks.
also it takes huge time to parse large log files.
so my advise is ,before starting the test ,using jsch library connect to remote server and start tailing the log and redirect to a temporary file and run this tailing command in background job.
now run another shell command over ssh connection using jsch and get the process id of background task and save it in a variable.
then perform your steps on application using selenium and this will generates application logs and the tailed log contains this information alone,it takes less time to parse small log file and also you can get rid of log rotation problem. now run anothet command over ssh connection and stop tailing the log and search thr temporary file for required pattren this also you can perform using via ssh connection using jsch library
you can get the string to local via ssh connection and you can assert for required log hope it helps
_rajendra
-
on modern machines it doesn't take huge time to parse huge files, well depending on your definitions. We parse 1G files in a few seconds.– RsfCommented Nov 15, 2016 at 9:19
awk
because the format has blocks spanning multiple lines