Monday, December 29th, 2008...10:32 am

Regular Expression to Replace System.out.println with Log4j

Jump to Comments

This is nothing fancy, but may help some of you log4j newbies.

I found myself replacing a project’s hideous System.out.println statements with log4j log calls.

Just do a File Search in eclipse , tick the regular expression box and do a Replace:

Find: System\.out\.println\(“(.+?)”\);

Now you just have to go in and add your imports and your log field variable to your classes.


  • Nice idea, but it does not account for the all to common case of:
    System.out.println(myClassName + “my quoted text” +
    myVar1 +
    myVar2 +

    So I tried this:

    which works fine… you ask why the {0,5}? because eclipse seems to choke on the greedier ‘+’ implementation. Perhaps a limitation in Eclipse.

  • Why don’t you just replace “System.out.println” with “”?

Leave a Reply