I have a structure as follows: Class A is started via main method Class A 
starts Class B using ProcessBuilder (via main method of course) Class B starts 
Class C using its Constructor
I want each class to have its own log and to use a single log4j2.xml file.

Appender has the following:

<RollingFile
    name="file"
    fileName="${sys:loggingFileName}.log"
    …
</RollingFile>

Each Class has code similar to this:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.slf4j.LoggerFactory;

private static final Logger log = LoggerFactory.getLogger (A.class);

System.setProperty ("loggingFileName", “A”);
LoggerContext context = (LoggerContext) LogManager.getContext (false);

If there were only these classes involved, everything would work, but there are 
many other classes that do logging.

For example, Class D is referenced by Classes A, B, and C and only has this 
code:

private static final Logger log = LoggerFactory.getLogger (D.class);

I would like the output from Class D referenced from Class A to be in log A, 
but it may wind up in log A, B, or C.

Is there a way to construct the logs so that output for Class D winds up in: 
log A when referenced from A log B when referenced from B log C when referenced 
from C.




--
Gerard Gagliano
505-792-3331 Office
505-463-3999 Mobile

Prodentity
Corrales, NM 87048-6935
http://www.prodentity.com <http://www.prodentity.com/>

Reply via email to