• Post Reply Bookmark Topic Watch Topic
  • New Topic

logs are not capturing in external log file.  RSS feed

 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm facing one problem with my log4j configuration. It is not capturing the log files in "external log file"

# Root logger option
log4j.rootLogger=INFO,DEBUG, file

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender

#Redirect to Tomcat logs folder
#log4j.appender.file.File=${catalina.home}/logs/logging.log

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

====================================================================

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 java.util.logging.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.getName());


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());

       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();
      }   
}
}
=======================================================
Pom.xml
----------
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>



Thank you,
Sijesh
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Possibly whatever is running that code doesn't have a mapping for drive E.
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sijesh Alayaril wrote:# Root logger option
log4j.rootLogger=INFO,DEBUG, file

That doesn't look right - you should only have one debug level.  If you sepcify DEBUG, it will include INFO (and other more-critical debug levels).

I believe the syntax is:
    log4j.rootLogger=debug-level, appender-1, appender-2, appender-n
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sijesh Alayaril wrote:final static Logger log = Logger.getLogger(FileUploadManagedBean.class.getName());

Also, the getLogger method can also take a class, so you could just use Logger.getLogger(FileUploadManagedBean.class)

Less typing 
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul - I have done the mapping for drive E. Use can see that in my log4j.properties file,

log4j.appender.file.File=E:\\Virology_Lab\logs\Virologylogs.log

Anything more required for  configuration side please suggest.

Thank you.
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron - I did the changes that you mentioned above but even now log file configured is not capturing the logs and i'm getting the log details only in console.

Log file location - "E:\\Virology_Lab\logs\Virologylogs.log "


any other change i have to do.Please suggest?

Thank you.
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sijesh Alayaril wrote:log4j.appender.file.File=E:\\Virology_Lab\logs\Virologylogs.log


If you are going to use WIndows path notation, you will need to escape each directory separator backslash with another backslash:
    log4j.appender.file.File=E:\\Virology_Lab\\logs\\Virologylogs.log

Or, just use UNIX notation - it will work in Windows environments as well:
    log4j.appender.file.File=E:/Virology_Lab/logs/Virologylogs.log
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried above path but no luck. See my new log4j.properties

I'm i missing anything else Ron :-)

# Root logger option
#log4j.rootLogger=INFO, DEBUG, file
log4j.rootLogger=debug-level, appender-1, appender-2, appender-n

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender

#Redirect to Tomcat logs folder
#log4j.appender.file.File=${catalina.home}/logs/logging.log

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


 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like I wasn't clear when I said that the syntax is log4j.rootLogger=debug-level, appender-1, appender-2, appender-n.  You were meant to replace debug-level with the desired debug level (such as DEBUG), and the appenders with a list of names of log4j appender (such as file, console, etc.).

Your configuration should probably look something like this:
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sijesh Alayaril wrote:Paul - I have done the mapping for drive E. Use can see that in my log4j.properties file,

log4j.appender.file.File=E:\\Virology_Lab\logs\Virologylogs.log


I can see that you've used drive E in your configuration. And I expect you've mapped drive E for when you sign in. But perhaps this code is running in a server somewhere, as a Windows service. In that case you should investigate how drive E gets mapped for that service.
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Paul, I have deployed the application in the same machine.That is the reason the mapped with "E:\\Virology_Lab\\logs\\Virologylogs.log " instead of IP.
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>


 
Dave Tolls
Ranch Foreman
Posts: 2996
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sijesh Alayaril wrote: Yes Paul, I have deployed the application in the same machine.That is the reason the mapped with "E:\\Virology_Lab\\logs\\Virologylogs.log " instead of IP.


But is it running as your user.
I think that was the question.
If it's running as a service then it's quite likely that drive isn't mapped.
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:
Sijesh Alayaril wrote: Yes Paul, I have deployed the application in the same machine.That is the reason the mapped with "E:\\Virology_Lab\\logs\\Virologylogs.log " instead of IP.


But is it running as your user.
I think that was the question.
If it's running as a service then it's quite likely that drive isn't mapped.


If it's running as a Windows service under one of the default Windows service user ID's (which it almost certainly is) then that drive is definitely not mapped.

There are two steps to fix this:

1. Set up a user ID for the service to use, and reconfigure and restart the service.

That still won't use a mapped drive, though, even if that user ID is configured to automatically map the drive when somebody signs on with it. Step 2:

2. Change the log file name to use the Windows UNC convention: \computername\logs\Virologylogs.log (and don't forget to make sure that the user ID you set up in step 1 is permitted to access that remote machine and the folder where you're storing the logs).
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
    - In Step 2 - "Windows UNC convention: \computername\logs\Virologylogs.log " how come it knows the drive?
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't understand. In particular I don't understand "it" and "the drive". So, how come who understands what?
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If you want to find the UNC path for the network drive to use in step 2, use can use net use from the command line in the session where you have the E-drive mounted.  For example, on my workstation, I see:

The UNC path for my R-drive is \\192.168.100.10\users\home\ron
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried it. But there is no luck. Please see the below log4j file.

