If nothing else, it'd be great to have this as a tutorial on the wiki. Even if we decided to add it, it'd be great to have it documented somewhere.
Matt On Tue, Apr 1, 2008 at 10:56 PM, Thomas Ramapuram <[EMAIL PROTECTED]> wrote: > Hi, > Yesterday I wrote an action to dynamically change logging levels. > Usually in application servers this is done with JMX but since I do not > use jmx I thought I'd write an action to change logging levels. > I'm sure others users would have the same requirements. In a > production system which it throwing up some problems it would be nice to > increase the logging level to find the problem and then turn down the > logging level without a server restart. > I was just wondering if it is worth including in the project. > Just someting to start a discussion. > Regards, > Thomas Ramapuram. > Ps. > > I'm just including my Code so others can implement it. I just have an > action and the corresponding struts.xml entries. I have not provided > for security nor I18N. I have not added a front end either. The action > is invoked by typing the url and the prameters in the address bar eg. > > (http://localhost:8080/appname/changeLevel.html?logger=org.hibernate.SQL&level=debug) > > > My Action (called LogControlAction) > /** > * > */ > package com.mycompany.app.webapp.action; > > import org.apache.commons.logging.Log; > import org.apache.log4j.Level; > import org.apache.log4j.Logger; > import org.appfuse.webapp.action.BaseAction; > > /** > * @author thomas > * > */ > public class LogControlAction extends BaseAction { > Log log = org.apache.commons.logging.LogFactory > .getLog(LogControlAction.class); > public String lo; > public String le; > > public String getLo() { > return lo; > } > > public void setLo(String lo) { > this.lo = lo; > } > > public String getLe() { > return le; > } > > public void setLe(String le) { > this.le = le; > } > > public String execute() { > Logger logger = Logger.getLogger(lo); > if (null == logger) { > saveMessage(getText("NoSuchLogger")); > return INPUT; > } > if ("debug".equalsIgnoreCase(le)) { > logger.setLevel(Level.DEBUG); > saveMessage(getText("ChangedToDebug")); > log.debug("Saved to Debug"); > } else if ("info".equalsIgnoreCase(le)) { > logger.setLevel(Level.INFO); > saveMessage(getText("ChangedToInfo")); > log.debug("Saved to Info"); > } else if ("error".equalsIgnoreCase(le)) { > logger.setLevel(Level.ERROR); > saveMessage(getText("ChangedToError")); > log.debug("Saved to Error"); > } else if ("fatal".equalsIgnoreCase(le)) { > logger.setLevel(Level.FATAL); > saveMessage(getText("ChangedToFatal")); > log.debug("Saved to Fatal"); > } else if ("warn".equalsIgnoreCase(le)) { > logger.setLevel(Level.WARN); > saveMessage(getText("ChangedToWarn")); > log.debug("Saved to Warn"); > } else { > saveMessage(getText("NoSuchLevel")); > log.debug("No Such Level"); > } > return SUCCESS; > } > } > > Entry in struts.xml > <action name="changeLevel" > class="com.mycompany.app.webapp.action.LogControlAction"> > <result name="success">/WEB-INF/pages/mainMenu.jsp</result> > </action> > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]