Log4j multiple loggers

I was curious if anyone has been able to get multiple log4j loggers to work with weblogic? I have configured my domains
to use log4j for logging and it appears to be functioning correctly. I am trying to use multiple loggers to send send system logs to the localhost and auditing log events to a remote host (using log4j syslogappender). A subset of my log4j.properties is shown below
system.log.level=DEBUG
log.dir=Logs
max.filesize=10MB
log4j.rootLogger=${system.log.level}, systemLogFile, stdout
log4j.logger.audit=INFO, syslog
log4j.additivity.audit=false
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.SyslogHost=RemoteAuditRepositoryHost
log4j.appender.syslog.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.syslog.layout.ConversionPattern=%d{${datestamp}} [%t] %-5p %c : %m%n
log4j.appender.syslog.Facility=local2
If I use this configuration the syslogd on my remote host receives nothing. I can get it too work if I move the syslog appender
into the root logger but then it receives a lot of other logging Id rather not receive. I am using log4j 1.2.16 and Weblogic 10.3.

Here's my test version that works correctly:class SubClass {
  private Logger log;
  public SubClass(String name) {
    // Create the appender
    RollingFileAppender appender = new RollingFileAppender();
    appender.setLayout(new PatternLayout("%d{DATE} %-5p [" + name
                    + "] - %m%n"));
    appender.setFile("C:/temp/" + name + ".txt");
    appender.activateOptions();
    // Create logger
    log = Logger.getLogger("SubClass." + name);
    log.addAppender(appender);
  public void writeToLog(String txt) {
    log.info(txt);
}I don't have this "policy" business in my version of Log4J so I simplified your code a bit. My version produces two different log files with one line in each file.

Similar Messages

  • Log4j and multiple loggers/appenders

    Hello,
    I have a class that is instantiated multiple times. Each instance needs to write to a separate file which has to be rolled daily.
    The example below instantiates SubClass twice; both log files are created successfully -2007-05-09_sc1.log and 2007-05-09_sc2.log-, but the output goes only to 2007-05-09_sc2.log with the following:
    09 May 2007 15:00:05,953 INFO [sc2] - writing to class sc1
    09 May 2007 15:00:05,953 INFO [sc2] - writing to class sc2
    ... while 2007-05-09_sc1.log is empty.
    Could someone please point out what am I doing wrong?
    Thanks in advance.
    import org.apache.log4j.Logger;
    import org.apache.log4j.PatternLayout;
    import org.apache.log4j.rolling.RollingFileAppender;
    import org.apache.log4j.rolling.TimeBasedRollingPolicy;
    public class LogTest
        public static void main(String[] args)
            SubClass sc1 = new SubClass("sc1");
            SubClass sc2 = new SubClass("sc2");
            sc1.writeToLog("writing to class sc1");
            sc2.writeToLog("writing to class sc2");
    class SubClass
        private String name;
        private static Logger log;
        public SubClass( String name )
            this.name = name;
            // Create policy
            TimeBasedRollingPolicy policy = new TimeBasedRollingPolicy();
            policy.setFileNamePattern("logs/%d{yyyy-MM-dd}_" + name + ".log.zip");
            policy.activateOptions();
            // Create the appender
            RollingFileAppender appender = new RollingFileAppender();
            appender.setLayout(new PatternLayout("%d{DATE} %-5p [" + name+ "] - %m%n"));
            appender.setRollingPolicy(policy);
            appender.activateOptions();
            // Create logger
            log = Logger.getLogger("SubClass." + name);
            log.addAppender(appender);
        public void writeToLog( String txt )
            log.info(txt);
    }

    Here's my test version that works correctly:class SubClass {
      private Logger log;
      public SubClass(String name) {
        // Create the appender
        RollingFileAppender appender = new RollingFileAppender();
        appender.setLayout(new PatternLayout("%d{DATE} %-5p [" + name
                        + "] - %m%n"));
        appender.setFile("C:/temp/" + name + ".txt");
        appender.activateOptions();
        // Create logger
        log = Logger.getLogger("SubClass." + name);
        log.addAppender(appender);
      public void writeToLog(String txt) {
        log.info(txt);
    }I don't have this "policy" business in my version of Log4J so I simplified your code a bit. My version produces two different log files with one line in each file.

  • Java.util.logging - different log files for different loggers

    I'm having trouble configuring Java logging to use different log files for different loggers.
    In log4j, I would do this by configuring multiple loggers each with a different appender. But how can I do this with Java (java.util.logging) logging?
    This is the basic idea of what I'd like to do:
    com.mycompany.app1.level = FINEST
    com.mycompany.app1.<log file> = logfile1.log
    com.mycompany.app2.level = ALL
    com.mycompany.app2.<log file> = logfile2.log
    Any suggestions?

    This kind of thing?
    import java.io.IOException;
    import java.util.logging.FileHandler;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.logging.SimpleFormatter;
    public class LogTest {
        private Logger app1;
        private Logger app2;
        public LogTest() {
            // setup loggers
            try {
                // first logger
                app1 = Logger.getLogger("com.mycompany.app1");
                FileHandler filehandler = new FileHandler( "logfile1.log" );
                filehandler.setFormatter(new SimpleFormatter());
                app1.addHandler(filehandler);  
                // second logger       
                app2 = Logger.getLogger("com.mycompany.app2");
                filehandler = new FileHandler( "logfile2.log" );
                filehandler.setFormatter(new SimpleFormatter());
                app2.addHandler(filehandler);  
            } catch(IOException ioex) {
                ioex.printStackTrace();
        private void logStuff() {
            app1.log(Level.SEVERE, "a message for log 1");
            app2.log(Level.SEVERE, "a message for log 2");
            app2.log(Level.WARNING, "another message for log 2");
         * @param args
        public static void main(String[] args) {
            new LogTest().logStuff();
    }

  • How to set up multiple log4j configurations for multiple WAR packages?

    hi all,
    the EAR that i am trying to deploy has multiple WARs.
    I need to configure separate loggers for each these WARs.
    Could any of experts can help me out.

    Hi
    Depending on your needs, you may find that Set level offers the best approach:
    Within a Set you have the Playbacks (Set Level, so they work for the entire set) with individual patches in the set "live" for the EWI etc as needed.
    You need only map one set of controls for all the Playbacks since only 1 set can run at a time.
    CCT

  • Log4j - logging to multiple files

    Hi,
    Is there a way to do this? I have a class in a shared package in which I want to log into a separate log file.
    I'm using the text configuration file - not the xml one.
    I tried this (a suggestion from google):
    log4j.rootLogger = ERROR, WebLog
    log4j.category.se.aftonbladet.elitserien=ERROR
    log4j.category.org.apache.struts2=ERROR
    log4j.category.org.apache=ERROR
    log4j.category.catalia=ERROR
    # An extra category to a log file
    log4j.category.AlternativeLog=A3
    log4j.appender.stdout = org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.Threshold = DEBUG
    log4j.appender.stdout.Target   = System.out
    log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern = %d{ISO8601} %-5p [%F:%L] : %m%n
    log4j.appender.WebLog = org.apache.log4j.RollingFileAppender
    log4j.appender.WebLog.file = /opt/tomcat/logs/elitserienservice.log
    log4j.appender.WebLog.MaxFileSize=2048KB
    log4j.appender.WebLog.MaxBackupIndex = 5
    log4j.appender.WebLog.layout = org.apache.log4j.PatternLayout
    log4j.appender.WebLog.layout.ConversionPattern = %d{ISO8601} %-5p [%F:%L] : %m%n
    # A3 is set to be a FileAppender which will log all actions in the application.
    log4j.appender.A3=org.apache.log4j.RollingFileAppender
    log4j.appender.A3.file=/opt/tomcat/logs/elitserienservice_alt.log
    log4j.appender.A3.MaxFileSize=2048KB
    log4j.appender.A3.MaxBackupIndex = 5
    log4j.appender.A3.layout=org.apache.log4j.PatternLayout
    log4j.appender.A3.layout.ConversionPattern=%d{ISO8601} %-5p [%F:%L] : %m%nAnd in my class I get my logger like this:
    private static final Logger logger = Logger.getLogger("AlternativeLog");But it doesnt work. All logging still ends up in the 'elitserienservice.log'.
    Any help much appreciated!
    /best regards, Håkan Jacobsson

    log4j loggers/categories are additive by default. If you write a message to the "AlternativeLog" logger, log4j will first pass that message to all appenders that are attached to the "AlternativeLog" appender. After that, log4j will pass that same message to all appenders that are attached to any 'parent' loggers/categories. In your example, the only 'parent' logger above the "AlternativeLog" is the root logger.
    To alter this behavior, you'll need to set the additivity property to false on the "AlternativeLog" logger. Something like this should do the trick:
    log4j.additivity.AlternativeLog=false
    FYI... For better responses to log4j inquiries, you should post your questions to the log4j users mailing list ([email protected])
    http://logging.apache.org/mail-lists.html

  • Multiple log4j.xml files for single application.

    Hi All,
    How to use multiple log4j.xml files for single application?
    I do have a pluggable application modules. ie, If I add a jar I will get some functionalities. Like that i do have many jars.
    Log4j.xml also will be present in that jar only. So if I add multiple jar files like this, I will get multiple log4j.xml files. What should I do?

    Each logger can have its own file I think. Check the log4j documentation.

  • Log4j - creating 2 loggers

    I'm having trouble with log4j. I want to create 2 loggers to log to 2 seperate files. I've read the documentation at http://logging.apache.org/log4j/1.2/manual.html but it is too brief and only covers basic logging using a single logger. I've read all the articles recommended in http://logging.apache.org/log4j/1.2/publications.html but they seem mainly to be a rehash of the manual page.
    Does anybody know where I can find good, detailed documentation of log4j, or maybe they can point out why my test app isn't working.
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;
    public class LogTest
       public static void main(String[] args)
          Logger logger1 = Logger.getLogger("Logger1");
          Logger logger2 = Logger.getLogger("Logger2");
          PropertyConfigurator.configure("log4j.properties");
          logger1.info("logging to logger 1");
          logger2.info("logging to logger 2");
    }Contents of my log4j.properties file;
    #Define logger 1 as A1
    log4j.Logger1=A1
    #Configure A1
    log4j.appender.A1=org.apache.log4j.FileAppender
    log4j.appender.A1.File=log1.log
    log4j.appender.A1.Append=true
    log4j.appender.A1.Threshold=INFO
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss dd/MM/yyyy} [%t] %-5p %c %x - %m%n
    #Define logger 2 as A2
    log4j.Logger2=A2
    #Configure A2
    log4j.appender.A2=org.apache.log4j.FileAppender
    log4j.appender.A2.File=log2.log
    log4j.appender.A2.Append=true
    log4j.appender.A2.Threshold=INFO
    log4j.appender.A2.layout=org.apache.log4j.PatternLayout
    log4j.appender.A2.layout.ConversionPattern=%d{HH:mm:ss dd/MM/yyyy} [%t] %-5p %c %x - %m%nWhen I run I get;
    log4j:WARN No appenders could be found for logger (Logger1).
    log4j:WARN Please initialize the log4j system properly.and no log files are created.
    Edited by: Nelbins on 30-Apr-2008 12:30

    to associate a Logger with an appender you need something like this:
    log4j.logger.Logger1=DEBUG,A1
    log4j.logger.Logger2=INFO,A2I.e. prefix the Logger name with "log4j.logger" and use "<logger level>,<appender>" as the value.

  • Multiple log4j jars of different versions in classpath

    Hi,
    Does having multiple log4j jars in the classpath of different versions cause problem. If I have both log4j-1.2.14.jar and log4j-1.2.15.jar in my classpath will that cause a problem.
    I have a scenario where in the production env. servers hung and when I checked the classpath it had both the above log4j jars. Could it be an reason for server hanging?
    Thanks
    AA

    Hi GP,
    Thanks for all the help again.
    2.How to ensure the existing user updates /new user creations that comes from OID 10g propagate to OID 11g as well? Please suggest the steps likely involved in OIM 11g configuration.
    3.Also need to ensure the password changes propagates from OID 10g to OID 11g after the above configurations. Please suggest ways for this as well.
    ->>>PLease clear your requirement. Do you want to transfer data from OID 10g to OID 11g via OIM? If yes configure OID 11g as trusted source and trusted source reconciliation bring OID 10g data to OIM and OIM will propogate it to OID 11g.
    I think you are looking for LDAPSync between two OIDs. You can refer its documentation to configure LDAP sync, so whatever changes are done in 10g will be propagated to OIM 11g.
    ->>>>>>>>>>Yes I want all the users that were once created in OID 10g should also be propagated on OID 11g under a similar context/orgs. Also if any change / modification in the existing user happens on OID 10g should propagate the changes for the same user on OID 11g. Please guide me how to configure trusted source in OIM 11g?
    Also can you please point LDAPSync document (for propagate changes for user passwords from OID 10g to OID 11g user). I understand that you are suggesting for the same purpose? Please correct me if am wrong.
    Thanks again.

  • How can I get log4j to write out to multiple logs?

    Hi,
    How can I get log4j to write out to multiple logs?
    Pls help me out.
    Thanks

    yawmark wrote:
    Harikesh wrote:
    Thanks@ gimbal2
    for giving valuable url.You should also type your question directly into Google. You might be pleasantly surprised by the results.
    ~Or not... [When tech support goes horribly wrong|http://www.cracked.com/video_16937_when-tech-support-goes-horribly-wrong.html] (cracked.com video)

  • Log4J and Multiple Servers

    Hi, I'm just wondering is there a way that I could have multiple servers running and writing/appending to the same log file?? Java seems to lock for writing and no other servers can append.

    Sure. Centralize your logging by setting up another server whose only purpose is to write to that log file. Have all the other servers send their logs to that server. Log4J provides a SimpleSocketServer and a SocketAppender for exactly that purpose.

  • Log4j in multiple clusters in the same machine

    Hi,
    i use log4j and i'm having some problems with my log files. I have two clusters in the same machine. How can i have the logs independent of each other. Now i have one cluster jamming the log of the other cluster. I want this doesn't happen, i want they log separately. How can i do it?
    Many thanks in advance,
    Nuno

    nfalmeida wrote:
    Hi,
    i use log4j and i'm having some problems with my log files. I have two clusters in the same machine. How can i have the logs independent of each other. Now i have one cluster jamming the log of the other cluster. I want this doesn't happen, i want they log separately. How can i do it?
    I hope you have configuration files that configure log4j? The applications/clusters shouldn't use the same configuration.

  • Multiple log files using Log4j

    Hello,
    I want to generate log files based on package structure. Like com.temp.test in test.log ,also I am having a log file at application like app.log .
    This is my requirement what has been logged in test.log should not be logged in app.log.This is my log4j.properties file.
    # Log4j configuration file.
    # Available levels are DEBUG, INFO, WARN, ERROR, FATAL
    # Default logger
    log4j.rootLogger=DEBUG, PFILE
    log4j.logger.com.temp.test=DEBUG,TEST
    # PFILE is the primary log file
    log4j.appender.PFILE=org.apache.log4j.RollingFileAppender
    log4j.appender.PFILE.File=./App.log
    log4j.appender.PFILE.MaxFileSize=5120KB
    log4j.appender.PFILE.MaxBackupIndex=10
    #log4j.appender.PFILE.Threshold=DEBUG
    log4j.appender.PFILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.PFILE.layout.ConversionPattern=%p %d[%l][%C] %m%n
    #log4j.appender.PFILE.layout.ConversionPattern=%p %d %m%n
    log4j.appender.TEST=org.apache.log4j.RollingFileAppender
    log4j.appender.TEST.File=./test.log
    log4j.appender.TEST.MaxFileSize=5120KB
    log4j.appender.TEST.MaxBackupIndex=10
    log4j.appender.TEST.layout=org.apache.log4j.PatternLayout
    log4j.appender.TEST.layout.ConversionPattern=%p %d[%l][%C] %m%n
    Can u help me!!!

    You have to configure the temp logger so that it does not send its info on to the root logger.
    For this, you can use the additivity flag.
    # Default logger
    log4j.rootLogger=DEBUG, PFILE
    log4j.additivity.com.temp.test=false
    log4j.logger.com.temp.test=DEBUG,TESTThe rest of the file remains the same.

  • ADF loggers Vs Log4j

    Hi,
    We are using WebCenter Portal PDK application. Which approch is recommended here for logging. Any Pros or Cons. Please find below the high level requirements
    * clustered logging
    * Module wise logging
    * setting logging levels like info, debug
    Thanks,
    Vishnu

    Hi.
    Pros to use ADFLogger:
    - You can control trace level in Oracle Fusion Middleware Console (Enterprise Manager) with a visual interface.
    - You have support by Oracle if you are having problems with logging solution.
    - You have an ADFLogger for JavaScript too.
    - Have more trace level's than log4j.
    Cons to use ADFLogger:
    - You need to associate ADF libraries to your PDK's.
    Pros to use log4j:
    - Best known for most developers.
    - Easy to set different log strategies and file sizes.
    - Goog performance.
    - Easy to extend and use Wrappers with it.
    Cons to use log4j:
    - You can't control trace level with visual interface provided by Oracle. You need to change manually log4j.properties
    - You haven't Oracle Support for log4j.
    It's only my own opinion.
    To me is recommended to use ADFLogger if you are in ADF Application. If you are in a JSR-168 or another application use log4j instead of ADFLogger.
    Regards. Daniel

  • Multiple deployed modules using log4j log to same file

    We have deployed two modules in ias 6.5 Solaris - moduleA and moduleB. Each of these modules uses log4j to write to a log file - logA and logB. Each module includes logj4.jar in it's WEB-INF/lib directory and the classes are unzipped upon deployment into an org/apache/log4j directory under each module.
    Upon app server startup, neither module is loaded. A request is sent to /NASApp/moduleA. logA is written to as the module is initialized. A request is then sent to /NASApp/moduleB. logB is written to as the module in initialized. A request is then sent to /NASApp/moduleA again. This request should be logged in logA but is instead written to logB.
    This happened in ias 6.0 sp3 as well as ias 6.5.
    An attempt to determine the source of the problem:
    The /APPS/modules/moduleB/WEB-INF/lib/org/apache/log4j directory was removed. This should cause ClassNotFoundExceptions to be thrown when attempts are made to write to log4j from moduleB. The appserver is first stopped, then killed, then started again - neither module is loaded. A request is sent to /NASApp/moduleA. logA is written to as the module is initialized. A request is then sent to /NASApp/moduleB - a request that should result in ClassNotFoundExceptions being thrown because the log4j classes are no longer present in the module's classpath. Instead, logB is written and everything behaves as was described above.
    Based on this test, we believe that the root of this problem is once again a class loader issue. Apparently, the log4j classes are being loaded by a class loader that is shared between both moduleA and moduleB. Normally this would not cause a problem, but in the case of log4j, the target log file is being overwritten and causes the log entries to be shared between the two modules.
    What must we do to remedy this problem? At present, the only fix we know will work is to run a separate appserver instance for each module - a solution that is not acceptable due to the amount of resources consumed by all of the deployed code.

    Hi,
    You are correct it is a classloader problem, in sp4/6.5 you have a separate classloader for each module (war/jar) but all the helping classes inside modules share a single classloader, that's why even after deleting the helping files from ModuleB it was working.
    The remedy to your problem is to create ear module out of those ModuleA and ModuleB and put the helping jar files in both of the ear modules. For ias an ear file is an J2EE application and a separate classloader instance is dedicated to it, it holds true for all the helping classes in the ear module too and the helping classes in two J2EE application (ear module) no longer share the classloader.
    I hope it will solve your problem. For further information regarding classloaders please visit Classloader runtime hierarchy.
    Please feel free to ask further questions.
    Sanjeev,
    Developer Support, Sun ONE Application Server-India.

  • Multiple Threads and Loggers

    I have a program that spawns off multiple threads. I want each thread to have its own logger and file name. The catch is that the file names must be dynamic.
    Basically, each thread should have its own log file.
    I'm using commons-logging.
    I know one suggestion is to let it all log into one file, and then parse afterwards. I figured that if the only way the log file is readable is in its parsed form, why not try to create these parsed files from the program itself.

    dewalt wrote:
    I have a program that spawns off multiple threads. I want each thread to have its own logger and file name. The catch is that the file names must be dynamic.
    Basically, each thread should have its own log file. Sounds like a bad idea to me.
    I know one suggestion is to let it all log into one file, and then parse afterwards. I figured that if the only way the log file is readable is in its parsed form, why not try to create these parsed files from the program itself.Because if you are spending all your time reading a log file then either there is something seriously wrong with your code or something seriously wrong with your requirements.
    You read a log file because there is a problem in production.
    So now you have 20 or 300 log files to look at just to find the problem. And operations has to collect those 20 or 300 files so you can look at them in the first place. (Or maybe 40 to 600 because the problem happen sometime between yesterday and today.)
    Then you have to assume that there is absolutely no intentional interaction between the threads at all. Because if there is then obviously you are going to be looking at more than one file (and finding it) anyways.
    And what if there is an unintentional interaction? How are you going to even figure that out, since you won't have a semi-accurrate timeline of all the threads running at that time.....without puting all of the log files back together.

Maybe you are looking for

  • Reply to Juergen Opgenorth's mail  about How can i change the creation ...

    Hello sir, But As i said before, I am migrating an application which is currently deployed in JBOSS.4.0.2. and the databse is MySQL. With reference to our discussion in the last mails, I was able to install the DB Manager and created the database wit

  • Snow Leopard Time machine migration to Lion problem?

    I have a time machine backup of a mac with snow leopard that I made back in June. I want to put it on my new mac with Lion but it won't have this update - http://www.cultofmac.com/105225/if-you-want-to-migrate-from-snow-leopard-to-lion -tomorrow-you-

  • Ajax submit failed: error = 403, Forbidden

    Hello, I try to connect to the eprint center, I enter my email and password and I get the above message. If I press "I' don't remember my password", the OK button is not pressed. What can I do? Any help? This question was solved. View Solution.

  • Problem with a nokia 5310 xpress and a bluetooth

    i have problem with a nokia 5310 xpress and a bluetooth!i can transfer anything from my phone to pc with or without pc suite! but when i want to transfer files from pc to phone i doesen"t work! with pcsuite soethings work but very slow! i want to tra

  • IMac freezes after installing snow leopard

    I recently installed Snow Leopard in my 5 year old iMac. It had functioned flawlessly until that point. Now it freezes constantly. The only way to get out is to shut it down and do a safe reboot. Another difficulty is that I am not that computer lite