Example usage for javax.servlet ServletContext log

List of usage examples for javax.servlet ServletContext log

Introduction

In this page you can find the example usage for javax.servlet ServletContext log.

Prototype

public void log(String msg);

Source Link

Document

Writes the specified message to a servlet log file, usually an event log.

Usage

From source file:com.shengpay.commons.bp.logback.LogbackWebConfigurer.java

/**
 * Shut down logback, properly releasing all file locks and resetting the web app root system property.
 * /*w w w  .j a v a 2  s .c o  m*/
 * @param servletContext
 *            the current ServletContext
 * @see WebUtils#removeWebAppRootSystemProperty
 */
public static void shutdownLogging(ServletContext servletContext) {
    servletContext.log("Shutting down logback");
    try {
        LogbackConfigurer.shutdownLogging();
    } finally {
        // Remove the web app root system property.
        if (exposeWebAppRoot(servletContext)) {
            WebUtils.removeWebAppRootSystemProperty(servletContext);
        }
    }
}

From source file:com.excilys.ebi.utils.spring.log.logback.web.LogbackWebConfigurer.java

/**
 * Shut down Logback, properly releasing all file locks and resetting the
 * web app root system property.// ww  w .j av  a 2s . co  m
 * 
 * @param servletContext
 *            the current ServletContext
 * @see WebUtils#removeWebAppRootSystemProperty
 */
public static void shutdownLogging(ServletContext servletContext) {
    servletContext.log("Shutting down Logback");
    LogbackConfigurer.shutdownLogging();
}

From source file:com.github.gagu.web.util.Log4jWebConfigurer.java

/**
 * Shut down log4j, properly releasing all file locks
 * and resetting the web app root system property.
 * @param servletContext the current ServletContext
 * @see WebUtils#removeWebAppRootSystemProperty
 */// ww w.  j a  v a  2s . c o  m
public static void shutdownLogging(ServletContext servletContext) {
    servletContext.log("Shutting down log4j");
    try {
        Log4jConfigurer.shutdownLogging();
    } finally {
        // Remove the web app root system property.
        if (exposeWebAppRoot(servletContext)) {
            WebUtils.removeWebAppRootSystemProperty(servletContext);
        }
    }
}

From source file:com.scf.web.context.spring.ProjectLog4jWebConfigurer.java

public static void initLogging(ServletContext servletContext, String location) {

    if (location != null) {
        try {/*from   w w w.  jav  a 2s .c o m*/
            // Write log message to server log.
            servletContext.log("Initializing log4j from [" + location + "]");

            // Check whether refresh interval was specified.
            String intervalString = servletContext.getInitParameter(REFRESH_INTERVAL_PARAM);
            if (StringUtils.hasText(intervalString)) {
                // Initialize with refresh interval, i.e. with log4j's watchdog thread,
                // checking the file in the background.
                try {
                    long refreshInterval = Long.parseLong(intervalString);
                    Log4jConfigurer.initLogging(location, refreshInterval);
                } catch (NumberFormatException ex) {
                    throw new IllegalArgumentException(
                            "Invalid 'log4jRefreshInterval' parameter: " + ex.getMessage());
                }
            } else {
                // Initialize without refresh check, i.e. without log4j's watchdog thread.
                Log4jConfigurer.initLogging(location);
            }
        } catch (FileNotFoundException ex) {
            throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage());
        }
    }
}

From source file:net.community.chest.gitcloud.facade.ServletUtils.java

public static final Log wrapServletContext(final ServletContext context, final Level thresholdLevel) {
    if ((context == null) || (thresholdLevel == null)) {
        throw new IllegalArgumentException("Incomplete wrapper specification");
    }/*from  ww w  .j a  va2  s  .  com*/

    return new AbstractJULWrapper() {
        @Override
        public void log(Level level, Object message, Throwable t) {
            if (isEnabled(level)) {
                if (t == null) {
                    context.log(level.getName() + ": " + message);
                } else {
                    context.log(level.getName() + ": " + message, t);
                }
            }
        }

        @Override
        public boolean isEnabled(Level level) {
            if (Level.OFF.equals(thresholdLevel)) {
                return false;
            }

            if (Level.ALL.equals(thresholdLevel)) {
                return true;
            }

            if (level.intValue() >= thresholdLevel.intValue()) {
                return true;
            } else {
                return false; // debug breakpoint
            }
        }
    };
}

