public static void updateLog4jConfiguration(Class<?> targetClass, String log4jPath, String log4jFileName)
      throws IOException {
    Closer closer = Closer.create();
    try {
      InputStream fileInputStream = closer.register(new FileInputStream(log4jPath));
      InputStream inputStream = closer.register(targetClass.getResourceAsStream("/" + log4jFileName));
      Properties customProperties = new Properties();
      customProperties.load(fileInputStream);
      Properties originalProperties = new Properties();
      originalProperties.load(inputStream);

      for (Entry<Object, Object> entry : customProperties.entrySet()) {
        originalProperties.setProperty(entry.getKey().toString(), entry.getValue().toString());
      }

      LogManager.resetConfiguration();
      PropertyConfigurator.configure(originalProperties);
    } catch (Throwable t) {
      throw closer.rethrow(t);
    } finally {
      closer.close();
    }
  }
public static void updateLog4jConfiguration ( Class < ? > targetClass , String log4jPath , String log4jFileName ) throws IOException { Closer closer = Closer . create ( ) ; try { InputStream fileInputStream = closer . register ( new FileInputStream ( log4jPath ) ) ; InputStream inputStream = closer . register ( targetClass . getResourceAsStream ( "/" + log4jFileName ) ) ; Properties customProperties = new Properties ( ) ; customProperties . load ( fileInputStream ) ; Properties originalProperties = new Properties ( ) ; originalProperties . load ( inputStream ) ; for ( Entry < Object , Object > entry : customProperties . entrySet ( ) ) { originalProperties . setProperty ( entry . getKey ( ) . toString ( ) , entry . getValue ( ) . toString ( ) ) ; } LogManager . resetConfiguration ( ) ; PropertyConfigurator . configure ( originalProperties ) ; } catch ( Throwable t ) { throw closer . rethrow ( t ) ; } finally { closer . close ( ) ; } }
Update the log4j configuration.

@param targetClass the target class used to get the original log4j configuration file as a resource
@param log4jPath the custom log4j configuration properties file path
@param log4jFileName the custom log4j configuration properties file name
@throws IOException if there's something wrong with updating the log4j configuration