2

Is it possible to create a user-defined level of log in java? If yes can someone give me an example?

I have an web application, and some web services exposed by the same. I want to create a new log file for every new request. Is there any way I can do it? If yes, please share the solution. Thank you in Advance :)

bibhu_bioit
  • 97
  • 1
  • 9
  • Depends on your backend. Why do you want to do this? – Thorbjørn Ravn Andersen Sep 13 '16 at 06:22
  • The web-services does some checks for the application which needs to be logged separately so that the user can verify the log for every check separately. Is there any way for the same? If it depends on backend, then what information may help you understand the application ? – bibhu_bioit Sep 13 '16 at 06:26
  • this post might help you http://stackoverflow.com/questions/2331128/log4j-one-log-file-per-request, you can achieve this through file appender, but it will occupy more physical space,, which you need to clear on timely basis, since the log files are created per request – pappu_kutty Sep 13 '16 at 06:31
  • logback can do this. I would suggest doing the splitting yourself afterwards - ensure that each log line contains information (like thread name etc) that you can use to detect with a small program that writes the files you need based on the common log file. – Thorbjørn Ravn Andersen Sep 13 '16 at 06:38

1 Answers1

2

You can use something like MDC(Mapped Diagnostic Context) in LOGBack. For WEB application javax.servlet.Filter can be used to set context values for every request.

example: http://logback.qos.ch/xref/chapters/mdc/UserServletFilter.html

Sergey Bespalov
  • 1,746
  • 1
  • 12
  • 29
  • this is not the kind of answers the site is looking for, this is a comment at best and a poor one at that and it is basically a "link only answer" as well which is pretty useless when the link dies. –  Sep 16 '16 at 08:30