From source file:ch.qos.logback.ext.spring.web.WebLogbackConfigurer.java

/**
 * Shut down Logback, properly releasing all file locks
 * and resetting the web app root system property.
 *
 * @param servletContext the current ServletContext
 * @see WebUtils#removeWebAppRootSystemProperty
 */// ww  w  . j  a  v a  2  s .  c  o m
public static void shutdownLogging(ServletContext servletContext) {
    //Uninstall the SLF4J java.util.logging bridge *before* shutting down the Logback framework.
    try {
        Class<?> julBridge = ClassUtils.forName("org.slf4j.bridge.SLF4JBridgeHandler",
                ClassUtils.getDefaultClassLoader());
        Method uninstall = ReflectionUtils.findMethod(julBridge, "uninstall");
        if (uninstall != null) {
            servletContext.log("Uninstalling JUL to SLF4J bridge");
            ReflectionUtils.invokeMethod(uninstall, null);
        }
    } catch (ClassNotFoundException ignored) {
        //No need to shutdown the java.util.logging bridge. If it's not on the classpath, it wasn't started either.
    }

    try {
        servletContext.log("Shutting down Logback");
        LogbackConfigurer.shutdownLogging();
    } finally {
        // Remove the web app root system property.
        if (exposeWebAppRoot(servletContext)) {
            WebUtils.removeWebAppRootSystemProperty(servletContext);
        }
    }
}

From source file:com.excilys.ebi.utils.spring.log.logback.web.LogbackWebConfigurer.java

/**
 * Initialize Logback, including setting the web app root system property.
 * /*ww w  . j  a v  a2 s .c  o m*/
 * @param servletContext
 *            the current ServletContext
 * @see org.springframework.web.util.WebUtils#setWebAppRootSystemProperty
 */
public static void initLogging(ServletContext servletContext) {

    // Only perform custom Logback initialization in case of a config file.
    String location = getConfigLocation(servletContext);

    if (location != null) {
        // Perform actual Logback initialization; else rely on Logback's
        // default initialization.
        try {
            // 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)) {
                // Resolve system property placeholders before resolving
                // real path.
                location = SystemPropertyUtils.resolvePlaceholders(location);
                location = WebUtils.getRealPath(servletContext, location);
            }

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

            // Initialize
            LogbackConfigurer.initLogging(location);
        } catch (FileNotFoundException ex) {
            throw new IllegalArgumentException("Invalid 'logbackConfigLocation' parameter: " + ex.getMessage());
        } catch (JoranException e) {
            throw new RuntimeException("Unexpected error while configuring logback", e);
        }
    }
}

From source file:org.owasp.webgoat.application.WebGoatServletListener.java

/** {@inheritDoc} */
@Override/*  w ww . j av a  2 s . co  m*/
public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    context.log("WebGoat is starting");
    setApplicationVariables(context);
    context.log("Adding extra mappings for lessions");

    loadPlugins(sce);
    loadServlets(sce);
}

From source file:ReqListener.java

public void requestInitialized(ServletRequestEvent sre) {

    ServletContext context = sre.getServletContext();
    ServletRequest request = sre.getServletRequest();

    synchronized (context) {
        context.log("Request for "
                + (request instanceof HttpServletRequest ? ((HttpServletRequest) request).getRequestURI()
                        : "Unknown")
                + "; Count=" + ++reqCount);
    }//w ww  .ja v  a  2  s  .c om

}

From source file:org.owasp.webgoat.application.WebGoatServletListener.java

/** {@inheritDoc} */
@Override/*from   www.  ja  v a 2  s  . c o m*/
public void contextDestroyed(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    context.log("WebGoat is stopping");

    // Unregister JDBC drivers in this context's ClassLoader:
    // Get the webapp's ClassLoader
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    // Loop through all drivers
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        java.sql.Driver driver = drivers.nextElement();
        if (driver.getClass().getClassLoader() == cl) {
            // This driver was registered by the webapp's ClassLoader, so deregister it:
            try {
                context.log("Unregister JDBC driver {}");
                DriverManager.deregisterDriver(driver);
            } catch (SQLException ex) {
                context.log("Error unregistering JDBC driver {}");
            }
        } else {
            // driver was not registered by the webapp's ClassLoader and may be in use elsewhere
            context.log("Not unregistering JDBC driver {} as it does not belong to this webapp's ClassLoader");
        }
    }
}