Užsisakykite naujienų biuletenį arba RSS kanalas gauti automatiškai dienoraštį!

MBean už lygio pokyčiais karšto rąstų Log4j



Pasikeitus karšto (ty neperkraunant "Application Server) yra vienas iš reikalavimų, paprastai dažniau Įmonių plėtojimo programas, Java.
Laikui bėgant aš galėčiau pamatyti ir išbandyti įvairius sprendimus (daugiau ar mažiau elegantiškas), bet labiausiai kartus buvo gana sudėtingas procesas ir reglamentuotas, ir tai yra visada grandinių dėl konfigūracijos failus ar iššūkiu servlet ranka Atnaujinimo failą log4j.properties arba log4j.xml pasikeitė.
Šiandien naudojant pavasarį ir ypač klasės org.springframework.jmx.export.MBeanExporter ", ji tampa labai lengva sukurti MBean galima eksponuoti visų metodų, būtinų siekiant manipuliuoti per karšta" Logger ".

Mes dabar mažmenomis parduodami įgyvendinimą; ką mes turime pradėti yra paprasta klase, kad galima eksponuoti būdai manipuliuoti registruotuvai:

 package net.nothing2hide.jmx; import java.util.Enumeration; import java.util.List; import java.util.Vector; import org.apache.log4j.Level; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; public class Log4jConfigurator { /** * Set the log level to INFO for the target logger * @param target The name of the logger to change */ public void enableInfo(String target) { LogManager.getLogger(target).setLevel(Level.INFO); } /** * Set the log level to WARN for the target logger * @param target The name of the logger to change */ public void enableWarn(String target) { LogManager.getLogger(target).setLevel(Level.WARN); } /** * Set the log level to ERROR for the target logger * @param target The name of the logger to change */ public void enableError(String target) { LogManager.getLogger(target).setLevel(Level.ERROR); } /** * Set the log level to DEBUG for the target logger * @param target The name of the logger to change */ public void enableDebug(String target) { LogManager.getLogger(target).setLevel(Level.DEBUG); } /** * Set the log level to INFO for the ROOT logger */ public void enableInfoGlobally() { LogManager.getRootLogger().setLevel(Level.INFO); } /** * Set the log level to WARN for the ROOT logger */ public void enableWarnGlobally() { LogManager.getRootLogger().setLevel(Level.WARN); } /** * Set the log level to ERROR for the ROOT logger */ public void enableErrorGlobally() { LogManager.getRootLogger().setLevel(Level.ERROR); } /** * Set the log level to DEBUG for the ROOT logger */ public void enableDebugGlobally() { LogManager.getRootLogger().setLevel(Level.DEBUG); } /** * @return The list of all the available loggers */ public String listAvailableLoggers(){ Enumeration en = LogManager.getLoggerRepository() .getCurrentLoggers(); StringBuffer res = new StringBuffer(); while(en.hasMoreElements()){ Logger logger = (Logger)en.nextElement(); res.append(logger.getName()).append("n"); } return res.toString(); } } 

Kitas žingsnis į "eksporto klasės" Log4jConfigurator "kaip MBean per pavasario:

 <bean id="myMBeansExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="beans"> <map> <entry key="n2h:name=log4jConfigurator" value-ref="log4jConfigurator"/> </map> </property> <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING" /> </bean> <bean id="log4jConfigurator" class="net.nothing2hide.jmx.Log4jConfigurator" /> 

Tuo metu, kai bus dislokuoti mūsų prašymą, mes turime MBean "n2h: log4jConfigurator", kuris reiškia bet kokį JMX konsolės pateiks visus metodus klasės "Log4jConfigurator".



Ar jums patinka šis straipsnis? Registruotis dabar gauti naujinimus ar naujienų straipsniai:
Prenumeruoti RSS parašykite per "RSS feed"


Vis dar nėra komentarą "

Comments RSS feed for this post. TrackBack URI

Palikite komentarą

XHTML: <a href="#" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Nothing2Hide © 2006 Visos teisės saugomos.

Licencija | Atsakomybės apribojimas

Uždaryti
Siųsti e-mail