/**
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 			http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.nanoframework.core.plugins.defaults.plugin;

import java.io.File;
import java.net.URI;
import java.net.URL;

import javax.servlet.ServletConfig;

import org.apache.commons.lang3.StringUtils;
import org.nanoframework.commons.util.ResourceUtils;
import org.nanoframework.core.plugins.Plugin;
import org.nanoframework.core.plugins.PluginLoaderException;

/**
 * @author yanghe
 * @date 2015年11月17日 上午9:06:59
 */
public class Log4j2Plugin implements Plugin {
	public static final String DEFAULT_LOG4J2_PARAMETER_NAME = "log4j2";
	private String log4j2;
	
	@Override
	public boolean load() throws Throwable {
		if(StringUtils.isNotBlank(log4j2)) {
			URL url = this.getClass().getResource(log4j2);
			if (url != null) {
				try {
					File file = ResourceUtils.getFile(url);
					Class<?> LogManager = Class.forName("org.apache.logging.log4j.LogManager");
					Object context = LogManager.getMethod("getContext", boolean.class).invoke(LogManager, false);
					Class<?> LoggerContext = Class.forName("org.apache.logging.log4j.core.LoggerContext");
					LoggerContext.getMethod("setConfigLocation", URI.class).invoke(context, file.toURI());
					LoggerContext.getMethod("reconfigure").invoke(context);
				} catch(Exception e) {
					if(!(e instanceof ClassNotFoundException))
						throw new PluginLoaderException(e.getMessage(), e);
					
					return false;
				}
			}
		} else {
			return false;
		}
		
		return true;
	}

	@Override
	public void config(ServletConfig config) throws Throwable {
		log4j2 = config.getInitParameter(DEFAULT_LOG4J2_PARAMETER_NAME);
	}

}

@@ -1269,45 +1269,50 @@
 %7B%0A%09%09
-%09URL url = this.getClass().getResourc
+    final File file = ResourceUtils.getFil
 e(lo
@@ -1325,19 +1325,20 @@
 %0A%09%09%09if (
-url
+file
  != null
@@ -1355,53 +1355,8 @@
 y %7B%0A
-%09%09%09%09%09File file = ResourceUtils.getFile(url);%0A
 %09%09%09%09
@@ -1850,16 +1850,18 @@
 eption))
+ %7B
 %0A%09%09%09%09%09%09t
@@ -1907,24 +1907,31 @@
 sage(), e);%0A
+%09%09%09%09%09%7D%0A
 %09%09%09%09%09%0A%09%09%09%09%09r

update Log4j2Plugin.java