0

I have implemented a HttpServlet that uses java.util.logging for leaving Log. Now I want that the Servlet leaves the Log inside a txt file.

I know the FileHandlers implements this functionality. Doubts:

  • Where I have to put the code that adds the FileHanlder to the Logger? by "where", I mean in which part of the code. I think that in the service() method is not correct at all.

     @Override
     protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    
              //  HERE???
      }
    
  • I want that the FileHandler is instanced only one time , so I have no locks problem with the txt file. How can I do that? Do you have any samples of code/recommendations?

Please forgive my bad explanation, but I am lost, and very noob in Java.

Catalina Island
  • 7,027
  • 2
  • 23
  • 42
X.Otano
  • 2,079
  • 1
  • 22
  • 40
  • http://stackoverflow.com/questions/960099/how-to-set-up-java-logging-using-a-properties-file-java-util-logging – kaos Oct 18 '16 at 11:11
  • ¿What about the place to add the implementation inside the Servlet? – X.Otano Oct 18 '16 at 11:13
  • http://stackoverflow.com/questions/1227292/setting-java-util-logging-destination-programmatically – kaos Oct 18 '16 at 11:17
  • If i place the FileHandler code inside service, a lot of log files are created. I just add: FileHandler fileTxt = new FileHandler(logDirectory+"/RetrieveServiceLog.txt",true); – X.Otano Oct 18 '16 at 12:29

0 Answers0