How to include protocal and request path in loggers | Community
Skip to main content
Level 3
June 12, 2023
Solved

How to include protocal and request path in loggers

  • June 12, 2023
  • 2 replies
  • 1203 views

request.log file contains request(method,protocal) and response (status code,response time) details same way I want to see these details in my other custom log file. Is there any configuation I need to add ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Umesh_Thakur

You can easily get those parameters from request.

As SlingHttpServletRequest is ServletRequest so it is having getProtocol() from ServletRequest. same way you can have other values as well from the request.

Hope this helps

Umesh Thakur

2 replies

Umesh_Thakur
Community Advisor
Umesh_ThakurCommunity AdvisorAccepted solution
Community Advisor
June 12, 2023

You can easily get those parameters from request.

As SlingHttpServletRequest is ServletRequest so it is having getProtocol() from ServletRequest. same way you can have other values as well from the request.

Hope this helps

Umesh Thakur

vijithaAuthor
Level 3
June 15, 2023

Hi @umesh_thakur 

Thanks for your info but my doubt is how we can add request URL and protocal to our custom log files.

EG:request.log file contains request(method,protocal) and response (status code,response time) details same way I want to see these details in my other custom log file. Is there any configuation I need to add ?

Umesh_Thakur
Community Advisor
Community Advisor
June 16, 2023

you will have your logger in your java file right?
there you will have these parameters from above explained methods and simply add those to the log level like info, debug etc.

but make sure you have enabled that logging level on system/console/slinglog console.

Hope this helps

Umesh Thakur

Sanjay_Bangar
Community Advisor
Community Advisor
June 12, 2023

Hi @vijitha ,

As mentioned by @umesh_thakur  you can get easily using SlingHttpServletRequest   and after you got the value in the servlet then you can add those value into logger.

Please refer 

https://sling.apache.org/apidocs/sling11/org/apache/sling/api/SlingHttpServletRequest.html