strName = pstrName;
/**
* Anlegen der Properties-Datei, falls diese fehlt
*/
JSTextFile objFile = new JSTextFile(strPropfileName);
boolean flgNew = false;
boolean flgPropFileIsOk = true;
if (objFile.exists() == false) {
try {
objFile.WriteLine("log4j.rootCategory=debug, stdout");
if (flgUseJobSchedulerLog4JAppender == false) {
objFile.WriteLine("log4j.appender.stdout=org.apache.log4j.ConsoleAppender");
}
else {
/**
* von aussen steuern. bei junit-tests ist der consoleappender richtig, sonst nicht.
*/
objFile.WriteLine("log4j.appender.stdout=com.sos.JSHelper.Logging.JobSchedulerLog4JAppender");
}
objFile.WriteLine("log4j.appender.stdout.layout=org.apache.log4j.PatternLayout");
objFile.WriteLine("log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n");
objFile.close();
flgNew = true;
}
catch (Exception e) {
System.err.println(conClassName + ": unable to create the log4j-property-file " + objFile.getAbsolutePath());
e.printStackTrace();
flgPropFileIsOk = false;
}
}
/**
* Vorbereitung des Logging-Environments
*/
objRootLog = Logger.getRootLogger();
if (flgPropFileIsOk == true) {
PropertyConfigurator.configure(strPropfileName);
// TODO exception abfangen und direkt konfigurieren
}
else {
/**
* hier jetzt direkt konfigurieren
*/
try {
SimpleLayout layout = new SimpleLayout();
// Appender consoleAppender = new JobSchedulerLog4JAppender(layout);
Appender consoleAppender = new ConsoleAppender(layout);
objRootLog.addAppender(consoleAppender);
// ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF:
objRootLog.setLevel(Level.DEBUG);
objRootLog.debug("Log4J configured programmatically");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
if (pstrName.equals(conClassName))
objCurrentLog = objRootLog;
else
objCurrentLog = Logger.getLogger(strName);
if (flgNew) {
objRootLog.warn("log4j-property-file did not exist - a simple default-file was created");
objRootLog.debug("using log4j-property-file " + objFile.getAbsolutePath());
objRootLog.warn("all log-entries will be written to the console");
}
objLevel = objCurrentLog.getLevel();
}