This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

logs are not capturing in external log file.

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, already my log4j.properties are in resources folder and no luck this time as well. This issue killing  me!!.

Here I'm adding my changes,

log4j.properties
-----------------
log4j.rootLogger=INFO, fileOut, stdOut, error
log4j.appender.fileOut = org.apache.log4j.RollingFileAppender
log4j.appender.fileOut.File = F://Virologylogs.log
log4j.appender.fileOut.MaxFileSize=10MB
log4j.appender.fileOut.MaxBackupIndex=10
log4j.appender.fileOut.layout=org.apache.log4j.PatternLayout
log4j.appender.fileOut.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Direct log messages to stdout
log4j.appender.stdOut=org.apache.log4j.ConsoleAppender
log4j.appender.stdOut.Target=System.out
log4j.appender.stdOut.layout=org.apache.log4j.PatternLayout
log4j.appender.stdOut.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


Pom.xml
----------

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>VIROLOGY-PRISM</groupId>
 <artifactId>VIROLOGY-PRISM</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>

<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>;
<layout>default</layout>
</repository>
</repositories>

<dependencies>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- Faces Implementation -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.4</version>
</dependency>

<!-- Faces Library -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.4</version>
</dependency>
<!-- Primefaces Version 5 -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
<!-- JSP Library -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- JSTL Library -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>

</project>

ManagedBean
----------------

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 org.apache.log4j.Logger;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.primefaces.model.UploadedFile;

@ManagedBean
@SessionScoped
public class FileUploadManagedBean {

final static Logger log = Logger.getLogger(FileUploadManagedBean.class);

UploadedFile file;

public UploadedFile getFile() {
return file;
}

public void setFile(UploadedFile file) {
this.file = file;
}


public void dummyAction(){

System.out.println("Uploaded File Name Is :: "+file.getFileName()+" :: Uploaded File Size :: "+file.getSize());


if(log.isInfoEnabled()){
log.info("This is info : ");
}

log.warn("This is warn : ");
log.error("This is error : ");
log.fatal("This is fatal : ");


      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;
     
      log.info("Inside method");
      log.debug("In Debug mode level");
      log.trace("ddddddddddddd");
       
       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);
                      /*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);
            }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);
            }                                              
             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();
     }    
}
}

I'm not understanding what blocking to capture the log here?

Log4j_Location.png
[Thumbnail for Log4j_Location.png]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean src/main/resources, not src/main/resources/log
 
Sijesh Alayaril
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

     Michael, Already log4j.properties files are in resources folder. But it's not logging anything still.

Please see the below details,

log4j.properties
------------------
log4j.rootLogger=INFO, fileOut, stdOut, error
log4j.appender.fileOut = org.apache.log4j.RollingFileAppender
log4j.appender.fileOut.File = F://Virologylogs.log
log4j.appender.fileOut.MaxFileSize=10MB
log4j.appender.fileOut.MaxBackupIndex=10
log4j.appender.fileOut.layout=org.apache.log4j.PatternLayout
log4j.appender.fileOut.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Direct log messages to stdOut
log4j.appender.stdOut=org.apache.log4j.ConsoleAppender
log4j.appender.stdOut.Target=System.out
log4j.appender.stdOut.layout=org.apache.log4j.PatternLayout
log4j.appender.stdOut.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


Pom.xml
----------

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>VIROLOGY-PRISM</groupId>
 <artifactId>VIROLOGY-PRISM</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>

<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>;
<layout>default</layout>
</repository>
</repositories>

<dependencies>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- Faces Implementation -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.4</version>
</dependency>

<!-- Faces Library -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.4</version>
</dependency>
<!-- Primefaces Version 5 -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
<!-- JSP Library -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- JSTL Library -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>

</project>


FileUploadManagedBean.java
---------------------------------

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 org.apache.log4j.Logger;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.primefaces.model.UploadedFile;

@ManagedBean
@SessionScoped
public class FileUploadManagedBean {

final static Logger log = Logger.getLogger(FileUploadManagedBean.class);

UploadedFile file;

public UploadedFile getFile() {
return file;
}

public void setFile(UploadedFile file) {
this.file = file;
}


public void dummyAction(){

System.out.println("Uploaded File Name Is :: "+file.getFileName()+" :: Uploaded File Size :: "+file.getSize());


if(log.isInfoEnabled()){
log.info("This is info : ");
}

log.warn("This is warn : ");
log.error("This is error : ");
log.fatal("This is fatal : ");


      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;
     
      log.info("Inside method");
      log.debug("In Debug mode level");
      log.trace("ddddddddddddd");
       
       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);
                      /*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);
            }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);
            }                                              
             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();
     }    
}
}


web.xml
---------
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5" metadata-complete="true">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>

<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<welcome-file-list>
   <welcome-file>fileUpload.xhtml</welcome-file>
</welcome-file-list>

</web-app>



 
Michael Ivanov
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you attach your build log?
 
Why is the word "abbreviation" so long? And this ad is so short?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!