package org.objectweb.util.monolog.log4j;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
import org.objectweb.util.monolog.api.LoggerFactory;
import org.objectweb.util.monolog.wrapper.common.Configurable;
import java.util.Properties;
public class Config {
protected static LoggerFactory factory;
protected static String cfgfn;
protected static void init() {
String loggerFactory = "org.objectweb.util.monolog.wrapper.log4j.MonologLoggerFactory";
try {
factory = (LoggerFactory) Class.forName(loggerFactory).newInstance();
}
catch (Exception exc) {
System.err.println("Unable to instantiate monolog wrapper");
exc.printStackTrace();
System.exit(1);
}
try {
Properties prop = null;
/*
// Cas 1 --> Ca marche
((Configurable) factory).configure(null);
// Cas 2 --> Ca marche
prop = new Properties();
prop.put(Configurable.LOG_CONFIGURATION_TYPE, Configurable.DEFAULT);
((Configurable) factory).configure(prop);
*/
// Cas 3 ...
prop = new Properties();
prop.put(Configurable.LOG_CONFIGURATION_TYPE, Configurable.PROPERTY);
prop.put(Configurable.LOG_CONFIGURATION_FILE, cfgfn);
prop.put(Configurable.LOG_CONFIGURATION_FILE_USE_CLASSPATH, "false");
((Configurable) factory).configure(prop);
}
catch (Exception exc) {
System.err.println("Unable to configure monolog wrapper");
exc.printStackTrace();
System.exit(-1);
}
}
public static Logger getLogger(String topic) {
if (factory == null) init();
System.out.println(factory.getLogger(topic).getClass());
return (Logger) factory.getLogger(topic);
}
public static void main(String args[]) {
cfgfn = (args.length > 0 ? args[0] : "./debug.cfg");
Logger logmon = getLogger("mono");
logmon.log(BasicLevel.DEBUG, "ca marche");
}
}