Monday 18 January 2016

Enable and Disabled Log in Liferay

In our development time and in production we need to debug the functionality for resolve the issue.

Liferay gives OOTB logging functionality. Say I have ABController.java and  I want to get log of this class then create one static log variable in Java class.  

private static Log _log = LogFactoryUtil.getLog(ABController.class);

You have below option to log the value.

1. _log.debug() method  :  This log only can see when the debug option is selected for this class in control panel (we will see where you can change it)
2. _log.error() method : To display error message.
3. _log.info() method : This will always display log message.
4. _log.fatal() method : This will display fatal error message.
5. _log.warn() method : This message will display warnings.

You can enabled and disabled the log level of Class in Control panel. Go to  Control panel -> Server Administration -> Log Levels.   First search you class with full package in Update category tab and if you find the class then you can change log level from log level options. But if you don't find the Class then you can create your own category by click on Add category and add  your class with full specified path and select log level you want to select.

In production, more logs may create performance issue so generally We will use _log.debug() method. When we need to test on production then enable debug log level for this class and after completion of debugging reset it to Off.

Useful links:
 https://www.liferay.com/community/wiki/-/wiki/Main/How+to+configure+the+logs+in+Liferay

Saturday 9 January 2016

Run Script of code in Liferay

Hi All,

In our development time, some times we need check output of some methods of Util class or service class. Say I want to view all documents of group in Lifray then Liferay provides you run your lines of code in control panel.

Go to Control Panel -> Server Administration -> Script  and select Groovy for Java code.

Paste below lines of code to get all documents of group.

java.util.List<DLFileEntry>  dlFileEntryList =       com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.getGroupFileEntries(10167, -1, -1);

   for(com.liferay.portlet.documentlibrary.model.DLFileEntry fileEntry : dlFileEntryList){

                          out.println(fileEntry.getTitle());
                    }

Here 10167 is static value of group Id but you can get it the same way as above script.  

Click on Execute button and it will run above code and it will show all document title in page.


Same way you can run and check the out put of any code but make sure to use Class or Object with full specified path like  for DLFileEntry object I have used com.liferay.portlet.documentlibrary.model.DLFileEntry.