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

/**
 * Initialize logback, including setting the web app root system property.
 * //from  www  .  j a va  2  s . c  om
 * @param servletContext
 *            the current ServletContext
 * @see WebUtils#setWebAppRootSystemProperty
 */
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 {
            // 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 without refresh check, i.e. without logback's watchdog thread.
            LogbackConfigurer.initLogging(location);

        } catch (FileNotFoundException ex) {
            throw new IllegalArgumentException("Invalid 'logbackConfigLocation' parameter: " + ex.getMessage());
        }
    }
}

From source file:SessionFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws java.io.IOException, ServletException {

    HttpSession session = ((HttpServletRequest) request).getSession();
    ServletContext context = config.getServletContext();
    /*//from   w w w .  j  av  a  2s.  c  om
     * use the ServletContext.log method to log filter messages
     */
    context.log("doFilter called in: " + config.getFilterName() + " on " + (new java.util.Date()));

    // log the session ID
    context.log("session ID: " + session.getId());

    // Find out whether the logged-in session attribute is set
    String logged = (String) session.getAttribute("logged-in");
    if (logged == null)
        session.setAttribute("logged-in", "no");

    //log a message about the log-in status
    context.log("log-in status: " + (String) session.getAttribute("logged-in"));
    context.log("");
    chain.doFilter(request, response);
}

From source file:com.qualogy.qafe.web.ContextLoader.java

public void close(ServletContext servletContext) {
    servletContext.log("Closing QAFE root WebApplicationContext");
    // TODO//  w ww  .  j a  v  a  2  s . com
    // ApplicationContextLoader.unload();
}

From source file:ParamSnoop.java

public void  doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws java.io.IOException, ServletException {
    //w ww.  ja  v a 2 s.com
       
    Map paramMap = request.getParameterMap();
    ServletContext context = config.getServletContext();
    /* use the ServletContext.log method to log 
    param names/values */
     context.log("doFilter called in: " + config.getFilterName() +  
      " on " + (new java.util.Date()));
    context.log("Snooping the parameters in request: " + 
        ((HttpServletRequest) request).getRequestURI());
            
     Iterator iter = paramMap.entrySet().iterator();
      while (iter.hasNext()){
             
         Map.Entry me = (Map.Entry) iter.next();
         context.log((String)me.getKey() + ": " + ((String[]) me.getValue())[0]);
      }

    chain.doFilter(request,response); 
      
}

From source file:ParamSnoop.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws java.io.IOException, ServletException {

        Map paramMap = request.getParameterMap();
        ServletContext context = config.getServletContext();
        /* use the ServletContext.log method to log 
        param names/values *///w  ww . java 2s .c o  m
        context.log("doFilter called in: " + config.getFilterName() + " on " + (new java.util.Date()));
        context.log("Snooping the parameters in request: " + ((HttpServletRequest) request).getRequestURI());

        Iterator iter = paramMap.entrySet().iterator();
        while (iter.hasNext()) {

            Map.Entry me = (Map.Entry) iter.next();
            context.log((String) me.getKey() + ": " + ((String[]) me.getValue())[0]);
        }

        chain.doFilter(request, response);

    }

From source file:LogFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {
    ServletContext context = getFilterConfig().getServletContext();
    long bef = System.currentTimeMillis();
    try {//from w ww.  ja  v  a 2  s .c  om
        chain.doFilter(req, res);
    } catch (Exception e) {
    }
    long aft = System.currentTimeMillis();
    context.log("Request to " + req.getRemoteHost() + ": " + (aft - bef));
}

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

/**
 * Initialize Logback, including setting the web app root system property.
 *
 * @param servletContext the current ServletContext
 * @see org.springframework.web.util.WebUtils#setWebAppRootSystemProperty
 *///from ww w. j a v a2s  . c  om
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 = ServletContextPropertyUtils.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);
        } catch (FileNotFoundException ex) {
            throw new IllegalArgumentException("Invalid 'logbackConfigLocation' parameter: " + ex.getMessage());
        } catch (JoranException e) {
            throw new RuntimeException("Unexpected error while configuring logback", e);
        }
    }

    //If SLF4J's java.util.logging bridge is available in the classpath, install it. This will direct any messages
    //from the Java Logging framework into SLF4J. When logging is terminated, the bridge will need to be uninstalled
    try {
        Class<?> julBridge = ClassUtils.forName("org.slf4j.bridge.SLF4JBridgeHandler",
                ClassUtils.getDefaultClassLoader());

        Method removeHandlers = ReflectionUtils.findMethod(julBridge, "removeHandlersForRootLogger");
        if (removeHandlers != null) {
            servletContext.log("Removing all previous handlers for JUL to SLF4J bridge");
            ReflectionUtils.invokeMethod(removeHandlers, null);
        }

        Method install = ReflectionUtils.findMethod(julBridge, "install");
        if (install != null) {
            servletContext.log("Installing JUL to SLF4J bridge");
            ReflectionUtils.invokeMethod(install, null);
        }
    } catch (ClassNotFoundException ignored) {
        //Indicates the java.util.logging bridge is not in the classpath. This is not an indication of a problem.
        servletContext.log("JUL to SLF4J bridge is not available on the classpath");
    }
}

From source file:org.cloudfoundry.identity.uaa.config.YamlServletProfileInitializer.java

private void applySpringProfiles(ConfigurableEnvironment environment, ServletContext servletContext) {
    if (environment.containsProperty("spring_profiles")) {
        String profiles = (String) environment.getProperty("spring_profiles");
        servletContext.log("Setting active profiles: " + profiles);
        environment.setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles));
    }/*from  w w  w .  jav a2 s. c  o m*/
}

From source file:org.lightadmin.logging.configurer.LightConfigurerWebApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    LoggingConfigurerSettings configuration = new LoggingConfigurerSettings(servletContext);

    if (lightConfigurerNotEnabled(configuration)) {
        servletContext.log("Light Configurer Module is disabled by default. Skipping.");
        return;/*  w w  w .  j av a2s. c  o  m*/
    }

    if (notValidBaseUrl(configuration.getApplicationBaseUrl())) {
        servletContext.log("Light Configurer Module's 'baseUrl' property must match "
                + BASE_URL_PATTERN.pattern() + " pattern. Skipping.");
        return;
    }

    registerLightConfigurerDispatcher(servletContext, configuration);
    registerHiddenHttpMethodFilter(servletContext, configuration);
    registerCharsetFilter(servletContext, configuration);
}

From source file:RequestFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws java.io.IOException, ServletException {

    ReqWrapper wrapper = null;//from  w w  w  . j a  v  a2  s.c  o  m
    ServletContext context = null;

    if (request instanceof HttpServletRequest)
        wrapper = new ReqWrapper((HttpServletRequest) request);

    /*
     * use the ServletContext.log method to log param names/values
     */
    if (wrapper != null) {
        context = config.getServletContext();
        context.log("Query: " + wrapper.getQueryString());
    }

    //continue the request, response to next filter or servlet
    //destination
    if (wrapper != null)
        chain.doFilter(wrapper, response);
    else
        chain.doFilter(request, response);
}