Results 1 to 11 of 11
  1. #1
    mousumidas is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default problem of logging in ejb3

    Hi,

    I am not able to log anything in from my ejb3.0 project. I am using log4j and weblogic 10.0 MP2. Please help.
    my log4j.properties is as follows:

    ### direct log messages to stdout ###
    #log4j.appender.stdout=org.apache.log4j.ConsoleApp ender
    #log4j.appender.stdout.Target=System.out

    #log4j.appender.stdout.layout=org.apache.log4j.Pat ternLayout
    #log4j.appender.stdout.layout.ConversionPattern=%d {ABSOLUTE} %5p %c{1}:%L - %m%n
    #log4j.rootLogger=debug, stdout
    #### Use two appenders, one to log to console, another to log to a file
    log4j.rootCategory=debug, R

    #### First appender writes to console
    log4j.appender.stdout=org.apache.log4j.ConsoleAppe nder
    log4j.appender.stdout.layout=org.apache.log4j.Patt ernLayout

    # Pattern to output the caller's file name and line number.
    log4j.appender.stdout.layout.ConversionPattern=%d{ ABSOLUTE} [%t] %5p %C{7}\:%L - %m%n

    #### Second appender writes to a file
    log4j.appender.R=org.apache.log4j.RollingFileAppen der
    log4j.appender.R.File=D:/ejbModuleLog.log

    # Control the maximum log file size
    log4j.appender.R.MaxFileSize=100KB
    # Archive log files (one backup file here)
    log4j.appender.R.MaxBackupIndex=5

    log4j.appender.R.layout=org.apache.log4j.SimpleLay out
    log4j.appender.R.layout.ConversionPattern=%d{ABSOL UTE} [%t] %5p %C{7}\:%L - %m%n

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    First create some test class
    that use logger and log to console
    just to see if everything is ok with log4j.jar and classpath.

    There are different approaches on using logger and way how you will configure
    it for use.

    First is using log4j.propertis,
    second is avoid using it and make your one class
    from log4j API classes which will to it's job.

    If you want to use log4j.properties you will have to find way to:

    create each property in proper format,

    decide where to place it in your code (...src folder),

    decide where to put it on web server after app deployment
    so your src classes can use it with no problem (...WEB-INF/classes),

    maybe you will have to put your log4.jar in webserver/lib
    or even in JRE/lib/ext to skip initializaion and classloader problems

    Be patient with this,
    and if you gonna use it often,
    i strongly suggest avoiding all this problems by simply creating your own class
    with log4j configuration

    good luck !

  3. #3
    mousumidas is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    I have usen log4j in another project but it is working fine. But when I am trying to use in ejb 3.0 module then it is not working. So I am confused how to use this in ejb project.

  4. #4
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    You have to describe your current configuration
    in project that works
    so people here have some start point in helping you to fix it for ejb

  5. #5
    mousumidas is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    I have build a dynamic web project. log4j-1.2.15.jar is added under WEB-INF\lib folder and log4j.properties is added in WEB-INF\classes folder.
    In my class I have added as follows:

    Logger log = Logger.getLogger(className.class);

    log.info(" ");
    These all are working fine for this project.

    But the same thing is not working in ejb project.
    I have tried so many things like changing folder structure ,etc.to solve the problem but still stuck on the problem.

  6. #6
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    OK, few more question about your config:

    IDE: Eclipse, Netbeans...?

    Web-Server/Servlet Container: Tomcat 5,6 ...?

    log4j version?

    Do you deploy app in from IDE in embedded
    Web-Server/Servlet Container automatically
    or you do some export to *.war

    Does Web-Server/Servlet Container in it's .../lib contains log4j.jar?

    Does your ...jre/lib/ext oontains log4j.jar ?

    Can you see any kind of error or exception in servers logs or in console...?

  7. #7
    mousumidas is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    Eclipse oepe-galileo-all-in-one-11.1.1.3.0.200909171310-win32
    Weblogic 10.0 MP2

    I need to make a log in my EJB project.So I can use any version compatible with the above.

    I have made a EAR project and it is deployed in weblogic application server.The code is error free but nothing has beed added in my log file.

  8. #8
    mousumidas is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    I am doing this 1st time with the help of google.Please tell me how should I solve this problem.

  9. #9
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    Looks like you will have to put some administration skills in this.

    Take a look here:

    Configuring WebLogic Logging Services

    Can u manage it using that ?

  10. #10
    mousumidas is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    I am not able to write any custom messages in the log file.Only server related information has been logged in the AdminServer.log
    Please help me out.

  11. #11
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    OK, i guess you are not much familiar with administration of WebLogic,
    so i offer you manual solution, that has to work independently of any
    web-server configuration.

    Be sure to read and study all steps in large comment
    at the beginning, just follow steps and you will have it running in 5 minutes !


    Java Code:
    import java.io.IOException;
    import java.util.ResourceBundle;
    
    import org.apache.log4j.ConsoleAppender;
    import org.apache.log4j.FileAppender;
    import org.apache.log4j.HTMLLayout;
    import org.apache.log4j.Level;
    import org.apache.log4j.Logger;
    import org.apache.log4j.PatternLayout;
    
    /**
     * README:
     * 
     * This example was tested on Dynamic web project file structure
     * on Windows using log4j-1.2.9.jar 
     * 
     * TO MAKE IT WORK:
     * 
     * 1.add log4j-1.2.9.jar to /web-inf/lib folder
     * 
     * 2. add jar to classpath
     * 
     * 3. manually create settings.properties file and place it in /src folder
     * 
     * 4. Enter (K,V) in settings.properties for path to your log file that will be created:
     * 	logPathHTML = C:\\temp\\somelog.html
     * 
     * 5. Run MyLoggerFactory for 1st test
     * 
     * 6. Using logger in your app:
     * To log in any class, user must create class field called log :
     * 		Logger log = MyLoggerFactory.getInstance().createLogger(MovieServlet.class); 			
     * 
     * Servlet example:
     * 
      	public class MovieServlet extends HttpServlet {
    	
    		Logger log = MyLoggerFactory.getInstance().createLogger(MovieServlet.class); 
     
    
      		public MovieServlet() {
            super();
            log.info("radi movie");
            log.debug("radi");
            log.error("radi");
            // TODO Auto-generated constructor stub
        }
      
     * TIP:
     * 
     * With this approach there is no need to add log5j-1.2.9.jar in 
     * servlet - container/lib or JRE/lib/ext folders
     * 
     * 
     * 
     */
    
    
    
    
    
    /**
     * factory Class for logger
     * <p>
     * 
     * Using this factory class, with settings.properties file 
     * excludes using of log4.properties
     * <p>
     * 
     * 
     * <p> 
     * Run to see usage of 2 appenders: console and HTML file
     * 
     *  * @author 
     *
     */
    public class MyLoggerFactory {
    	
    		
    	//HTMLappender
    	private FileAppender HTMLappender = null;
    	
    	private ResourceBundle bundle; 
    	
    	//default settings for appenders 
    	private String logPath;
    	private String logPattern;
    	private boolean logAppend;
    	private Level logLevel;
    		
    	//instanca
    	public static MyLoggerFactory instance = null;
    	
    	
    	/**
    	 * constructor - create factory, create log file, create log pattern , set log level
    	 */
    	private MyLoggerFactory(){
    		//settings.properties file is in src folder
    		bundle = ResourceBundle.getBundle("settings");
    		
    		//read logPathHTML key value from src/settings.properties, where path to log file in file-system is set 
    		logPath = bundle.getString("logPathHTML");
    		
    		//log pettern - edit it here instead of using log4j.properties
    		logPattern = "%d{HH:mm:ss} [%c{1}] %p - %m%n";
    		
    		//set log level: info, debug...
    		logLevel = Level.DEBUG;;
    		
    		logAppend = true;
    	}
    	
    	/**
    	 * Singleton for loger factory
    	 * @return  
    	 */
    	public static synchronized MyLoggerFactory getInstance(){
    		
    		if(instance == null)
    			instance = new MyLoggerFactory();
    		
    		return instance;
    	}
    	
    	
    	/**
    	 * add console appenderr do given logger
    	 * @param l
    	 */
    	private void addConsoleAppender(Logger log, String pattern){
    		
    		//pattern for writing to file
    		PatternLayout patternLayout = new PatternLayout(pattern);
    		ConsoleAppender console1 = new ConsoleAppender(patternLayout);
    
    		//adding appender and setting log level   
    		log.addAppender(console1);
    		
    	}		
    	
    	/**
    	 * add cached HTML appender to given logger.
    	 * 
    	 * If appender is not created yet, create appender with given params.
    	 * 
    	 * In order to make writing to HTML possible, you muast have 1 cached FileAppender for one HTML file
    	 * 
    	 * If you need more than one HTML file in one project, then cache new HTMLAppender as class filed
    	 * and write another method like this one for new appender
    	 * 
    	 * 
    	 * @param l
    	 * @param filePath
    	 * @param append
    	 */
    	private void addHTMLAppender(Logger l,String filePath, boolean append){
    		
    		try {
    			
    			//common HTMLAppender
    			if(HTMLappender == null){
    			
    				
    				
    			//create HTML appender
    			HTMLLayout  htmlLay = new HTMLLayout();
    			
    			//HTMLLayout htmlLay = new HTMLLayout();
    			HTMLappender = new FileAppender(htmlLay, filePath, append);
    			}
    			
    			l.addAppender(HTMLappender);
    			
    			
    		} catch (IOException e) {
    			System.out.println("HTML APPENDER NOT ADDED TO LOGER!!!");
    			e.printStackTrace();
    		}
    	}
    		
    	/**
    	 * creates logger with 2 appenders: console and HTML file
    	
    	 * @param clazz
    	 * @return
    	 */
    	public Logger createLogger(Class clazz){
    
    		//kreira i podesava loger za swing
    		Logger l = Logger.getLogger(clazz);
    		l.setLevel(logLevel);
    		
    		//add appenders
    		addConsoleAppender(l, logPattern);
    		addHTMLAppender(l,logPath,logAppend);
    		
    		//restrict adding of new appenders			
    		l.setAdditivity(false);
    		
    		return l;
    	}
    	
    	/**
    	 * main for test
    	 * @param args
    	 */
    	public static void main(String[] args) {
    						
    		//Logger log = Logger.getLogger(MyLoggerFactory.class);
    		Logger log = MyLoggerFactory.getInstance().createLogger(MyLoggerFactory.class);
    				
    		log.debug("debug");
    		log.error("error");
    		log.info("info");
    		
    							
    	}
    }

    As you can see there is no log4j.properties and
    configuration troubles

    Is this good enough?

Similar Threads

  1. ClassCastException: in EJB3
    By nida in forum Advanced Java
    Replies: 2
    Last Post: 07-03-2009, 03:03 PM
  2. Multiple Process Creation in EJB3.0
    By sankarguru in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 03-25-2009, 05:26 AM
  3. Quartz scheduling in EJB3
    By Niveditha in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 06-30-2008, 08:34 AM
  4. EJB3 question
    By bbq in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-04-2007, 08:58 AM
  5. Tables In Ejb3
    By Alan in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 05-10-2007, 04:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •