// Path: src/main/java/org/springframework/web/util/LogbackConfigurer.java
// public class LogbackConfigurer {
// 
//     private LogbackConfigurer() {
//     }
// 
//     /**
//      * Initialize logback from the given file.
//      *
//      * @param location the location of the config file: either a "classpath:" location
//      *                 (e.g. "classpath:logback.xml"), an absolute file URL
//      *                 (e.g. "file:C:/logback.xml), or a plain absolute path in the file system
//      *                 (e.g. "C:/logback.xml")
//      * @throws java.io.FileNotFoundException if the location specifies an invalid file path
//      * @throws ch.qos.logback.core.joran.spi.JoranException
//      *                                       Thrown
//      */
//     public static void initLogging(String location) throws FileNotFoundException, JoranException {
//         String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location);
//         URL url = ResourceUtils.getURL(resolvedLocation);
//         LoggerContext loggerContext = (LoggerContext)StaticLoggerBinder.getSingleton().getLoggerFactory();
// 
//         // in the current version logback automatically configures at startup the context, so we have to reset it
//         loggerContext.reset();
// 
//         // reinitialize the logger context.  calling this method allows configuration through groovy or xml
//         new ContextInitializer(loggerContext).configureByResource(url);
//     }
// 
//     /**
//      * Set the specified system property to the current working directory.
//      * <p/>
//      * This can be used e.g. for test environments, for applications that leverage
//      * LogbackWebConfigurer's "webAppRootKey" support in a web environment.
//      *
//      * @param key system property key to use, as expected in Logback configuration
//      *            (for example: "demo.root", used as "${demo.root}/WEB-INF/demo.log")
//      * @see ch.qos.logback.ext.spring.web.WebLogbackConfigurer WebLogbackConfigurer
//      */
//     public static void setWorkingDirSystemProperty(String key) {
//         System.setProperty(key, new File("").getAbsolutePath());
//     }
// 
//     /**
//      * Shut down Logback.
//      * <p/>
//      * This isn't strictly necessary, but recommended for shutting down
//      * logback in a scenario where the host VM stays alive (for example, when
//      * shutting down an application in a J2EE environment).
//      */
//     public static void shutdownLogging() {
//         ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
//         LoggerContext loggerContext = selector.getLoggerContext();
//         String loggerContextName = loggerContext.getName();
//         LoggerContext context = selector.detachLoggerContext(loggerContextName);
//         context.reset();
//     }
// }


import ch.qos.logback.core.joran.spi.JoranException;
import org.springframework.web.util.LogbackConfigurer;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.util.SystemPropertyUtils;
import org.springframework.web.util.WebUtils;
import javax.servlet.ServletContext;
import java.io.FileNotFoundException;
import java.lang.reflect.Method;

package org.springframework.web.util;



public class WebLogbackConfigurer {

    public static final String CONFIG_LOCATION_PARAM = "logbackConfigLocation";
    public static final String EXPOSE_WEB_APP_ROOT_PARAM = "logbackExposeWebAppRoot";

    private WebLogbackConfigurer() {
    }

