Example #1
0
  public void testOverflowHandling() throws Exception {
    Logger logger = Logger.getLogger("AppenderTest.overflowTest");
    AsyncCoalescingStatisticsAppender appender = new AsyncCoalescingStatisticsAppender();
    appender.setName("overflowTestAppender");
    appender.setTimeSlice(1000);
    appender.setQueueSize(2); // set low queue size so we overflow
    logger.addAppender(appender);
    logger.setAdditivity(false);
    logger.setLevel(Level.INFO);
    appender.activateOptions();

    for (int i = 0; i < 1000; i++) {
      StopWatch stopWatch = new StopWatch("testOverflow");
      Math
          .random(); // this should happen super fast, faster than the appender's Dispatcher thread
                     // can drain
      logger.info(stopWatch.stop());
    }

    // again close the appender
    appender.close();
    assertTrue(
        "Expected some stop watch messages to get discarded",
        appender.getNumDiscardedMessages() > 0);
  }
 /** Parse the additivity option for a non-root category. */
 void parseAdditivityForLogger(Properties props, Logger cat, String loggerName) {
   String value = OptionConverter.findAndSubst(ADDITIVITY_PREFIX + loggerName, props);
   LogLog.debug("Handling " + ADDITIVITY_PREFIX + loggerName + "=[" + value + "]");
   // touch additivity only if necessary
   if ((value != null) && (!value.equals(""))) {
     boolean additivity = OptionConverter.toBoolean(value, true);
     LogLog.debug("Setting additivity for \"" + loggerName + "\" to " + additivity);
     cat.setAdditivity(additivity);
   }
 }
 @Override
 public void activateOptions() {
   try {
     queue = new JdbmQueue<LoggingEvent>(file);
   } catch (IOException e) {
     throw new IllegalStateException(e);
   }
   forward = Logger.getLogger("audit.forward");
   forward.setAdditivity(false);
   forwarder = new Forwarder();
   forwarder.setDaemon(true);
   forwarder.start();
 }
Example #4
0
  public static void initTddlLog() {
    if (initOK) return;
    Appender dbTabAppender = buildAppender("TDDL_Vtab_Appender", "tddl-db-tab.log", "%m");
    Appender vSlotAppender = buildAppender("TDDL_Vtab_Appender", "tddl-vslot.log", "%m");
    Appender dynamicRuleAppender =
        buildAppender("TDDL_DynamicRule_Appender", "tddl-dynamic-rule.log", "%m");

    DB_TAB_LOG.setAdditivity(false);
    DB_TAB_LOG.removeAllAppenders();
    DB_TAB_LOG.addAppender(dbTabAppender);
    DB_TAB_LOG.setLevel(Level.INFO);

    VSLOT_LOG.setAdditivity(false);
    VSLOT_LOG.removeAllAppenders();
    VSLOT_LOG.addAppender(vSlotAppender);
    VSLOT_LOG.setLevel(Level.INFO);

    DYNAMIC_RULE_LOG.setAdditivity(false);
    DYNAMIC_RULE_LOG.removeAllAppenders();
    DYNAMIC_RULE_LOG.addAppender(dynamicRuleAppender);
    DYNAMIC_RULE_LOG.setLevel(Level.INFO);
  }
Example #5
0
  public static Map<String, Object> addOrUpdateLogger(
      DispatchContext dctc, Map<String, ?> context) {
    String name = (String) context.get("name");
    String level = (String) context.get("level");
    boolean additivity = "Y".equalsIgnoreCase((String) context.get("additivity"));

    Logger logger = null;
    if ("root".equals(name)) {
      logger = Logger.getRootLogger();
    } else {
      logger = Logger.getLogger(name);
    }
    logger.setLevel(Level.toLevel(level));
    logger.setAdditivity(additivity);

    return ServiceUtil.returnSuccess();
  }
  /**
   * Converts the specified XML DOM element to a monitored MBean.
   *
   * @param element the XML DOM element to be converted.
   * @return a monitored MBean represented by the specified XML DOM element.
   * @throws MalformedObjectNameException if the specified XML DOM element does not contain a valid
   *     object name.
   */
  private MonitoredMBean toMonitoredMBean(Element element) throws MalformedObjectNameException {
    String objectName = element.getAttribute(MBEAN_NAME_ATTRIBUTE);

    if ("".equals(objectName)) {
      throw createAttributeNotFoundException(MBEAN_NAME_ATTRIBUTE);
    }

    String loggerName = element.getAttribute(MBEAN_LOGGER_ATTRIBUTE);
    if ("".equals(loggerName)) {
      throw createAttributeNotFoundException(MBEAN_LOGGER_ATTRIBUTE);
    }

    Logger logger = Logger.getLogger(loggerName.toLowerCase());
    logger.setAdditivity(false);
    logger.setLevel(Level.INFO);

    String[] attributes = getMonitoredAttributes(element);

    return new MonitoredMBean(objectName, attributes, logger);
  }
