I have code to launch several independent processes, which then set up
socket connections with each other. I'd like to use log4j to acquire
execution trace information to assist me in finding bugs in that code.
I have a LoggingConfiguration() that I call at the start of each
independent process to set up logging. Currently the filename is fixed,
but I actually want to use the process id number as the name of the log
file (I just haven't done that yet).
Currently it's hardwired, but the file c:\trace.log doesn't showed up.
I assume I'm missing something simple? Almost all of the examples I have
seen use a configuration file (log4j.properties) instead of code setup,
but I didn't want to do this because I wanted the name of the logfile to
include the process id.
Here's LoggingConfiguration:
[package statement]
import org.apache.log4j.FileAppender;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.Logger;
public class LoggingConfiguration {
LoggingConfiguration() {
// Dump lots for now; figure out what I don't need later.
PatternLayout layout = new PatternLayout("%d %x %t %p %l %throwable:
%m%n");
FileAppender fileAppender = new FileAppender();
fileAppender.setFile("c:\\trace.log");
fileAppender.setAppend(true);
fileAppender.setImmediateFlush(true);
fileAppender.setLayout(layout);
fileAppender.activateOptions();
Logger log = Logger.getRootLogger();
log.addAppender(fileAppender);
};
};
And in other files, I do:
[package...]
[imports...]
public class Foo.Bar {
private static Logger log = Logger.getLogger(Foo.Bar.class);
[and for each routine I am interested in]
public boolean someRoutine() {
log.trace("Entered.");
[boolean result = ....;]
log.trace("Exited: result = |{}|.", result);
};
};
1) What am I missing to make the log file (files, once I start using
the process id for the name) show up?
2) Is there anything else an experienced user sees that I am doing
incorrectly?
Thanks,
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]