Ron,Paul - I'm i missing anything in the configuration. Still i haven't get anything in the log file configured. Here i'm adding all the codes.
Log4j.properties
------------------
# Root logger option
log4j.rootLogger=DEBUG, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=E:\\Virology_Lab\\logs\\Virologylogs.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Java Class File
----------------
package com.virology.lab.prism.bean;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.apache.log4j.Logger;
import org.primefaces.model.UploadedFile;
@ManagedBean
@SessionScoped
public class FileUploadManagedBean {
private final static Logger log = Logger.getLogger(FileUploadManagedBean.class);
// BasicConfigurator.configure();
UploadedFile file;
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public void dummyAction(){
log.info("Inside the method");
log.debug("this is a debug log message");
log.info("this is a information log message");
log.warn("this is a warning log message");
System.out.println("Uploaded File Name Is :: "+file.getFileName()+" :: Uploaded File Size :: "+file.getSize());
int nPos=-1;
int nPos1=-1;
int nPos2=-1;
String strDate=null;
String strSampleID=null;
String strRack=null;
String strPos=null;
String strExamType=null;
int nExamType=-1;
String strVal=null;
String strOps=null;
String strExamTime=null;
int x=-1;
DataInputStream dis = null;
BufferedReader br = null;
try {
/* Here BufferedInputStream is added for fast reading.*/
if(this.file!=null){
dis = new DataInputStream(this.file.getInputstream());
br = new BufferedReader(new InputStreamReader(dis));
}
String strLine;
strLine= (br!=null)?br.readLine():null;
if(strLine != null){
nPos=strLine.indexOf("|P|",0);
/*System.out.println("Values of nPos |P| is" );*/
}
if(nPos > -1) {
strDate = strLine.substring(nPos+3,nPos+3+14);
strDate=strDate.substring(4,6)+"/"+strDate.substring(6,8)+"/"+strDate.substring(0,4);
/*System.out.println("Values of strDate is" +strDate);*/
}
while ((strLine = br.readLine()) != null) {
x=-1;
if(strExamTime==null){
if(strLine != null){
nPos=strLine.indexOf("|2|");
/*System.out.println("Values of nPos |2| is" +strDate);*/
}
if(nPos > -1){
strExamTime=strLine.substring(nPos+3,nPos+3+14);
}
}
nPos=strLine.indexOf("O|1|",0);
/* System.out.println("Values of nPos 0|1| is" +strDate);*/
if (nPos>-1){
nPos = nPos+4;
nPos2 = strLine.indexOf("|",nPos);
if (nPos2>-1) {
strSampleID =strLine.substring(nPos,nPos2);
x=0;
nPos1=strSampleID.indexOf("CALIBRATOR",0)+strSampleID.indexOf("Pos",0);
if (nPos1>-1) {
x=1;
}else{
nPos1=strSampleID.indexOf("POS",0);
if( nPos1>-1 ){
x=1;
}
}
}
}
if (x==0){
try{
strRack= strLine.substring(nPos2+3,nPos2+5);
strPos= strLine.substring(nPos2+6,nPos2+7);
nPos = strLine.indexOf("||",nPos2+6);
strExamType = strLine.substring(nPos+2,nPos+3);
} catch(StringIndexOutOfBoundsException strexp){
strexp.printStackTrace();
}
try{
nExamType = Integer.parseInt(strExamType);
}catch(Exception exp){
exp.printStackTrace();
}
if (nExamType == 8 || nExamType == 1 ){
strExamType = "HIV";
System.out.println("Sample ID " + strSampleID + " has the Exam Type of " +strExamType +" in Rack " +strRack +" & Position " +strPos);
log.info("Inside HIV");
/*System.out.println("SampleID " +strSampleID "has the Exam Type of " +strExamType );*/
}else if( nExamType == 4 ){
strExamType = "HCV";
/*System.out.println("OutPut of the strExamType is " +strExamType);*/
/*System.out.println("Sample ID " + strSampleID + " has the Exam Type of " +strExamType);*/
System.out.println("Sample ID " + strSampleID + " has the Exam Type of " +strExamType +" in Rack " +strRack +" & Position " +strPos);
log.info("Inside HCV");
}else if (nExamType == 2) {
strExamType = "HBV";
/*System.out.println("OutPut of the strExamType is " +strExamType);*/
/*System.out.println("Sample ID " + strSampleID + " has the Exam Type of " +strExamType);*/
System.out.println("Sample ID " + strSampleID + " has the Exam Type of " +strExamType +" in Rack " +strRack +" & Position " +strPos);
log.info("Inside HBV");
}
strLine="";
while ((strLine = br.readLine()) != null) {
int t = strLine.indexOf("R|1|",0);
if(t > 0) {
StringBuffer sb = new StringBuffer(strLine);
strLine =sb.reverse().toString();
nPos = strLine.indexOf("|",0);
strVal = strLine.substring(nPos+16,nPos+20);
strOps = strLine.substring(nPos+1,nPos+2);
break;
}
}
}
}
// accessGroupService.saveAccessGroup(accessGroup);
br.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Maven Configuration for log4j
----------------------------------
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>