Search in sources :

Example 1 with PropertyConfigurator

use of org.apache.log4j.PropertyConfigurator in project apex-core by apache.

the class LoggerUtil method addAppender.

/**
   * Adds Logger Appender
   * @param name Appender name
   * @param properties Appender properties
   * @return True if the appender has been added successfully
   */
public static boolean addAppender(String name, Properties properties) {
    if (getAppendersNames().contains(name)) {
        logger.warn("A logger appender with the name '{}' exists. Cannot add a new logger appender with the same name", name);
    } else {
        try {
            Method method = PropertyConfigurator.class.getDeclaredMethod("parseAppender", Properties.class, String.class);
            method.setAccessible(true);
            Appender appender = (Appender) method.invoke(new PropertyConfigurator(), properties, name);
            if (appender == null) {
                logger.warn("Cannot add a new logger appender. Name: {}, Properties: {}", name, properties);
            } else {
                LogManager.getRootLogger().addAppender(appender);
                return true;
            }
        } catch (Exception ex) {
            logger.warn("Cannot add a new logger appender. Name: {}, Properties: {}", name, properties, ex);
        }
    }
    return false;
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) Method(java.lang.reflect.Method) PropertyConfigurator(org.apache.log4j.PropertyConfigurator) IOException(java.io.IOException)

Example 2 with PropertyConfigurator

use of org.apache.log4j.PropertyConfigurator in project jena by apache.

the class TestMemDriverWithLogging method afterClassResetLogging.

@AfterClass
public static void afterClassResetLogging() {
    // Unfortunately, this code "knows" how log4j was set up in testing
    // Thsi is fragile.
    URL configURL = Loader.getResource("log4j.properties");
    new PropertyConfigurator().doConfigure(configURL, LogManager.getLoggerRepository());
}
Also used : PropertyConfigurator(org.apache.log4j.PropertyConfigurator) URL(java.net.URL) AfterClass(org.junit.AfterClass)

Aggregations

PropertyConfigurator (org.apache.log4j.PropertyConfigurator)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 Appender (org.apache.log4j.Appender)1 FileAppender (org.apache.log4j.FileAppender)1 AfterClass (org.junit.AfterClass)1