Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.system.logging.log4j » [javadoc | source]
    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.system.logging.log4j;
   19   
   20   import java.io.BufferedReader;
   21   import java.io.File;
   22   import java.io.FileInputStream;
   23   import java.io.FileOutputStream;
   24   import java.io.IOException;
   25   import java.io.InputStreamReader;
   26   import java.io.OutputStream;
   27   import java.io.Reader;
   28   import java.net.MalformedURLException;
   29   import java.util.ArrayList;
   30   import java.util.Enumeration;
   31   import java.util.LinkedList;
   32   import java.util.List;
   33   import java.util.Timer;
   34   import java.util.TimerTask;
   35   import java.util.regex.Matcher;
   36   import java.util.regex.Pattern;
   37   import java.util.regex.PatternSyntaxException;
   38   
   39   import org.apache.geronimo.gbean.GBeanInfo;
   40   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   41   import org.apache.geronimo.gbean.GBeanLifecycle;
   42   import org.apache.geronimo.system.logging.SystemLog;
   43   import org.apache.geronimo.system.properties.JvmVendor;
   44   import org.apache.geronimo.system.serverinfo.DirectoryUtils;
   45   import org.apache.geronimo.system.serverinfo.ServerInfo;
   46   import org.apache.log4j.FileAppender;
   47   import org.apache.log4j.Level;
   48   import org.apache.log4j.LogManager;
   49   import org.apache.log4j.Logger;
   50   
   51   /**
   52    * A Log4j logging service.
   53    *
   54    * @version $Rev: 790692 $ $Date: 2009-07-02 10:32:13 -0700 (Thu, 02 Jul 2009) $
   55    */
   56   public class Log4jService implements GBeanLifecycle, SystemLog {
   57       // A substitution variable in the file path in the config file
   58       private final static Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{.*?\\}");
   59       // Next 6 are patterns that identify log messages in our default format
   60       private final static Pattern DEFAULT_ANY_START = Pattern.compile("^\\d\\d\\:\\d\\d\\:\\d\\d\\,\\d\\d\\d (TRACE|DEBUG|INFO|WARN|ERROR|FATAL) .*");
   61       private final static Pattern DEFAULT_FATAL_START = Pattern.compile("^\\d\\d\\:\\d\\d\\:\\d\\d\\,\\d\\d\\d FATAL .*");
   62       private final static Pattern DEFAULT_ERROR_START = Pattern.compile("^\\d\\d\\:\\d\\d\\:\\d\\d\\,\\d\\d\\d (ERROR|FATAL) .*");
   63       private final static Pattern DEFAULT_WARN_START = Pattern.compile("^\\d\\d\\:\\d\\d\\:\\d\\d\\,\\d\\d\\d (WARN|ERROR|FATAL) .*");
   64       private final static Pattern DEFAULT_INFO_START = Pattern.compile("^\\d\\d\\:\\d\\d\\:\\d\\d\\,\\d\\d\\d (INFO|WARN|ERROR|FATAL) .*");
   65       private final static Pattern DEFAULT_DEBUG_START = Pattern.compile("^\\d\\d\\:\\d\\d\\:\\d\\d\\,\\d\\d\\d (DEBUG|INFO|WARN|ERROR|FATAL) .*");
   66       // Next 6 are patterns that identify log messages if the user changed the format -- but we assume the log level is in there somewhere
   67       private final static Pattern UNKNOWN_ANY_START = Pattern.compile("(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)");
   68       private final static Pattern UNKNOWN_FATAL_START = Pattern.compile("FATAL");
   69       private final static Pattern UNKNOWN_ERROR_START = Pattern.compile("(ERROR|FATAL)");
   70       private final static Pattern UNKNOWN_WARN_START = Pattern.compile("(WARN|ERROR|FATAL)");
   71       private final static Pattern UNKNOWN_INFO_START = Pattern.compile("(INFO|WARN|ERROR|FATAL)");
   72       private final static Pattern UNKNOWN_DEBUG_START = Pattern.compile("(DEBUG|INFO|WARN|ERROR|FATAL)");
   73   
   74       private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Log4jService.class);
   75   
   76       private static final String LOG4JSERVICE_CONFIG_PROPERTY = "org.apache.geronimo.log4jservice.configuration";
   77   
   78       /**
   79        * The URL to the configuration file.
   80        */
   81       private String configurationFile;
   82   
   83       /**
   84        * The time (in seconds) between checking for new config.
   85        */
   86       private int refreshPeriod;
   87   
   88       /**
   89        * The properties service
   90        */
   91       private final ServerInfo serverInfo;
   92   
   93       /**
   94        * The URL watch timer (in daemon mode).
   95        */
   96       private Timer timer = new Timer(true);
   97   
   98       /**
   99        * A monitor to check when the config URL changes.
  100        */
  101       private TimerTask monitor;
  102   
  103       /**
  104        * Last time the file was changed.
  105        */
  106       private long lastChanged = -1;
  107   
  108       /**
  109        * Is this service running?
  110        */
  111       private boolean running = false;
  112   
  113       /**
  114        * Construct a <code>Log4jService</code>.
  115        *
  116        * @param configurationFile The log4j configuration file.
  117        * @param refreshPeriod The refresh refreshPeriod (in seconds).
  118        */
  119       public Log4jService(final String configurationFile, final int refreshPeriod, ServerInfo serverInfo) {
  120           this.refreshPeriod = refreshPeriod;
  121           this.configurationFile = configurationFile;
  122           this.serverInfo = serverInfo;
  123           Logger.getLogger(this.getClass().getName()).setLevel(Level.INFO);
  124       }
  125   
  126       /**
  127        * Gets the level of the root logger.
  128        */
  129       public synchronized String getRootLoggerLevel() {
  130           Level level = LogManager.getRootLogger().getLevel();
  131   
  132           if (level != null) {
  133               return level.toString();
  134           }
  135   
  136           return null;
  137       }
  138   
  139       /**
  140        * Sets the level of the root logger.
  141        *
  142        * @param level The level to change the logger to.
  143        */
  144       public synchronized void setRootLoggerLevel(final String level) {
  145           String currentLevel = this.getRootLoggerLevel();
  146   
  147           // ensure that the level has really been changed
  148           if (!currentLevel.equals(level)) {
  149               LogManager.getRootLogger().setLevel(Level.toLevel(level));
  150           }
  151       }
  152   
  153       /**
  154        * Gets the level of the logger of the give name.
  155        *
  156        * @param logger The logger to inspect.
  157        */
  158       public String getLoggerEffectiveLevel(final String logger) {
  159           if (logger == null) {
  160               throw new IllegalArgumentException("logger is null");
  161           }
  162   
  163           Level level = LogManager.getLogger(logger).getEffectiveLevel();
  164   
  165           if (level != null) {
  166               return level.toString();
  167           }
  168   
  169           return null;
  170       }
  171   
  172       /**
  173        * Gets the level of the logger of the give name.
  174        *
  175        * @param logger The logger to inspect.
  176        */
  177       public String getLoggerLevel(final String logger) {
  178           if (logger == null) {
  179               throw new IllegalArgumentException("logger is null");
  180           }
  181   
  182           Level level = LogManager.getLogger(logger).getLevel();
  183   
  184           if (level != null) {
  185               return level.toString();
  186           }
  187   
  188           return null;
  189       }
  190   
  191       /**
  192        * Sets the level for a logger of the give name.
  193        *
  194        * @param logger The logger to change level
  195        * @param level The level to change the logger to.
  196        */
  197       public void setLoggerLevel(final String logger, final String level) {
  198           if (logger == null) {
  199               throw new IllegalArgumentException("logger is null");
  200           }
  201           if (level == null) {
  202               throw new IllegalArgumentException("level is null");
  203           }
  204   
  205           log.info("Setting logger level: logger=" + logger + ", level=" + level);
  206           Logger.getLogger(logger).setLevel(Level.toLevel(level));
  207       }
  208   
  209       /**
  210        * Get the refresh period.
  211        *
  212        * @return the refresh period (in seconds)
  213        */
  214       public synchronized int getRefreshPeriodSeconds() {
  215           return refreshPeriod;
  216       }
  217   
  218       /**
  219        * Set the refresh period.
  220        *
  221        * @param period the refresh period (in seconds)
  222        * @throws IllegalArgumentException if refresh period is < 5
  223        */
  224       public synchronized void setRefreshPeriodSeconds(final int period) {
  225           if (period < 5) {
  226               throw new IllegalArgumentException("Refresh period must be at least 5 seconds");
  227           }
  228   
  229           if (this.refreshPeriod != period) {
  230               this.refreshPeriod = period;
  231               schedule();
  232           }
  233       }
  234   
  235       /**
  236        * Get the logging configuration URL.
  237        *
  238        * @return the logging configuration URL
  239        */
  240       public synchronized String getConfigFileName() {
  241           return configurationFile;
  242       }
  243   
  244       /**
  245        * Set the logging configuration URL.
  246        *
  247        * @param configurationFile the logging configuration file
  248        */
  249       public synchronized void setConfigFileName(final String configurationFile) {
  250           if (configurationFile == null) {
  251               throw new IllegalArgumentException("configurationFile is null");
  252           }
  253           
  254           log.debug("Using configuration file: {}", configurationFile);
  255           
  256           // ensure that the file name has really been updated
  257           if (!this.configurationFile.equals(configurationFile)) {
  258               this.configurationFile = configurationFile;
  259               lastChanged = -1;
  260               reconfigure();
  261           }
  262       }
  263   
  264       /**
  265        * Get the content of logging configuration file.
  266        *
  267        * @return the content of logging configuration file
  268        */
  269       public synchronized String getConfiguration() {
  270           File file = resolveConfigurationFile();
  271           if (file == null || !file.canRead()) {
  272               return null;
  273           }
  274           Reader in = null;
  275           try {
  276               StringBuffer configuration = new StringBuffer();
  277               in = new InputStreamReader(new FileInputStream(file));
  278               char[] buffer = new char[4096];
  279               for (int size = in.read(buffer); size >= 0; size = in.read(buffer)) {
  280                   configuration.append(buffer, 0, size);
  281               }
  282               return configuration.toString();
  283           } catch (IOException e) {
  284               e.printStackTrace();
  285           } finally {
  286               if (in != null) {
  287                   try {
  288                       in.close();
  289                   } catch (IOException e1) {
  290                       e1.printStackTrace();
  291                   }
  292               }
  293           }
  294           return null;
  295       }
  296   
  297       /**
  298        * Overwrites the content of logging configuration file.
  299        *
  300        * @param configuration the new content of logging configuration file
  301        */
  302       public synchronized void setConfiguration(final String configuration) throws IOException {
  303           if (configuration == null || configuration.length() == 0) {
  304               throw new IllegalArgumentException("configuration is null or an empty string");
  305           }
  306   
  307           File file = resolveConfigurationFile();
  308           if (file == null) {
  309               throw new IllegalStateException("Configuration file is null");
  310           }
  311   
  312           // make parent directory if necessary
  313           if (!file.getParentFile().exists()) {
  314               if (!file.getParentFile().mkdirs()) {
  315                   throw new IllegalStateException("Could not create parent directory of log configuration file: " + file.getParent());
  316               }
  317           }
  318   
  319           // verify that the file is writable or does not exist
  320           if (file.exists() && !file.canWrite()) {
  321               throw new IllegalStateException("Configuration file is not writable: " + file.getAbsolutePath());
  322           }
  323   
  324           OutputStream out = null;
  325           try {
  326               out = new FileOutputStream(file);
  327               out.write(configuration.getBytes());
  328               log.info("Updated configuration file: {}", file);
  329           } finally {
  330               if (out != null) {
  331                   try {
  332                       out.close();
  333                   } catch (IOException e) {
  334                       e.printStackTrace();
  335                   }
  336               }
  337           }
  338       }
  339   
  340       public synchronized String[] getLogFileNames() {
  341           List list = new ArrayList();
  342           for (Enumeration e = Logger.getRootLogger().getAllAppenders(); e.hasMoreElements();) {
  343               Object appender = e.nextElement();
  344               if (appender instanceof FileAppender) {
  345                   list.add(((FileAppender) appender).getFile());
  346               }
  347           }
  348           return (String[]) list.toArray(new String[list.size()]);
  349       }
  350   
  351       private static SearchResults searchFile(File file, String targetLevel, Pattern textSearch, Integer start, Integer stop, int max, boolean stacks) {
  352           List list = new LinkedList();
  353           boolean capped = false;
  354           int lineCount = 0;
  355           FileInputStream logInputStream = null;
  356           try {
  357               logInputStream = new FileInputStream(file);
  358               BufferedReader reader = new BufferedReader(new InputStreamReader(logInputStream, System.getProperty("file.encoding")));
  359               Matcher target = null;
  360               Matcher any = null;
  361               Matcher text = textSearch == null ? null : textSearch.matcher("");
  362               boolean hit = false;
  363               max = Math.min(max, MAX_SEARCH_RESULTS);
  364               String line;
  365               while ((line = reader.readLine()) != null) {
  366                   ++lineCount;
  367                   if(target == null) {
  368                       if(DEFAULT_ANY_START.matcher(line).find()) {
  369                           target = getDefaultPatternForLevel(targetLevel).matcher("");
  370                           any = DEFAULT_ANY_START.matcher("");
  371                       } else {
  372                           target = getUnknownPatternForLevel(targetLevel).matcher("");
  373                           any = UNKNOWN_ANY_START.matcher("");
  374                       }
  375                   }
  376                   if(start != null && start.intValue() > lineCount) {
  377                       continue;
  378                   }
  379                   if(stop != null && stop.intValue() < lineCount) {
  380                       continue;
  381                   }
  382                   target.reset(line);
  383                   if(target.find()) {
  384                       if(text != null) {
  385                           text.reset(line);
  386                           if(!text.find()) {
  387                               hit = false;
  388                               continue;
  389                           }
  390                       }
  391                       list.add(new LogMessage(lineCount,line.toString()));
  392                       if(list.size() > max) {
  393                           list.remove(0);
  394                           capped = true;
  395                       }
  396                       hit = true;
  397                   } else if(stacks && hit) {
  398                       any.reset(line);
  399                       if(!any.find()) {
  400                           list.add(new LogMessage(lineCount,line.toString()));
  401                           if(list.size() > max) {
  402                               list.remove(0);
  403                               capped = true;
  404                           }
  405                       } else {
  406                           hit = false;
  407                       }
  408                   }
  409               }
  410           } catch (Exception e) {
  411               // TODO: improve exception handling
  412           } finally {
  413               if (logInputStream != null) {
  414                   try {
  415                       logInputStream.close();
  416                   } catch (IOException e) {
  417                       // ignore
  418                   }
  419               }
  420           }
  421           return new SearchResults(lineCount, (LogMessage[]) list.toArray(new LogMessage[list.size()]), capped);
  422       }
  423   
  424       private static String substituteSystemProps(String source) {
  425           StringBuffer buf = new StringBuffer();
  426           int last = 0;
  427           Matcher m = VARIABLE_PATTERN.matcher(source);
  428           while(m.find()) {
  429               buf.append(source.substring(last, m.start()));
  430               String prop = source.substring(m.start()+2, m.end()-1);
  431               buf.append(System.getProperty(prop));
  432               last = m.end();
  433           }
  434           buf.append(source.substring(last));
  435           return buf.toString();
  436       }
  437   
  438       private static Pattern getDefaultPatternForLevel(String targetLevel) {
  439           if(targetLevel.equals("FATAL")) {
  440               return DEFAULT_FATAL_START;
  441           } else if(targetLevel.equals("ERROR")) {
  442               return DEFAULT_ERROR_START;
  443           } else if(targetLevel.equals("WARN")) {
  444               return DEFAULT_WARN_START;
  445           } else if(targetLevel.equals("INFO")) {
  446               return DEFAULT_INFO_START;
  447           } else if(targetLevel.equals("DEBUG")) {
  448               return DEFAULT_DEBUG_START;
  449           } else {
  450               return DEFAULT_ANY_START;
  451           }
  452       }
  453   
  454       private static Pattern getUnknownPatternForLevel(String targetLevel) {
  455           if(targetLevel.equals("FATAL")) {
  456               return UNKNOWN_FATAL_START;
  457           } else if(targetLevel.equals("ERROR")) {
  458               return UNKNOWN_ERROR_START;
  459           } else if(targetLevel.equals("WARN")) {
  460               return UNKNOWN_WARN_START;
  461           } else if(targetLevel.equals("INFO")) {
  462               return UNKNOWN_INFO_START;
  463           } else if(targetLevel.equals("DEBUG")) {
  464               return UNKNOWN_DEBUG_START;
  465           } else {
  466               return UNKNOWN_ANY_START;
  467           }
  468       }
  469   
  470       public SearchResults getMatchingItems(String logFile, Integer firstLine, Integer lastLine, String minLevel, String text, int maxResults, boolean includeStackTraces) {
  471           // Ensure the file argument is really a log file!
  472           if(logFile == null) {
  473               throw new IllegalArgumentException("Must specify a log file");
  474           }
  475           String[] files = getLogFileNames();
  476           boolean found = false;
  477           for (int i = 0; i < files.length; i++) {
  478               if(files[i].equals(logFile)) {
  479                   found = true;
  480                   break;
  481               }
  482           }
  483           if(!found) {
  484               throw new IllegalArgumentException("Not a log file!");
  485           }
  486           // Check for valid log level
  487           if(minLevel == null) {
  488               minLevel = "TRACE";
  489           } else if(!minLevel.equals("FATAL") && !minLevel.equals("ERROR") && !minLevel.equals("WARN") &&
  490                   !minLevel.equals("INFO") && !minLevel.equals("DEBUG") && !minLevel.equals("TRACE")) {
  491               throw new IllegalArgumentException("Not a valid log level");
  492           }
  493           // Check that the text pattern is valid
  494           Pattern textPattern = null;
  495           try {
  496               textPattern = text == null || text.equals("") ? null : Pattern.compile(text);
  497           } catch (PatternSyntaxException e) {
  498               throw new IllegalArgumentException("Bad regular expression '"+text+"'", e);
  499           }
  500           // Make sure we can find the log file
  501           File file = new File(substituteSystemProps(logFile));
  502           if(!file.exists()) {
  503               throw new IllegalArgumentException("Log file "+file.getAbsolutePath()+" does not exist");
  504           }
  505           // Run the search
  506           return searchFile(file, minLevel, textPattern, firstLine, lastLine, maxResults, includeStackTraces);
  507       }
  508   
  509       /**
  510        * Force the logging system to reconfigure.
  511        */
  512       public void reconfigure() {
  513           File file = resolveConfigurationFile();
  514           if (file == null || !file.exists()) {
  515               return;
  516           } else {
  517               log.debug("Reconfiguring from: {}", configurationFile);
  518               lastChanged = file.lastModified();
  519           }
  520   
  521           try {
  522               URLConfigurator.configure(file.toURL());
  523           } catch (MalformedURLException e) {
  524               e.printStackTrace();
  525           }
  526       }
  527   
  528       private synchronized void schedule() {
  529           if (timer != null) {
  530               // kill the old monitor
  531               if (monitor != null) {
  532                   monitor.cancel();
  533               }
  534   
  535               // start the new one
  536               monitor = new URLMonitorTask();
  537               TimerTask task = monitor;
  538               timer.schedule(monitor, 1000 * refreshPeriod, 1000 * refreshPeriod);
  539               task.run();
  540           }
  541       }
  542   
  543       public void doStart() {
  544           // Allow users to override the configurationFile which is hardcoded
  545           // in config.ser and cannot be updated by config.xml, as the
  546           // AttrbiuteManager comes up after this GBean
  547           String cfgFile = System.getProperty(LOG4JSERVICE_CONFIG_PROPERTY);
  548           if ((cfgFile != null) && (!cfgFile.equals(""))) {
  549               this.configurationFile = cfgFile;
  550           }
  551   
  552           synchronized (this) {
  553               reconfigure();
  554   
  555               timer = new Timer(true);
  556   
  557               // Periodically check the configuration file
  558               schedule();
  559           }
  560   
  561           logEnvInfo();
  562           
  563           synchronized (this) {
  564               running = true;
  565           }
  566       }
  567   
  568       public synchronized void doStop() {
  569           running = false;
  570           if (monitor != null) {
  571               monitor.cancel();
  572               monitor = null;
  573           }
  574           if (timer != null) {
  575               timer.cancel();
  576               timer = null;
  577           }
  578   
  579           log.info("Stopping Logging Service");
  580           log.info("----------------------------------------------");
  581   
  582           LogManager.shutdown();
  583       }
  584   
  585       public void doFail() {
  586           doStop();
  587       }
  588   
  589       private synchronized File resolveConfigurationFile() {
  590           try {
  591               return serverInfo.resolveServer(configurationFile);
  592           } catch (Exception e) {
  593               return null;
  594           }
  595       }
  596   
  597       private void logEnvInfo() {
  598          try {
  599             log.info("----------------------------------------------");
  600             log.info("Started Logging Service");
  601             
  602             log.debug("Log4jService created with configFileName={}, refreshPeriodSeconds={}", configurationFile, refreshPeriod);
  603             
  604             log.info("Runtime Information:");
  605             log.info("  Install Directory = " + DirectoryUtils.getGeronimoInstallDirectory());
  606             log.info("  JVM in use        = " + JvmVendor.getJvmInfo());
  607             log.info("Java Information:");
  608             log.info("  System property [java.runtime.name]     = " + System.getProperty("java.runtime.name"));
  609             log.info("  System property [java.runtime.version]  = " + System.getProperty("java.runtime.version"));
  610             log.info("  System property [os.name]               = " + System.getProperty("os.name"));
  611             log.info("  System property [os.version]            = " + System.getProperty("os.version"));
  612             log.info("  System property [sun.os.patch.level]    = " + System.getProperty("sun.os.patch.level"));
  613             log.info("  System property [os.arch]               = " + System.getProperty("os.arch"));
  614             log.info("  System property [java.class.version]    = " + System.getProperty("java.class.version"));
  615             log.info("  System property [locale]                = " + System.getProperty("user.language") + "_" + System.getProperty("user.country"));
  616             log.info("  System property [unicode.encoding]      = " + System.getProperty("sun.io.unicode.encoding"));
  617             log.info("  System property [file.encoding]         = " + System.getProperty("file.encoding"));
  618             log.info("  System property [java.vm.name]          = " + System.getProperty("java.vm.name"));
  619             log.info("  System property [java.vm.vendor]        = " + System.getProperty("java.vm.vendor"));
  620             log.info("  System property [java.vm.version]       = " + System.getProperty("java.vm.version"));
  621             log.info("  System property [java.vm.info]          = " + System.getProperty("java.vm.info"));
  622             log.info("  System property [java.home]             = " + System.getProperty("java.home"));
  623             log.info("  System property [java.classpath]        = " + System.getProperty("java.classpath"));
  624             log.info("  System property [java.library.path]     = " + System.getProperty("java.library.path"));
  625             log.info("  System property [java.endorsed.dirs]    = " + System.getProperty("java.endorsed.dirs"));
  626             log.info("  System property [java.ext.dirs]         = " + System.getProperty("java.ext.dirs"));
  627             log.info("  System property [sun.boot.class.path]   = " + System.getProperty("sun.boot.class.path"));
  628             log.info("----------------------------------------------");
  629          } catch (Exception e) {
  630             System.err.println("Exception caught during logging of Runtime Information.  Exception=" + e.toString());
  631          }
  632       }
  633   
  634       private class URLMonitorTask extends TimerTask {
  635           public void run() {
  636               try {
  637                   long lastModified;
  638                   synchronized (this) {
  639                       if (running == false) {
  640                           return;
  641                       }
  642   
  643                       File file = resolveConfigurationFile();
  644                       if (file == null) {
  645                           return;
  646                       }
  647   
  648                       lastModified = file.lastModified();
  649                   }
  650   
  651                   if (lastChanged < lastModified) {
  652                       lastChanged = lastModified;
  653                       reconfigure();
  654                   }
  655               } catch (Exception e) {
  656               }
  657           }
  658       }
  659       
  660       public static final GBeanInfo GBEAN_INFO;
  661   
  662       static {
  663           GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(Log4jService.class, "SystemLog");
  664   
  665           infoFactory.addAttribute("configFileName", String.class, true);
  666           infoFactory.addAttribute("refreshPeriodSeconds", int.class, true);
  667           infoFactory.addAttribute("configuration", String.class, false);
  668           infoFactory.addAttribute("rootLoggerLevel", String.class, false);
  669   
  670           infoFactory.addReference("ServerInfo", ServerInfo.class, "GBean");
  671   
  672           infoFactory.addOperation("reconfigure");
  673           infoFactory.addOperation("setLoggerLevel", new Class[]{String.class, String.class});
  674           infoFactory.addOperation("getLoggerLevel", new Class[]{String.class});
  675           infoFactory.addOperation("getLoggerEffectiveLevel", new Class[]{String.class});
  676           infoFactory.addInterface(SystemLog.class);
  677   
  678           infoFactory.setConstructor(new String[]{"configFileName", "refreshPeriodSeconds", "ServerInfo"});
  679   
  680           GBEAN_INFO = infoFactory.getBeanInfo();
  681       }
  682   
  683       public static GBeanInfo getGBeanInfo() {
  684           return GBEAN_INFO;
  685       }
  686   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.system.logging.log4j » [javadoc | source]