RE: Advanced questions ? (I hope)

2002-07-24 Thread Havaldar, Raghu

A possible solution for # 1:
- implement your own logger. Override the various error/warn/etc 
methods
- use contextual info(utilizing MDC) to identify which log files
that entries need to be dumped in
- the context info can contain an 'object id' identifying the
specific object, on which the log routing is accomplished
- dump it to separate files using different file appenders for
diff 'categories' of your objects

for #2, you can use the above concept to suit your needs.

Let us know what route you finally choose.

-raghu



-Original Message-
From: Stephane Nicoll [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 24, 2002 5:42 AM
To: 'Log4J Users List' (E-mail)
Subject: Advanced questions ? (I hope)


Dear all,
 
I have actually two questions to ask. I hope this is not clearly written in
the manual. I've checked documentation and found no solution to my problems.
 
1. I would like to declare for an application different loggers. I have an
application with many objets and I would like that logs about a set of
objets
goes into one log files. I assume that everything is in the way we get the
static logger in these classes but I can't figure out we can do this. More
explicitely If i have for instance a package com.foo with four objetcs (A,
B,
C, D). I would lie that logs from A and C go into log1.txt and logs from B
and D go into log2.txt.
 
2. Is it possible to associated a log file to an INSTANCE of an object? I
have object which does quite complex things and which is constructed with an
Id. I would like to associate one log file per instance, such as log-id1 and
log-id2 if I do new ComplexObject("id1); and new ComplexObject("id2");
 
Thanks in advance for any help!
 
Cheers,
 
Stéphane

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: Advanced questions ? (I hope)

2002-07-24 Thread Shapira, Yoav

Howdy,

>2. Is it possible to associated a log file to an INSTANCE of an object?
I
>have object which does quite complex things and which is constructed
with
>an Id. I would like to associate one log file per instance, such as
log-id1
>and log-id2 if I do new ComplexObject("id1); and new
ComplexObject("id2");

I think there's a relatively simple solution for this one.  Don't use
static loggers.  Get the logger in the constructor, e.g.

private final Logger myLogger;
private final Appender myAppender;

public myClass(int id)
{
...
myLogger = Logger.getLogger(myClass.class.getName() + id);
   
// Configure myAppender, if it hasn't been done yet.
// Add myAppender to myLogger.

}

That said, I don't think the one object instance per logger concept is
that good.  But it's your use case, your system ;)

Yoav Shapira
Millennium ChemInformatics

--
To unsubscribe, e-mail:   
For additional commands, e-mail: