Friday 19 December 2014

Watch your CQ Logs


There are times when you need to check cq server logs however you don't have access to the machine through vnc/putty, possible use cases could be QA/UAT environments where developers generally don't have machine rights. You will be left with option to asking for huge log files or viewing logs in browser via crxde console logs. Accessing logs this way could be very limiting as it won't show previous logs also it will show too many irrelevant logs which you may not be interested into.

There are few things that you can do to be able to view relevant logs via browser.

  • CQ provides CRXDELogServlet (com.day.crx.ide.CRXDELogServlet) which can be used with tail parameter to read limited number of lines. e.g. Hitting http://localhost:4502/bin/crxde/logs?tail=N will give last N lines of error log. This servlet is the one which reads error log and outputs retrieved lines to CRX console.
  • Add logger configuration to create different log file for your logger and then modify "Apache Sling Logging Configuration" to point to new log file. Say e.g. if your are only interested in logs of package com.example.util, create a logger configuration through osgi to log into separate logs/mylog.log file. Update "Apache Sling Logging Configuration" to point to logs/mylog.log. Now hitting http://localhost:4502/bin/crxde/logs?tail=N will read mylog.log file and display last N lines from it.






  • Write your own tool to read the log files. One of our clients needed functionality to have multiple log files and a way to allow admin users to view separate logs via browser. Though CRXDELogServlet provides basic log viewing capabilities it only allows a single log file configured in "Apache Sling Logging Configuration". We wrote another Servlet which can take log file name and lines to tail in request parameters and display lines from it. I will post code snippets in another post.


References:
http://sling.apache.org/documentation/legacy/logging.html

1 comment: