1

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?

3
  • Application server logs. I want to do it using Selenium. By use case I mean "my need is".
    – R11G
    Commented Nov 4, 2016 at 23:11
  • Sorry. I didn't mean to imply Selenium has to be used for it. I realize awk or sed can be used to parse the logs and get my problem solved.
    – R11G
    Commented Nov 11, 2016 at 18:31
  • awk because the format has blocks spanning multiple lines Commented Nov 13, 2016 at 0:24

2 Answers 2

1

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

http://json.org/example.html

2

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

1
  • 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.
    – Rsf
    Commented Nov 15, 2016 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.