Regsitering log4j appender to a logger in a class in a web app

During weblogic 9.2 server startup I would like to register a Handler with any number of log4j Loggers in all deployed web apps. I was thinking I could somehow get a reference to the applications classloader, and see if it has log4j, then register with the root logger. I used to do this in WLS 8, using ApplicationContainerFactory, but this is no longer available in WLS 9. Is there another way to do this in WLS 9? Thank for any help.

Thanks. I'm using a startup class. I could easily check if log4j is in the server classpath, and attach my appender. However, if log4j is not in server classpath, and in the application classpath, I need to check for this. I was using ApplicationContainerFactory in weblogic 8 like so:
appContainerFactory.getApplicationContainer(applicationName).getApplicationClassLoader()
which is not available in weblogic 9. And I can't find in the docs anywhere to indicate it's replacement, or any type of alternative.

Similar Messages

  • JMX-Log4j Appender problem

    Dear listers
    we wrote thefollowing code to log the loglevel's dynamically.
    Following is the code
    public class MyApp implements MyAppMBean {     
    private static Logger logger = Logger.getLogger(MyApp.class);
    public void go() throws Exception{
    while(true){
    logger.debug("DEBUG") ;
    logger.info("INFO") ;
    logger.warn("WARN");
    logger.error("ERROR");
    logger.fatal("FATAL");
    Thread.sleep(2000);
    public void setLoggingLevel(String level){
    logger.info("Setting logging level to: " + level);
    Level newLevel = Level.toLevel(level, Level.INFO);
    Logger.getRootLogger().setLevel(newLevel);
    public String getLoggingLevel(){                       
    return Logger.getRootLogger().getLevel().toString() ;
    public static void main(String[] args) throws Exception
    DOMConfigurator.configure("log4j.xml");
    MyApp app = new MyApp();
    //Lookup for the mbean server
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    //Create and register the top level log4j MBean
    HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
    ObjectName mbo = new ObjectName("log4j:logger=root");
    System.out.println("Debug10");
    server.registerMBean(hdm, mbo);
    LoggerRepository r = LogManager.getLoggerRepository();
    Enumeration<Logger> elogs = r.getCurrentLoggers();
    Logger logger = null;
    while(elogs.hasMoreElements())
    //need to show the elements of teamcenter only.
    logger = (Logger)elogs.nextElement();
    hdm.addLoggerMBean(logger.getName());
    } System.out.println(Logger.getRootLogger().getLevel().toString());
    int portNumber=9999;
    ObjectName htmlName = new ObjectName("log4j:logger=root,port=" + portNumber) ;
    HtmlAdaptorServer html = new HtmlAdaptorServer(portNumber);
    html.setPort(portNumber);
    server.registerMBean(html, htmlName);
    html.start();
    app.go();
    When setting the attributes for the appenders under log4j from htmladapter it gives the following message.
    *477 All Attributes Not Set*
    *1/8 attribute(s) were not set:*
    appender%3DTaskAppender%2Clayout%3Dorg.apache.log4j.PatternLayout
    Please advice how can we solve this issue ~Vilas

    Dear listers
    we wrote thefollowing code to log the loglevel's dynamically.
    Following is the code
    public class MyApp implements MyAppMBean {     
    private static Logger logger = Logger.getLogger(MyApp.class);
    public void go() throws Exception{
    while(true){
    logger.debug("DEBUG") ;
    logger.info("INFO") ;
    logger.warn("WARN");
    logger.error("ERROR");
    logger.fatal("FATAL");
    Thread.sleep(2000);
    public void setLoggingLevel(String level){
    logger.info("Setting logging level to: " + level);
    Level newLevel = Level.toLevel(level, Level.INFO);
    Logger.getRootLogger().setLevel(newLevel);
    public String getLoggingLevel(){                       
    return Logger.getRootLogger().getLevel().toString() ;
    public static void main(String[] args) throws Exception
    DOMConfigurator.configure("log4j.xml");
    MyApp app = new MyApp();
    //Lookup for the mbean server
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    //Create and register the top level log4j MBean
    HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
    ObjectName mbo = new ObjectName("log4j:logger=root");
    System.out.println("Debug10");
    server.registerMBean(hdm, mbo);
    LoggerRepository r = LogManager.getLoggerRepository();
    Enumeration<Logger> elogs = r.getCurrentLoggers();
    Logger logger = null;
    while(elogs.hasMoreElements())
    //need to show the elements of teamcenter only.
    logger = (Logger)elogs.nextElement();
    hdm.addLoggerMBean(logger.getName());
    } System.out.println(Logger.getRootLogger().getLevel().toString());
    int portNumber=9999;
    ObjectName htmlName = new ObjectName("log4j:logger=root,port=" + portNumber) ;
    HtmlAdaptorServer html = new HtmlAdaptorServer(portNumber);
    html.setPort(portNumber);
    server.registerMBean(html, htmlName);
    html.start();
    app.go();
    When setting the attributes for the appenders under log4j from htmladapter it gives the following message.
    *477 All Attributes Not Set*
    *1/8 attribute(s) were not set:*
    appender%3DTaskAppender%2Clayout%3Dorg.apache.log4j.PatternLayout
    Please advice how can we solve this issue ~Vilas

  • Log4j appender question

    I need some log4j help. Hope anyone can help me.
    Question 1:
    I need to log information to 4 different files. As far as I can tell from the log4j docs, I will then need to create 4 different appenders in the log4j.properties file. How can I do that?
    Looking at examples, it looks like I will need to add 4 new sections similar to this one. Is that correct?
    # Logfile 1
    log4j.appender.log1=org.apache.log4j.RollingFileAppender
    log4j.appender.log1.File=C:/Sun/logs/logme1.log
    Question 2:
    After that is done, how can I actually write to the files? When logging I was thinking just using: logger.info("log something").
    How can I specify which file that will log to? Is that even the correct way to log?
    Hope someone can help!

    After that is done, how can I actually write to the files? When logging I
    was thinking just using: logger.info("log something").
    How can I specify which file that will log to? Is that even the correct
    way to log?apperantly, it doesn't seem like you have understand how log4j works. that's probably why warnerja tell you to perform some search.
    understand the technology first..then ask specific question here.
    it will be useless just handling out answers to everyone. i think they're here just not to provides answers, but to educate other along the way...but they need to see an effort was made first.
    you're right..there are time when one doesn't have enough time to understand the whole technology..or the technology is too difficult to comprehend..or the documentation is poor., but i think there are plenty of good documentation on log4j. Futhermore..what you are asking is not usually shown in the documentation, but a google search would probably provides you with the answer you seek..you just need to find a good keyword.
    Futhermore, I suggest you read some tutorial on log4j if you plan to use the technology..it will not takes all day..maybe an hour or so..just to get how the technology works
    anyway,
    your appender tell the logger where the log the message to (depends on the level you specified) .. so if you have 3 appender that specified
    the level to be INFO, and you have logger.info("This is an INFO message"), then the message will be log to all three files.
    log4j.threshold=ALL
    log4j.rootLogger=ALL, stdout, DebugAppender, InfoAppender,
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%c %d{ISO8601} -- %p -- %m%n
    log4j.logger.DebugAppender.access=DEBUG
    log4j.appender.DebugAppender=org.apache.log4j.RollingFileAppender
    log4j.appender.DebugAppender.File=.${file.separator}log${file.separator}ex_debug.log
    log4j.appender.DebugAppender.MaxFileSize=10KB
    log4j.appender.DebugAppender.MaxBackupIndex=1
    log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.DebugAppender.layout.ConversionPattern=%c %d{ISO8601} -- %p --
    %m%n
    log4j.logger.InfoAppender.access=INFO
    log4j.appender.InfoAppender=org.apache.log4j.RollingFileAppender
    log4j.appender.InfoAppender.File=.${file.separator}log${file.separator}ex_info.log
    log4j.appender.InfoAppender.MaxFileSize=10MB
    log4j.appender.InfoAppender.MaxBackupIndex=2
    log4j.appender.InfoAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.InfoAppender.layout.ConversionPattern=%c %d{ISO8601} -- %p -- %m%nthe
    log4j.rootLogger=
    tell what appender to use...so include all your appender in this property.
    you appender specified the logging level INFO, WARN, DEBUG,
    ERROR, or FATAL. I'm not sure how to specified the min and max level
    for an appender using a property file..for xml configuartion file..look at
    the example provide in previous reply.
    now if you do :
    logger.info("This is an info message") and want it to log to file1 and file2
    and log.info("This is another info message") and you want this to log to file3
    you can't do that...a way around this is to create your own level..and the
    appender will specifies that level.
    if you plan to use an XML configuration file, then make sure you include the <root> node
    <root>
       <priority value="debug"/>
       <appender-ref ref="DEBUG"/> 
       <appender-ref ref="INFO"/>
       <appender-ref ref="MY_APPENDER_NAME"/>
    </root>
    </log4j:Configuration>

  • Reassign stderr/stdout to a Log4J appender.

    Does anyone know if there is a 'quick-and-dirty' way to reassign Java stderr and stdout to a Log4J Appender? Both Google and the log4j mailing lists are pretty sparse on this subject...

    This is the dirty way of doing it. If anyone knows
    the better way please mention it here.This is just putting a band-aid on a wound which will not be cured by a band-aid. It only masks the problem, and may introduce further problems (such as: What if you actually don't want to "log" certain things that were only intended for System.out?)
    The better way would be to re-design the code so that it logs messages to loggers rather than writing to System.out.
    I suspect the OP and you both know that, but just pointing it out in case.

  • Log4j, appender and InstantiationException

    Hi,
    I have written my own appender in an Eclipse project that uses log4j. When I try to use the appender I get the following exception:
    log4j:ERROR Could not instantiate class [test.appender.NewFileAppender].
    java.lang.InstantiationException: test.appender.NewFileAppender
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:329)
         at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:120)
         at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:629)
         at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:612)
         at org.apache.log4j.PropertyConfigurator.parseCatsAndRenderers(PropertyConfigurator.java:533)
         at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:417)
         at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:316)
         at org.apache.log4j.PropertyWatchdog.doOnChange(PropertyConfigurator.java:682)
         at org.apache.log4j.helpers.FileWatchdog.checkAndConfigure(FileWatchdog.java:88)
         at org.apache.log4j.helpers.FileWatchdog.<init>(FileWatchdog.java:57)
         at org.apache.log4j.PropertyWatchdog.<init>(PropertyConfigurator.java:674)
         at org.apache.log4j.PropertyConfigurator.configureAndWatch(PropertyConfigurator.java:382)
         at se.micronic.argos.main.Main.initLogging(Main.java:305)
         at se.micronic.argos.main.Main.<init>(Main.java:272)
         at se.micronic.argos.main.Main.main(Main.java:1339)
    log4j:ERROR Could not instantiate appender named "argos".My property file looks like this:
    log4j.appender.argos=test.appender.NewFileAppender
    log4j.appender.argos.file=logs/MArgos.logThe other appenders in the property file work fine.
    Any ideas?
    Thanks
    Markus

    could be you don't have a no-args constructor? show us the NewFileAppender class
    is that the entire stack trace? there's no other underlying exception being thrown?

  • LOG4J Appender  to Webservices

    Hello,
    I have a question.
    Is there an LOG4J Appender to Webservices?
    I founded a lot of kinds of appenders on www.apache.org, but nothing about webservices.
    Thanks for any help!!

    Thanks. I'm using a startup class. I could easily check if log4j is in the server classpath, and attach my appender. However, if log4j is not in server classpath, and in the application classpath, I need to check for this. I was using ApplicationContainerFactory in weblogic 8 like so:
    appContainerFactory.getApplicationContainer(applicationName).getApplicationClassLoader()
    which is not available in weblogic 9. And I can't find in the docs anywhere to indicate it's replacement, or any type of alternative.

  • Using log4j in User definied Extension Function java class

    Hi
    I am having a java class where I defined all the user defined XSL Functions.
    I used System.out.println for printing.
    But I want to use log4j. But when I use this to debug. It is not recognising only.
    Could you please tell me why this is not working in this class?
    Regards,
    Praveena

    Hi Anuj,
    I can see the below error in the default log file:
    09/08/11 16:25:21 log4j:ERROR A "org.apache.log4j.RollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
    09/08/11 16:25:21 log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
    09/08/11 16:25:21 log4j:ERROR [global.libraries:1.0] whereas object of type
    09/08/11 16:25:21 log4j:ERROR "org.apache.log4j.RollingFileAppender" was loaded by [oracle.bpel.common:10.1.3].
    09/08/11 16:25:21 log4j:ERROR Could not instantiate appender named "LOGFILE".
    09/08/11 16:25:21 log4j:WARN No appenders could be found for logger (oracle.sample.XSLFunction).
    09/08/11 16:25:21 log4j:WARN Please initialize the log4j system properly.
    log4j.properties file:
    # Set root category priority to INFO and its only appender to CONSOLE.
    log4j.rootCategory=INFO, LOGFILE
    # LOGFILE is set to be a File appender using a PatternLayout.
    log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
    log4j.appender.LOGFILE.File= C:/product/10.1.3.1/OracleAS_1/opmn/logs/XSLUtilExten.log
    log4j.appender.LOGFILE.Append=true
    log4j.appender.LOGFILE.Threshold=INFO,DEBUG
    log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.LOGFILE.layout.ConversionPattern=<%d>[%t] %p %C: %m%n
    log4j.appender.LOGFILE.MaxFileSize=40MB
    log4j.appender.LOGFILE.MaxBackupIndex=10
    Could you please tell me what is the problem?
    Edited by: Jakarta on Aug 11, 2009 4:16 AM

  • Logger.getLogger(myaction.class) method not found

    Hey, I want to use
    Logger logger = Logger.getLogger(myaction.class).
    I'm using JDev 10.1.2. I have added the log4j library in my project. But, I still not able to use getLogger(class).
    Logger class works but getLogger(myaction.class) is not found. Please help me to resolve this.

    Hey, I want to use
    Logger logger = Logger.getLogger(myaction.class).
    I'm using JDev 10.1.2. I have added the log4j library in my project. But, I still not able to use getLogger(class).
    Logger class works but getLogger(myaction.class) is not found. Please help me to resolve this.

  • Weblogic 10.1 web apps merge log4j log files into single log file

    Hi
    I have deployed multiple web applications on my weblogic (v 10.1 - JDK 1.5.0_12). I am using log4j-1.2.13.jar in a four different web applications.
    The location for the files are - WEB-INF\lib\log4j-1.3.13.jar and WEB-INF\classes\log4j.properties
    When I deployed all the four webapps in weblogic - we found that all of the apps started writing their logs into the logfile which is configured in the log4j of the first web apps log file. The "first web app" is the web app which is the first app deployed in weblogic.
    I have deployed all the four webapps in Tomcat and found that four separate log files get created. Hence, this problem is unique to Weblogic.
    Any suggestions on what the problem could be? I have been battling with this issue for over a week- and have exhausted all ideas.
    Thank you,
    Ronak S.

    Hi ,
    Read all about your issue here :
    Weblogic 10.0 and Log4j classpath problem
    Issue is that the Weblogic system classloader includes log4J already..
    Use "Filtering ClassLoader" a mechanism to configure deployment descriptors to explicitly specify that certain packages should always be loaded from the application, rather than being loaded by the system classloader.
    see: http://e-docs.bea.com/wls/docs100/programming/classloading.html#wp1097187
    Example:
    Add following to your META-INF/weblogic-application.xml
    <prefer-application-packages>
    <package-name>org.apache.log4j.*</package-name>
    </prefer-application-packages>
    Exclude all library packages used within your applcation to have full control over what is used by the application.
    regards,
    Kris

  • Creating  a static method returning Logger Object inside class

    Hello,
    Instead of creating Logger Instance in every class , can i do like this way by creating a static method in some class returning a Logger object , and using that method for getting instance of Logger in another class through that method
    Regards
    Mayur Mitkari

    On a related note, if you want to make it simpler, never do this:
    if (a == true)Instead, just do if (a)It's pointless and cluttersome to use == or != with true or false.
    // wrong
    if (a == true)
    if (a != false)
    // right
    if (a)
    // wrong
    if (a == false)
    if (a != true)
    // right
    if (!a)Also, note that
    if (x) {
      return true;
    else {
      return false;
    }can be simplified to return x;If you do that and change your variable to something a bit more meaningful, like trueCount or numTrue or something, your code would be
    int trueCount = 0;
    if (a) trueCount++;
    if (b) trueCount++;
    if (c) trueCount++;
    return trueCount >= 2;which is about as simple and clear as it can get, IMHO. Using less code doesn't necessarily make the code simpler or clearer. The idea is that someone reading the code can easily understand what it does.
    And note that the above can be easily generalized to "Are there at least M true values in this array/list of N booleans?" and still be concise and clear.

  • Logging with log4j in a Web app that uses TopLink

    The deployment engineer in my company is reporting problems with our first Web app that uses both log4j and TopLink. Apparently TopLink is failing to initialize correctly when log4j-1.2.8.jar is deployed to the WEB-INF/classes directory within the Web app.
    I know that 9iAS's Enterprise Manager uses an older version of log4j and I wonder if TopLink uses an older version too.
    Are there any known problems when using log4j 1.2.8 with TopLink 9.0.3?
    Thanks,
    Al Margheim

    Unfortunately, when I asked the deployment engineer for more information on the problem, he couldn't provide any, and since he moved the log4j library out of the application's WEB-INF\classes directory he can't reproduce the problem (whatever it was).
    Based on a variety of factors (including your response) I suspect that the people who encountered the problem misinterpreted the cause.
    If I can get him to put the log4j library back in WEB-INF\classes and get more specific information about the problem, and it still looks like a conflict between TopLink and log4j, I'll post the errors here.
    Thanks,
    Al Margheim

  • Log4j / Way to use any appender to get log4j logs into java logger logs?

    Hi,
    I've an older component, this use log4j.
    So I wonder if there any way to get log, logged by Log4J, into Java Logger logs?
    Thanks a lot!

    Thanks a lot, but this is not what i ment.
    I use glassfish. Glassfish uses for all log the Java Logger.
    My problem ist, that I have a library, that uses Log4J for logging.
    My current workaround is, to log all Log4J logs to console.
    Glassfish collect all "sysouts" and write them into the jave logger log file.
    But I wonder, if there is another way. I can't find any JavaLoggerAppender or something else.

  • Log4j appender

    hi,
    i have requirement wherein i must have logs generated for each 100 Mb but the rollover must not happen based on teh index. it must happen every 6 hours.
    so the logs must be generated as ,
    logging.log
    logging.log.1
    logging.log.2
    logging.log.3
    logging.log.15
    and after 6 hours, the rollover must start again.
    i am new to log4j, i want somebody to give some input or any pointerw where i can learn to do this sooner will be appreciated..
    thanks,
    aravind

    I seem to remember that someone contributed a TimeAndSizeRollingAppender to the Apache project. hava a google for it. ;-)

  • Log4j appender pipelining

    Hi there,
    Can I pipeline log4j appenders? Essentially, I have a custom AsyncAppender which I want feeding into DailyRollingFileAppender for file rollover purposes.
    How can I do that?
    Kind Regards,
    Zalle

    Hi there,
    Can I pipeline log4j appenders? Essentially, I have a custom AsyncAppender which I want feeding into DailyRollingFileAppender for file rollover purposes.
    How can I do that?
    Kind Regards,
    Zalle

  • Warning on logger of Beehive class

    Hi all,
    When starting Weblogic Network Gatekeeper, I always encountered warning against Log4j on one of Beehive's class as follows:
    log4j:WARN No appenders could be found for logger (org.apache.beehive.netui.pageflow.internal.AdapterManager).
    log4j:WARN Please initialize the log4j system properly.
    I have pointed the log4j configuration to the correct location of log4jconfiguration.xml, but the warning keeps poping up on me.
    Any help would be greatly appreciated.
    Regards,
    Setya

    Hi,
    Or you can try making a Validation View Object (VVO) for the VO that populates the advancedTable, and check if the mapped value is empty there...
    Hope it Helps!
    Thiago

Maybe you are looking for

  • When iTunes closes I get " iTunes has Stopped Working message"?

    iTunes works and runs fine on my Vista Ultimate system, however, every time I close iTunes I get a message stating that iTunes has stopped working. I havn't noticed any functionality loss, it's just that the dialog box is annoying. I just did a recen

  • Problems with Delete Rejected Photos

    I hope this hasn't been addressed earlier. I checked as far back as I had patience. I recently upgraded to a new Vista 64bit system. LR 64bit seems to "Not Respond" after I use the "delete rejected photos". Both instances the photos were deleted but

  • Uploading php files to server

    Hi. I would have thought my hosting provider could have helped me with this, but they could not. I have three different sites that i manage that are hosted at Interland. On one of these sites, when i upload a php file, and then try to bring this page

  • Viewing ratings while importing using the viewer

    Hello! When importing images in the Aperture import window using the viewer mode, is there a way to make Aperture show the rating of an image? (Some of my images have ratings given to them in-camera. They do show up perfectly AFTER the import. But it

  • IPhone SDK - Ideas for pop-up menus

    I have a screen where there are quite a few items which are of the multiple-choice type. In other platforms we use a combo box (pick lists) to do this. On the iPhone SDK the only thing that comes close is the UIPickerView which is too heavy IMHO. Cur