Tuesday, June 7, 2016

Logger in Liferay

Today we will see how to apply logger in our custom class. Here we create a custom class and add logger to it and then see how to set log level in liferay. 

So lets start this Step by Step:-

Step 1:-Create Liferay Project and Portlet

Just create a Liferay project and then create a generic portlet in it.

Step 2:-Change the Controller

Now open the java class and paste this:-

1)In line number 13 we create a object of Logger by using LogFactoryUtil .
2)Check line no 20 to 24 we use logger to call different methods like debug,error etc.

Step 3:-Add Category in Log Levels

Now Go to Control Panel->Server Administration->Log Levels
and Click on Add Category.Now provide the package name if you want to apply logger to all classes inside the package.But in my case their is only one class so i apply path till my Class:-


1)Here my Class name is Demo which is inside the package com.demo.
2)The drop down contain 7 values:-

  • OFF
  • WARN
  • INFO
  • ALL
They are in order of their priorities.
Ex- If you select INFO then INFO,WARN,ERROR and FATAL messages are shown.
Ex- If you select ERROR then only ERROR and FATAL messages are shown.

Step 4:-Check Output

Now deploy your portlet and add to the page.

1)I already selected INFO in log levels so my console shows INFO,WARN,FATAL and ERROR:-

2)Now Go to Control Panel->Server Administration->Log Levels
and Click on Update Categories and search your class by providing com.demo.Demo .Now change Log level to ERROR and click save:-

Now refresh the page where you add your portlet.As we select log level to ERROR so only ERROR and FATAL messages are Shown.

Note:- All you log are save inside server/logs/liferay.yyyy-mm-dd.txt file.

Hope this will Help....

Related Post:-

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!