I have a class which initializes my log4j. This code will never print or exit, I dont understand why.
public class MyLog
{
private static Logger log;
static
{
log = Logger.getRootLogger();
try
{
PropertyConfigurator.configure("somefileNameWhichDoesNotExist");
}
catch(Exception t)
{
System.out.println("oops logging cant be set, lets exit");
System.exit(0);
}
Why do you assume that an exception will be thrown when the file doesn’t exist? I just had a quick look at the API docs, and they don’t say anything about the handling of missing files – so it’s just as likely that the condition would just be ignored.
EDIT: just read your additional comments, so that’s not the case.
Make sure that the static block is actually executing.
EDIT: PropertyConfigurator is catching the exception, and handling it internally. That’s why you don’t see the exception. See the source – lines 370-380.