Rolling log Files & removing old log files

前端 未结 6 2085
长发绾君心
长发绾君心 2021-02-07 03:15

I am working on a Java SOAP based webservice application where I am writing stdout to a text file as log for our reference. That file is growing enormously, so I need to check f

6条回答
  •  自闭症患者
    2021-02-07 04:00

    I see a lot of answers telling you to use Log4J, but you can use Java's own logger to do this by simply creating a FileHandler:

    Handler handler =
        new FileHandler("%h/MyService-%g.log", 10 * 1024 * 1024, 10);
    handler.setLevel(Level.ALL);
    Logger.getLogger("").addHandler(handler);
    

提交回复
热议问题