How to remove System.out.println's from codebase

前端 未结 8 1430
天涯浪人
天涯浪人 2020-12-15 11:26

We have a huge (old legacy java) code-base, where many files (around 5k) have System.out.println\'s. We are planning to remove them for cleanup/performance reasons. How can

8条回答
  •  星月不相逢
    2020-12-15 11:36

    Extending Oscar's concept you can do even better IMHO:

    if(!DEBUG) {
        System.setOut(
            new PrintStream(new OutputStream() {
                public  void    close() {}
                public  void    flush() {}
                public  void    write(byte[] b) {}
                public  void    write(byte[] b, int off, int len) {}
                public  void    write(int b) {}
    
            } );
        }
    }
    

    In this case, if you are not in debug mode or any other the default system out is replaced internally with devNull implementation, else it works as expected. This way you do not have to find and replace anything in your code.

提交回复
热议问题