Saturday, May 19, 2012

How to update the Log4J logger level dynamically for a web application?


Are you looking for an option o update the Log4J logger level dynamically for a web application? If so, here is the solution for people like you to update the logger which doesn’t require any log4j,xml file configuration change or serve restart.

Here we had developed a jsp page that will show the current loggerName, loggerlevel and the list of logger levels lits it can take. Now, you can select the new log level from selectbox to set the new logger on the fly.

Here is the code sample. Wanna try?


<%@ page import="org.apache.log4j.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Dynamic Log4J control
<%
            Logger logger = Logger.getRootLogger();
            logger.setLevel(Level.toLevel(
                                    request.getParameter("selectedLevel"), Level.INFO));
%>


           

                       

           

           

                       

                       

                       

           

           

                       

                       

                       

           


                       

Dynamic Log4J control


                       
Current Log Level Logger Name Set New Log level
${rootLogger.level} ${rootLogger.name}

Pega Decisioning Consultant - Mission Test Quiz & Answers

The Pega Certified Decisioning Consultant (PCDC) certification is for professionals participating in the design and development of a Pega ...