But when you change the log4j.properties file by an editor how do you think your running application which has read this configuration gets notifided about the asynchronous happened change in the log4j.properties configuration?
You have to use a call to the log4j API in your application and tell the log4j system how often log4j.properties has to be checked for a change ! Any other ideas welcome The code below is our axis2 based web service init-method code public void init(ServiceContext sCtx) throws XMLStreamException, WsiException { // sCtx = Service Context is the ident for the session instance this.sc = sCtx; try { String scID = SpServer.class.getName().toString(); //String[] a1 = scID.split("."); does not work with "." as separator String[] a1 = {"axawl", "spezpla", "servers", "SpezplaService", "SpServer"}; String lcID = this.sc.getLogCorrelationIDString(); String[] a2 = lcID.split(":"); PropertyConfigurator.configureAndWatch( "/axcls/log4j.properties", 60*1000 ); // get the configured logger (known name) // the configured logger has // an appender of some type which knows a logfile // an layout, a pattern, some additivitie this.NameOfLogger = SpServer.class.getName(); this.clog = Logger.getLogger(this.NameOfLogger); // create the session logger this.slog = Logger.getLogger(this.NameOfLogger.concat("@").concat(a2[2])); this.slog.setLevel(this.clog.getLevel()); this.slog.setAdditivity(this.clog.getAdditivity()); // get the configured appender FileAppender cfapp = (FileAppender)this.clog.getAppender("LOGFILE"); if (cfapp != null) { String clogFileName = cfapp.getFile(); // get the filename int substringindex = clogFileName.indexOf(".log"); // index to ".log"" String sCxLogFileName = clogFileName.substring(0,substringindex-1); // extract configured prefix sCxLogFileName = sCxLogFileName.concat("_").concat(a2[2]).concat(".log"); // make session logfilename // create a new session appender of type FileAppender this.sfapp = new FileAppender( cfapp.getLayout(), sCxLogFileName, cfapp.getAppend() ); sfapp.activateOptions(); // finally add the session-appender to the session-logger this.slog.addAppender( this.sfapp ); } // for CHAINSAW Logging SocketAppender sapp = (SocketAppender)this.clog.getAppender("CHAINSAW_AXIS2"); if (sapp != null) { // create a new session appender of type SocketAppender this.ssapp = new SocketAppender(sapp.getRemoteHost(),sapp.getPort()); this.ssapp.setLocationInfo(sapp.getLocationInfo()); ssapp.activateOptions(); this.slog.addAppender( this.ssapp); } // for later in other methods we need this.log = this.slog; // take a local copy to be used in this method only Logger log = this.slog; // create a local copy String sDate = new Date().toString(); log.info(" init() called at : "+ sDate + " using "+ this.sc.toString()+" i="+intObj.toString(i+=1)); log.info(" ---------------------------------------------------"); log.info(" Logger is of type : "+ Logger.class.toString()); log.info(" Logger is instance : "+ log.toString()); log.info(" Logger is named : "+ log.getName()); log.info(" Logger is at level : "+ log.getLevel()); log.info(" ---------------------------------------------------"); this.SPg = null; // doubble moppel - we need it null to call login twice for vms debugging log.info("******************************************************************************"); log.info("Wie are testing all log.levels here .........................................."); log.fatal("test of this.log.fatal() Logger-Name "+log.getName()); log.error("test of this.log.error() Logger-Name "+log.getName()); log.warn("test of this.log.warn() Logger-Name "+log.getName()); log.info("test of this.log.info() Logger-Name "+log.getName()); log.debug("test of this.log.debug() Logger-Name "+log.getName()); log.info("can you see all FATAL ERROR WARN INFO DEBUG messages?\n"); log.info("******************************************************************************\n"); log.info(" init() OK called at : "+ sDate); // erst wenn alle loggers initialisiert sind darf man sie brauchen sonst knallts MessageContext msgCtx = MessageContext.getCurrentMessageContext(); HttpServletRequest request = (HttpServletRequest) msgCtx.getProperty("transport.http.servletRequest"); HttpSession session = request.getSession(true); if(session.isNew()){ this.log.info("SpServer.init() called and session IS NEW *********"); } else { this.log.info("SpServer.init() called and session IS NOT NEW *****"); } /* * There are various types of exceptions that you can catch here, * including: * WsiConnectException = Out-of-Process Connection error * WsiServerException = Application Server (back-end) based error * WsiException = Generic WSIT based error * Java Exception should only be used as a catch all. } catch (WsiConnectException wcex) { wcex.printStackTrace(); this.log.error("Exception took place during connection to out-of-Process application server."); } catch (WsiServerException wsex) { wsex.printStackTrace(); this.log.error("Exception took place within application server."); } catch (WsiException wsitex) { wsitex.printStackTrace(); this.log.error("Unknown WSIT exception took place within the client."); */ } catch (Exception ex) { ex.printStackTrace(); log.error("Unknown Java exception took place within the SpezplaService."); } } And here is our IA64-2>ty log4j.properties log4j.debug=false # ------------------------------------------------------------------- # Copyright 2001-2004 The Apache Software Foundation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ------------------------------------------------------------------- log4j.rootLogger=INFO, CONSOLE, R, CHAINSAW_CLIENT, LOGFILE, CHAINSAW_AXIS2 # in absence of a true console - the log goes into # apache$specific:[000000]APACHE$JAKARTA_SERVER_OUTPUT.LOG # ------------------------------------------------------------------- # CONSOLE is set to be a ConsoleAppender using a PatternLayout. ----- log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d %-5p %c - %m%n # ------------------------------------------------------------------- # R is a rolling file appender # if R is not used yet / no need to parse this log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.Append=true log4j.appender.R.File=${catalina.home}logs/tomcat.log log4j.appender.R.MaxFileSize=2MB log4j.appender.R.MaxBackupIndex=10 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n # ------------------------------------------------------------------- # CHAINSAW_CLIENT is an appender sending to a remote host GUI ------- # feeding the CHAINSAW client listening on TCP/IP port 4445 log4j.appender.CHAINSAW_CLIENT=org.apache.log4j.net.SocketHubAppender # # we changed to the socket hub appender above #-log4j.appender.CHAINSAW_CLIENT.RemoteHost=C038020 log4j.appender.CHAINSAW_CLIENT.Port=4451 log4j.appender.CHAINSAW_CLIENT.LocationInfo=true # ------------------------------------------------------------------- # LOGFILE is set to be a File appender using a PatternLayout. ------- log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=/axcls/axis2_SpServer.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%-5p - %m%n #log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n #log4j.appender.LOGFILE.layout=org.apache.log4j.xml.XMLLayout # ------------------------------------------------------------------- # CHAINSAW_AXIS2 is an appender sending to a remote host GUI ------- # feeding the CHAINSAW client listening on TCP/IP port 4445 log4j.appender.CHAINSAW_AXIS2=org.apache.log4j.net.SocketHubAppender log4j.appender.CHAINSAW_AXIS2.Port=4452 log4j.appender.CHAINSAW_AXIS2.LocationInfo=true # ------------------------------------------------------------------- #- Set your loggers priority to what you need ----------------------- # Logger logging WHAT it logs WHO is actually logging log4j.logger.org.apache.catalina=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.coyote=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.jasper=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.jk=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.tomcat=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.commons=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.axiom=WARN, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.axis2=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.axis2.deployment=DEBUG, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.de.hunsicker.jalopy.io=FATAL, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.httpclient.wire.header=FATAL, CONSOLE, R, CHAINSAW_CLIENT # ------------------------------------------------------------------- #- create the SpServer Logger --------------------------------------- # this is the CONFIGURED logger for the SpServer.java JavaPart # the Configurator strips of the logger_prefix "log4j.logger." # the logger is then known in the hierarchy as # "axawl.spezpla.servers.SpezplaService.SpServer" # retrive this configured logger from log4j.hierarchy through # Logger log = Logger.getLogger(SpServer.class); log4j.logger.axawl.spezpla.servers.SpezplaService.SpServer=INFO, LOGFILE, CHAINSAW_AXIS2 # ------------------------------------------------------------------- # define the additivities used to prevent logging twice the same msg # NOTE: each logger needs an additivity set or you risk logging twice # log4j.additivity.org.apache.axiom=false log4j.additivity.org.apache.axis2=false log4j.additivity.org.apache.axis2.deployment=false log4j.additivity.org.apache.catalina=false log4j.additivity.org.apache.coyote=false log4j.additivity.org.apache.jasper=false log4j.additivity.org.apache.jk=false log4j.additivity.org.apache.commons=false # to prevent that logging events are propagated to parent loggers # and finally arrive at the root loggers appender, printed to the root- # loggers files i.e. additivity must be set to false to prevent this. # please goto http://logging.apache.org/log4j/1.2/manual.html and read # the short manual or buy the full manual log4j.additivity.axawl.spezpla.servers.SpezplaService.SpServer=false IA64-2> Josef -----Ursprüngliche Nachricht----- Von: Jacob Kjome [mailto:h...@visi.com] Gesendet: Sonntag, 4. September 2011 20:16 An: Log4J Users List Betreff: Re: Changing Level of Logging during runtime There used to be a nice open source, Struts-based, Log4j configuration app out there, but it seems to have disappeared. There's a simple one in the Log4j-sandbox you can try... http://svn.apache.org/repos/asf/logging/sandbox/log4j/log4j_sandbox/tags/LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/servlet/ConfigurationServlet.java Note that I specifically point to the tag "LOG4J_SANDBOX_ALPHA3" because later tags were based on the now defunct Log4j-1.3 codebase and the trunk, I believe, continues to be based on the said defunct codebase. Jake On 9/2/2011 2:58 AM, Amitabh78 wrote: > > Hi, I want to change the level og logging during runtime. The change in level > should be in immediate effect i.e. when admin changes the level og logging > from Debug to Info through UI Screen, the logging at debug level should be > stopped immediately. > > --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org