Example #7
0
 // Create a Log4J log file with a monthly rolling appender and populate
 // it with information from the dataset in a csv format so the log file
 // can be opened and processed with a spreadsheet.
 private void makeTrialLogEntry(String service, DicomObject dicomObject) {
   if (!TrialConfig.log()) return;
   if (processorLog == null) {
     try {
       processorLog = Logger.getLogger("trial");
       processorLog.setAdditivity(false);
       PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd},%d{HH:mm:ss},%m%n");
       File logs = new File(TrialConfig.basepath + TrialConfig.logDirectory);
       logs.mkdirs();
       DailyRollingFileAppender appender =
           new DailyRollingFileAppender(
               layout,
               TrialConfig.basepath
                   + TrialConfig.logDirectory
                   + File.separator
                   + TrialConfig.serviceName
                   + ".csv",
               "'.'yyyy-MM");
       processorLog.addAppender(appender);
       processorLog.setLevel((Level) Level.ALL);
     } catch (Exception e) {
       logger.warn("Unable to instantiate a trial logger");
       processorLog = null;
       return;
     }
   }
   processorLog.info(
       service
           + ","
           + dicomObject.getPatientName()
           + ","
           + dicomObject.getPatientID()
           + ","
           + dicomObject.getModality()
           + ","
           + dicomObject.getSeriesNumber()
           + ","
           + dicomObject.getAcquisitionNumber()
           + ","
           + dicomObject.getInstanceNumber());
 }
  /* Configure the log4j appenders
   */
  static void configureLogger() {
    ConsoleAppender console = new ConsoleAppender(); // create appender
    // configure the appender
    console.setLayout(new PatternLayout(PATTERN));
    console.setThreshold(Level.ALL);
    console.activateOptions();
    // add appender to any Logger (here is root)
    log.addAppender(console);
    // This is for the rmi_server log file
    FileAppender fa = new FileAppender();
    fa.setName("FileLogger");
    fa.setFile("log/_rmi_server.log");
    fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
    fa.setThreshold(Level.ALL);
    fa.setAppend(true);
    fa.activateOptions();

    // add appender to any Logger (here is root)
    log.addAppender(fa);
    log.setAdditivity(false);
    // repeat with all other desired appenders
  }
  /**
   * This method is used to join other logger branch with the jrds' one and use same setting if it's
   * not already defined
   *
   * @param logname the logger name
   * @param level the desired default level for this logger
   */
  public static void configureLogger(String logname, Level level) {
    // Do nothing if jrds is not allowed to setup logs
    if (!isLogOwner()) return;
    Logger externallogger = LogManager.getLoggerRepository().exists(logname);
    // Change level only for new logger
    if (externallogger == null) {
      externallogger = Logger.getLogger(logname);
      externallogger.setLevel(level);
    }

    // Replace the appender, not optionally add it
    if (jrdsAppender != null) {
      Logger logger = Logger.getLogger(logname);
      Appender oldApp = logger.getAppender(jrdsAppender.getName());
      if (oldApp != null) logger.removeAppender(oldApp);
      logger.addAppender(jrdsAppender);
      logger.setAdditivity(false);
    }

    // Keep the new logger name
    rootLoggers.add(logname);
  }
Example #10
0
  public static Logger getLogger(String categroy, String name) {
    Logger logger = Logger.getLogger(name);
    logger.removeAllAppenders();
    logger.setAdditivity(false);

    FileAppender appender = null;
    PatternLayout layout = new PatternLayout();
    layout.setConversionPattern("[%p][%d{yyyy-MM-dd HH:mm:ss}] %m%n");
    try {
      appender =
          new DailyRollingFileAppender(
              layout, String.format("/data/applogs/%s/%s.log", categroy, name), "yyyy-MM-dd");
      appender.setEncoding("UTF-8");
      appender.activateOptions();
    } catch (IOException e) {
      throw new RuntimeException("LogUtil fail.", e);
    }
    logger.addAppender(appender);
    logger.setLevel(Level.INFO);

    return logger;
  }