# 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=\\172.20.28.139\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
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And your service is now running under a specific network user ID (not "Local System Account" or the like) which has suitable permissions for that folder?
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Paul. My service is running in Local System and it has permission to access  the shared folder(I have confirmed it accessing from system as well). As guided above i have given the UNC path of my IP  address to rectify the issue.
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sijesh Alayaril wrote:Yes Paul. My service is running in Local System...


Sounds like you didn't change the user ID under which the service runs. Running it under the user ID "Local System account" is what I told you not to do.

In the service properties, click on the "Log On" tab and you'll see what I'm talking about.
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul- Please clarify below points

   - Could you please elaborate what service you mean here? I'm getting little bit confused on service(In my understanding Login User have a User name  and Password - It's the credential for my local system and all source code and share folder contains the log file comes under this credentials.).

  - Also as per your previous comment : there are something more need to change in the  system configuration level  for Login User  in order to fix the issue(As per my understanding, Please correct me if i'm wrong)?

  - If the log file in shared folder have accessed  in different machine, then why we need a  separate system configuration changes required?

 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought we had that all covered. Is the code you posted there not running in a Windows service?

(If you don't know, then perhaps you should consult with the person who manages the place where that code is running.)
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul - I have checked with network team here and came to know I'm not using any services apart form normal services( Asusual). It is default windows login and execution of the application.We don't have any service associated with the application that I'm running.
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So somebody sits down at a screen, signs on, and starts the application? I didn't understand the part about "default Windows login" -- I didn't think there was any such thing. But if there is, it's unlikely to map an E drive.
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand I'm missing something in Windows Services configuration level as you said. I'm investigating on that. Hope for the best.
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul - I had discussion with network team here and as suggested, I have shared a folder and given permission to 'everyone' for that folder(logs_virology),  in that scenario it should work right? But even logs are not generating.

Please see the log4j.properties
-----------------------------------
log4j.rootLogger = DEBUG, file
log4j.appender.fileout = com.veerasundar.log4j.LogLevelFilterFileAppender
log4j.appender.fileout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c - %m%n
log4j.appender.fileout.layout = org.apache.log4j.PatternLayout
log4j.appender.fileout.File = \\172.20.28.139\logs_virology\Virologylogs.log

Code is running in my system and it is deploying in tomcat server in same system.

Bean Class
-------------
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());

       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();
      }   
}
}


Please tell me where I'm doing mistake. Application is working fine, log file is creating problem now.

 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose I might as well give up then. Good luck with your project.
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However if you're prepared to deal with the issue I identified, don't hesitate to post back with answers to the questions I asked.
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies if i miss anything to communicate.

"So somebody sits down at a screen, signs on, and starts the application? I didn't understand the part about "default Windows login" -- I didn't think there was any such thing. But if there is, it's unlikely to map an E drive." -  Yes, application is started by the end user also code and server is in same machine and I'm trying to make link the share folder that is part of E drive(log4j.appender.fileout.File = \\172.20.28.139\logs_virology\Virologylogs.log) in my system.
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the command that the user types to start the server?
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sijesh Alayaril wrote:log4j.appender.fileout.File = \\172.20.28.139\logs_virology\Virologylogs.log

I think the path separator needs to be escaped:
    log4j.appender.fileout.File = \\\\172.20.28.139\\logs_virology\\Virologylogs.log
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One other thing you could try: write the logs to a directory on the machine where the server is running. If you still see no log entries then it probably means that no log entries are being produced; this would explain why you see no log entries in your remote folder.

Incidentally that's how I always used to set up servers when I was working. The server would log to a local folder, and anybody who wanted to see those logs would map a drive to that folder.
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul- I'm using Tomcat version 7 and here is the command to start the server.

F:\Workspace-Structs-Demo\apache-tomcat-7.0.73\bin>startup.bat

also server is integrated with my editor(eclipse: Neon 3)

In addition to this I'm attaching image for log.properties and it's location.


Ron - I have tried it, no luck.
log_and_Location.png
[Thumbnail for log_and_Location.png]
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sijesh Alayaril wrote:In addition to this I'm attaching image for log.properties and it's location.


And here I thought you would be telling us what was in the startup.bat script which the user runs. That would be more useful.
 
Paul Clapham
Sheriff
Posts: 22695
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:One other thing you could try: write the logs to a directory on the machine where the server is running.


Seems like you're going out of your way to avoid accepting help...
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"One other thing you could try: write the logs to a directory on the machine where the server is running. " - I have tried it as well. But this also not working.


 
Michael Ivanov
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! How do you "connect" your log4j properties file to your project? Using command line or placing file into resource folder?
 
Sijesh Alayaril
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, I have placed log.properties in resource folder.

  Is it mandatory, do i need both log4j.xml and log4j.properties file. At the moment i have only properties file. Also do i need to add any extra configuration level changes in web.xml file? please advise

 
Michael Ivanov
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you need to move log4j.properties to main/src/resources, then try to log  into filename:
log4j.appender.fileout.File = Virologylogs.log
just to verify that log records will appears in file.
Also try to change path separator from "\" to "/" (Ron McLeod advised it)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!