Tuesday 20 March 2018

What is log4j

What is log4j ? How can we implement it? Explain log4j property ?

 

1. Log4j is logging framework developed by Apache
2. There are few steps to implement it into the project .

Step1 : download log4j.jar from apache web site and set into class path . 


Step 2 : Create one log4j.properties and set into class path. 

log4j prop file should have following value with naming convention as shown below  :

log4j.rootLogger=ERROR, stdout, logfile // stdout to pring on console  , logfile to print log into file

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=logs/sample.log
log4j.appender.logfile.MaxFileSize=5MB
log4j.appender.logfile.MaxBackupIndex=3
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.logger.com.sample=DEBUG


That's it .. Here I have used two type of  appender  , console and file but there lot more also available to configure. Appenders are which helps to print log.

Converiosn patterns Layout decide the pattern of printing . d - date , p - type , c - class name , m - message , n - name

And last line is used for filtering and type according to your packages to make the decision of log printing.
Here under com.sample package all classes debug log message will print if log4j Logger has set into class as following :

private static Logger _log= Logger.getLogger("com.sample.tutorials.main.SpringMain");
_log.debug("test debug");

Note : XML (log4j.xml) is also another way to configure the log4j logger. 

Empty and null check in JSTL JAVA

Difference between empty and null check of JSTL Core tag

< c:if test="${param.name != null}">< /c:if>


The above tag is to check whether parameter name is null or not. If it is not null then it prints out the sentence and it prints nothing if the value is null.

< c:if test="${param.name ne null}">< /c:if>

A test shows that parameter name contains value of ${param.name} via "ne" operator

Above codes are working similarly with the previous codes. We just want to test JSP notation “ne” for not equal function as what “!=” does.

< c:if test="${not empty(param.name)}">< /c:if>



A test shows that parameter name contains value of ${param.name} via empty operator.

Above codes are another feature of JSP notation to check a value whether it is empty or not. It is basically pretty much the same as the second and third tag do. The difference lies on the value null and empty. 
  
So What is the difference between empty and null? 
  
Well, empty is not necessarily be null but null always be empty. Null means that the variable is simply not existed while empty means that the variable is existed and initialized but it contains nothing. Please be careful when dealing with null values as it may cause you the famous NullPointerException.

Friday 16 March 2018

How to Debug INSE Eclipse server or OutSide Eclpise Setting

Add following user variable
                CATALINA_BASE: D: \Liferay Developer Studio 1.5\liferay-portal-6.2.10-ee-ga1\tomcat-7.0.25
                CATALINA_HOME: D: \Liferay Developer Studio 1.5\liferay-portal-6.2.10-ee-ga1\tomcat-7.0.25
                JAVA_HOME:    C:\jdk1.7.0_20\bin
3. Go to following path:
D:\Liferay Developer Studio 1.5\liferay-portal-6.1.10-ee-ga1\tomcat-7.0.25\bin

4. Open startup.bat file
5. Add following line on top of this file
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket

6. Chance executable command as below on last of this file(user jpda start to start sever into jpda debug mode on port 8000)
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

Steps to make configuration into eclipse:
1. Open Eclipse
2. Go to Run Menu -> Debug configuration
3. Go to Remote java application on opend box at left side
4. Add project as “your  portlet” (select from browse button in connect tab)
5. Select connect type as Standard (socket attach)
6. Set connection property: localhost
7. Set Port:8000
8. Clickon Common Tab
9. Select Debug check box

Now click on Debug  to debug remote server on port 8000