    public static void initLogging(ServletContext servletContext) {
        // Expose the web app root system property.
        if (exposeWebAppRoot(servletContext)) {
            WebUtils.setWebAppRootSystemProperty(servletContext);
        }

        // Only perform custom Logback initialization in case of a config file.
        String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
        if (location != null) {
            // Perform actual Logback initialization; else rely on Logback's default initialization.
            try {
                // Resolve system property placeholders before potentially resolving real path.
                location = SystemPropertyUtils.resolvePlaceholders(location);
                // Return a URL (e.g. "classpath:" or "file:") as-is;
                // consider a plain file path as relative to the web application root directory.
                if (!ResourceUtils.isUrl(location)) {
                    location = WebUtils.getRealPath(servletContext, location);
                }

                // Write log message to server log.
                servletContext.log("Initializing Logback from [" + location + "]");

                // Initialize

// Path: src/main/java/org/springframework/web/util/LogbackConfigurer.java
// public class LogbackConfigurer {
// 
//     private LogbackConfigurer() {
//     }
// 
//     /**
//      * Initialize logback from the given file.
//      *
//      * @param location the location of the config file: either a "classpath:" location
//      *                 (e.g. "classpath:logback.xml"), an absolute file URL
//      *                 (e.g. "file:C:/logback.xml), or a plain absolute path in the file system
//      *                 (e.g. "C:/logback.xml")
//      * @throws java.io.FileNotFoundException if the location specifies an invalid file path
//      * @throws ch.qos.logback.core.joran.spi.JoranException
//      *                                       Thrown
//      */
//     public static void initLogging(String location) throws FileNotFoundException, JoranException {
//         String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location);
//         URL url = ResourceUtils.getURL(resolvedLocation);
//         LoggerContext loggerContext = (LoggerContext)StaticLoggerBinder.getSingleton().getLoggerFactory();
// 
//         // in the current version logback automatically configures at startup the context, so we have to reset it
//         loggerContext.reset();
// 
//         // reinitialize the logger context.  calling this method allows configuration through groovy or xml
//         new ContextInitializer(loggerContext).configureByResource(url);
//     }
// 
//     /**
//      * Set the specified system property to the current working directory.
//      * <p/>
//      * This can be used e.g. for test environments, for applications that leverage
//      * LogbackWebConfigurer's "webAppRootKey" support in a web environment.
//      *
//      * @param key system property key to use, as expected in Logback configuration
//      *            (for example: "demo.root", used as "${demo.root}/WEB-INF/demo.log")
//      * @see ch.qos.logback.ext.spring.web.WebLogbackConfigurer WebLogbackConfigurer
//      */
//     public static void setWorkingDirSystemProperty(String key) {
//         System.setProperty(key, new File("").getAbsolutePath());
//     }
// 
//     /**
//      * Shut down Logback.
//      * <p/>
//      * This isn't strictly necessary, but recommended for shutting down
//      * logback in a scenario where the host VM stays alive (for example, when
//      * shutting down an application in a J2EE environment).
//      */
//     public static void shutdownLogging() {
//         ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
//         LoggerContext loggerContext = selector.getLoggerContext();
//         String loggerContextName = loggerContext.getName();
//         LoggerContext context = selector.detachLoggerContext(loggerContextName);
//         context.reset();
//     }
// }


// Path: src/main/java/org/springframework/web/util/WebLogbackConfigurer.java
import ch.qos.logback.core.joran.spi.JoranException;
import org.springframework.web.util.LogbackConfigurer;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.util.SystemPropertyUtils;
import org.springframework.web.util.WebUtils;
import javax.servlet.ServletContext;
import java.io.FileNotFoundException;
import java.lang.reflect.Method;

package org.springframework.web.util;



public class WebLogbackConfigurer {

    public static final String CONFIG_LOCATION_PARAM = "logbackConfigLocation";
    public static final String EXPOSE_WEB_APP_ROOT_PARAM = "logbackExposeWebAppRoot";

    private WebLogbackConfigurer() {
    }

    public static void initLogging(ServletContext servletContext) {
        // Expose the web app root system property.
        if (exposeWebAppRoot(servletContext)) {
            WebUtils.setWebAppRootSystemProperty(servletContext);
        }

        // Only perform custom Logback initialization in case of a config file.
        String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
        if (location != null) {
            // Perform actual Logback initialization; else rely on Logback's default initialization.
            try {
                // Resolve system property placeholders before potentially resolving real path.
                location = SystemPropertyUtils.resolvePlaceholders(location);
                // Return a URL (e.g. "classpath:" or "file:") as-is;
                // consider a plain file path as relative to the web application root directory.
                if (!ResourceUtils.isUrl(location)) {
                    location = WebUtils.getRealPath(servletContext, location);
                }

                // Write log message to server log.
                servletContext.log("Initializing Logback from [" + location + "]");

                // Initialize

                LogbackConfigurer.initLogging(location);
