Reading in the config file is a static, one-time thing.  (Conversations
about rereading the configuration notwithstanding.)  That means that you
can't use any non-final, non-static information in it.  The best you can do
is variable substitution similar to the way ant does.  But there again,
that's not a runtime kind of thing.

That leaves you with basically two options: subclass Category to do what
Ceki suggested, or subclass FileAppender to take a classname that computes
the value you want (e.g., the "evaluator" option for SMTPAppender) or a
substitutable parameter (e.g., the "DatePattern" of
DailyRollingFileAppender).

What may be even better for what you're describing is doing both.  Enjoy.

-Jim Moore

-----Original Message-----
From: Thilo Schottelius [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 24, 2001 7:16 AM
To: 'LOG4J Users Mailing List' (E-mail)
Subject: Advanced logging II


Dear Jim,

your idea of concating the category name with the filename in order to
distinguish the output of two instances from the same class, sounds quite
good. As I read your comment, I had another idea. Due to the fact that you
always have to choose another filename, I would like to create a class
offering an unique ID:

public class ID {
        private static int id=0;
        public static int getUniqueID(){
                return id++;
        }
}

class Test {
  Category cat;  // must be instance variable
        String filename="pathAndFilename";
        int id=0;
        //no Parameters in constructors necessary
   Test() {
        //get Id only one time!
        id=ID.getUniqueID();
        cat = Category.getInstance("this.getClass.getName()"+id);
    FileAppender appender = new FileAppender();
    appender.setFilename(filename+"."+id);
    cat.addAppender(appender);
  }
  method() {
    cat.error("An error message");
  }
}

When working with diferrnet files for Threads, the Thread.getName() method
may serve as the unique-Id.

But the problem (or the question) is:
As I create the filename in the class, how can I do the same thing by using
the config file? The config file then needs an assignment:

log4j.appender.FileApp2.File=MyClass.myMethod()
# myClass.myMethod returns a String value

Thilo

----------------------------------------------------------------------------
-----------------------------
Dr. Thilo Schottelius
IMPRESS SOFTWARE AG             
<http://www.impress.com>
<Mailto:[EMAIL PROTECTED]>

            


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to