Wednesday, October 17, 2007

Converting sysout to logger - entire application

We never worried about sysout statements in java, jsp codes, when we started development of web application in 2000. It has grown such a way that around 2000 files of java, jsp, js and html. User base also increased drastically from few hundreds to thousands. Always atleast 150 parallel sessions running on. This is just a history

One fine day, OOM (i love this term) Out Of Memory occured. This application has been migrated to tomcat and we disabled catalina.out by redirecting output to /dev/null. This is because catalina.out file started growing in GBs. Now how do we debug OOM, there is no out file :(

Here is where, we realised sysout issue. What a mistake, we should have used logger for this. Anyway how to solve? We discussed couple of options, writing a custom pearl script to comment out set of files. Take it as a manual tasks.

Luckily Eclipse has option to search and replace multiple files

  1. Check out all the files from repository
  2. Setup java project for application
  3. Select Search > File option
  4. Enter System.out.print as containing text
  5. File name patterns as “*”
  6. Click on Replace
  7. Enter "Logger.debug" as replace String
  8. Select replace all to replace in all files
  9. Update to repository and commit
Its done. We had compile error in some of the files and needed to include logger. Good tool :)

No comments: