org.apache.uima.util.Level Java Examples

The following examples show how to use org.apache.uima.util.Level. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CPMUtils.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Dumps all events in the process trace object.
 *
 * @param aPTr -
 *          event container
 */
public static void dumpEvents(ProcessTrace aPTr) {
  List aList = aPTr.getEvents();
  for (int i = 0; i < aList.size(); i++) {
    ProcessTraceEvent prEvent = (ProcessTraceEvent) aList.get(i);
    String aEvType = prEvent.getType();
    if (System.getProperty("DEBUG_EVENTS") != null) {
      if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
        UIMAFramework.getLogger(CPMUtils.class).log(
                Level.FINEST,
                "Returning Report With Event::" + aEvType + " For Component:::"
                        + prEvent.getComponentName() + " Duration:::"
                        + prEvent.getDurationExcludingSubEvents());
      }
    }
  }

}
 
Example #2
Source File: Log4jLogger_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * log4j level mapping to UIMA level mapping. <br>
 * SEVERE (highest value) -&gt; SEVERE <br> 
 * WARNING -&gt; WARNING <br> 
 * INFO -&gt; INFO <br> 
 * CONFIG -&gt; INFO <br> 
 * FINE -&gt; DEBUG <br> 
 * FINER -&gt; TRACE <br> 
 * FINEST (lowest value) -&gt; TRACE <br> 
 * OFF -&gt; OFF <br> 
 * ALL -&gt; ALL <br>
 * 
 * @param level uima level
 * @return Level - corresponding log4j 2 level
 */
static org.apache.logging.log4j.Level getLog4jLevel(Level level) {
   switch (level.toInteger()) {
   case org.apache.uima.util.Level.OFF_INT:
      return org.apache.logging.log4j.Level.OFF;
   case org.apache.uima.util.Level.SEVERE_INT:
      return org.apache.logging.log4j.Level.ERROR;
   case org.apache.uima.util.Level.WARNING_INT:
      return org.apache.logging.log4j.Level.WARN;
   case org.apache.uima.util.Level.INFO_INT:
      return org.apache.logging.log4j.Level.INFO;
   case org.apache.uima.util.Level.CONFIG_INT:
      return org.apache.logging.log4j.Level.INFO;
   case org.apache.uima.util.Level.FINE_INT:
      return org.apache.logging.log4j.Level.DEBUG;
   case org.apache.uima.util.Level.FINER_INT:
     return org.apache.logging.log4j.Level.TRACE;
   case org.apache.uima.util.Level.FINEST_INT:
     return org.apache.logging.log4j.Level.TRACE;
   default: // for all other cases return Level.ALL
      return org.apache.logging.log4j.Level.ALL;
   }
}
 
Example #3
Source File: Filter.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Parses filter expression.
 *
 * @param expression -
 *          filter expression to parse
 * @return - list of filters
 * @throws ParseException -
 */
public LinkedList parse(String expression) throws ParseException {
  StringTokenizer tokenizer = new StringTokenizer(expression, " !=", true);
  parseTokens(tokenizer);
  StringBuffer sb = new StringBuffer();
  for (int i = 0; i < expressionList.size(); i++) {
    Expression ex = (Expression) expressionList.get(i);
    if (ex.hasLeftPart()) {
      sb.append(ex.getLeftPart().get() + " ");
    }
    if (ex.hasOperand()) {
      sb.append(ex.getOperand().getOperand() + " ");
    }
    if (ex.hasRightPart()) {
      sb.append(ex.getRightPart().get() + " ");
    }
    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
              "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_expression__FINEST",
              new Object[] { Thread.currentThread().getName(), sb.toString() });

    }
    sb.setLength(0);
  }
  return expressionList;
}
 
Example #4
Source File: UIMASlf4jWrapperLogger.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
@Override
public void log(Level level, String msg, Throwable throwable) {
	switch (level.toInteger()) {
	case org.apache.uima.util.Level.OFF_INT:
		return;
	case org.apache.uima.util.Level.SEVERE_INT:
		this.slf4jLogger.error(msg, throwable);
	case org.apache.uima.util.Level.WARNING_INT:
		this.slf4jLogger.warn(msg, throwable);
	case org.apache.uima.util.Level.INFO_INT:
		this.slf4jLogger.info(msg, throwable);
	case org.apache.uima.util.Level.CONFIG_INT:
		this.slf4jLogger.debug(msg, throwable);
	case org.apache.uima.util.Level.FINE_INT:
		this.slf4jLogger.debug(msg, throwable);
	case org.apache.uima.util.Level.FINER_INT:
		this.slf4jLogger.trace(msg, throwable);
	case org.apache.uima.util.Level.FINEST_INT:
		this.slf4jLogger.trace(msg, throwable);
	default: // for all other cases return Level.ALL
		this.slf4jLogger.trace(msg, throwable);
	}
}
 
Example #5
Source File: UIMASlf4jWrapperLogger.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
@Override
public void log(Level level, String msg, Object[] params) {
	switch (level.toInteger()) {
	case org.apache.uima.util.Level.OFF_INT:
		return;
	case org.apache.uima.util.Level.SEVERE_INT:
		this.slf4jLogger.error(msg, params);
	case org.apache.uima.util.Level.WARNING_INT:
		this.slf4jLogger.warn(msg, params);
	case org.apache.uima.util.Level.INFO_INT:
		this.slf4jLogger.info(msg, params);
	case org.apache.uima.util.Level.CONFIG_INT:
		this.slf4jLogger.debug(msg, params);
	case org.apache.uima.util.Level.FINE_INT:
		this.slf4jLogger.debug(msg, params);
	case org.apache.uima.util.Level.FINER_INT:
		this.slf4jLogger.trace(msg, params);
	case org.apache.uima.util.Level.FINEST_INT:
		this.slf4jLogger.trace(msg, params);
	default: // for all other cases return Level.ALL
		this.slf4jLogger.trace(msg, params);
	}
}
 
Example #6
Source File: CPMEngine.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
   * Releases given cases back to pool.
   * 
   * @param aCASList -
   *          cas list to release
   */
  public void releaseCASes(CAS[] aCASList) {
    for (int i = 0; i < aCASList.length; i++) {
      if (aCASList[i] != null) {
        // aCASList[i].reset();
        casPool.releaseCas(aCASList[i]);
//        synchronized (casPool) {  // redundant - the above releaseCas call does this
//          casPool.notifyAll();
//        }

      } else {
        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
          UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                  "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_release_tcas__FINEST",
                  new Object[] { Thread.currentThread().getName() });
        }
      }
    }
  }
 
Example #7
Source File: RoomNumberAnnotator.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
   * @see JCasAnnotator_ImplBase#process(JCas)
   */
  public void process(JCas aJCas) throws AnalysisEngineProcessException {
    // get document text
    String docText = aJCas.getDocumentText();

    // loop over patterns
    for (int i = 0; i < mPatterns.length; i++) {
      Matcher matcher = mPatterns[i].matcher(docText);
      while (matcher.find()) {
        // found one - create annotation
        RoomNumber annotation = new RoomNumber(aJCas, matcher.start(), matcher.end());
        annotation.addToIndexes();
        annotation.setBuilding(mLocations[i]);
        getLogger().log(Level.FINEST, "Found: " + annotation);
        // or, using slf4j
        // note: this call skips constructing the message if tracing is not enabled
//        getSlf4jLogger().trace("Found: {}", annotation);
      }
    }
  }
 
Example #8
Source File: Log4jLogger_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void setLevel(Level level) {    
     if (level == Level.CONFIG) {
       // next seems to do nothing...
//       coreLogger.getContext().getConfiguration().getLoggerConfig(coreLogger.getName()).addFilter(FILTER_CONFIG);
       // next also seems to do nothing...
//       ((LoggerContext)LogManager.getContext(false)).getConfiguration().getLoggerConfig(coreLogger.getName()).addFilter(FILTER_CONFIG);
       coreLogger.get().addFilter(FILTER_CONFIG);
     } else {
//       coreLogger.getContext().getConfiguration().getLoggerConfig(coreLogger.getName()).removeFilter(FILTER_CONFIG);
       coreLogger.get().removeFilter(FILTER_CONFIG);
     }
     
     if (level == Level.FINEST) {
       coreLogger.get().addFilter(FILTER_FINEST);
     } else {
       coreLogger.get().removeFilter(FILTER_FINEST);
     }
          
     coreLogger.get().setLevel(getLog4jLevel(level));
     coreLogger.getContext().updateLoggers();
   }
 
Example #9
Source File: UimacppAnalysisComponent.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Get the logging level of the logger for TAFAnnotator. TAF only supports three levels of
 * logging. All logging levels INFO and below are mapped to the TAF message level.
 * @return the logging level
 */
public static int getLoggingLevel() {

  Logger uimacppLogger = UIMAFramework.getLogger(UimacppAnalysisComponent.class);

  if (uimacppLogger.isLoggable(Level.FINEST) || uimacppLogger.isLoggable(Level.FINER)
          || uimacppLogger.isLoggable(Level.FINE) || uimacppLogger.isLoggable(Level.CONFIG)
          || uimacppLogger.isLoggable(Level.INFO)) {
    return TAF_LOGLEVEL_MESSAGE;
  } else if (uimacppLogger.isLoggable(Level.WARNING)) {
    return TAF_LOGLEVEL_WARNING;
  } else if (uimacppLogger.isLoggable(Level.SEVERE)) {
    return TAF_LOGLEVEL_ERROR;
  } else {
    return TAF_LOGLEVEL_OFF;
  }
}
 
Example #10
Source File: CasDataUtils.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public static void dumpFeatures(CasData aCAS) {
  Iterator<FeatureStructure> it = aCAS.getFeatureStructures();
  while (it.hasNext()) {
      FeatureStructure fs = it.next();
      UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(), "dumpFeatures",
              LOG_RESOURCE_BUNDLE, "UIMA_cas_feature_structure_type__FINE", fs.getType());

      String[] names = fs.getFeatureNames();
      for (int i = 0; names != null && i < names.length; i++) {
        FeatureValue fValue = fs.getFeatureValue(names[i]);
        if (fValue != null) {
          UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(),
                  "dumpFeatures", LOG_RESOURCE_BUNDLE, "UIMA_cas_feature_name__FINE",
                  new Object[] { names[i], fValue.toString() });
        }
      }
  }

}
 
Example #11
Source File: UIMASlf4jWrapperLogger.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
@Override
public void log(Level level, String msg) {
	switch (level.toInteger()) {
	case org.apache.uima.util.Level.OFF_INT:
		return;
	case org.apache.uima.util.Level.SEVERE_INT:
		this.slf4jLogger.error(msg);
	case org.apache.uima.util.Level.WARNING_INT:
		this.slf4jLogger.warn(msg);
	case org.apache.uima.util.Level.INFO_INT:
		this.slf4jLogger.info(msg);
	case org.apache.uima.util.Level.CONFIG_INT:
		this.slf4jLogger.debug(msg);
	case org.apache.uima.util.Level.FINE_INT:
		this.slf4jLogger.debug(msg);
	case org.apache.uima.util.Level.FINER_INT:
		this.slf4jLogger.trace(msg);
	case org.apache.uima.util.Level.FINEST_INT:
		this.slf4jLogger.trace(msg);
	default: // for all other cases return Level.ALL
		this.slf4jLogger.trace(msg);
	}
}
 
Example #12
Source File: DictionaryResource.java    From newsleak with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves the dictionary files as configured in the preprocessing configuration.
 *
 * @param list
 *            the list
 * @return the dictionary files
 */
private List<File> getDictionaryFiles(String list) {
	List<File> files = new ArrayList<File>();
	for (String f : list.split(", +?")) {
		String[] args = f.split(":");
		if (args.length > 2) {
			logger.log(Level.SEVERE,
					"Could not parse dictionary files configuration: '" + list + "'\n"
							+ "Expecting format 'dictionaryfiles = langcode:filename1, langcode:filename2, ...'.\n"
							+ "You can also omit 'langcode:' to apply dictionary to all languages.");
			System.exit(1);
		}
		if (args.length == 1 || (args.length == 2 && args[0].equals(languageCode))) {
			String fname = args.length == 1 ? args[0] : args[1];
			files.add(new File(dictionaryDir, fname));
			logger.log(Level.INFO, "Applying dictionary file " + f + " to language " + languageCode);
		}
	}
	return files;
}
 
Example #13
Source File: Slf4jLogger_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public boolean isLoggable(Level level, Marker marker) {
  switch (level.toInteger()) {
  case org.apache.uima.util.Level.OFF_INT:
    return false;
  case org.apache.uima.util.Level.SEVERE_INT:
    return logger.isErrorEnabled(marker);
  case org.apache.uima.util.Level.WARNING_INT:
    return logger.isWarnEnabled(marker);
  case org.apache.uima.util.Level.INFO_INT:
    return logger.isInfoEnabled(marker);
  case org.apache.uima.util.Level.CONFIG_INT:
    return logger.isInfoEnabled(marker);
  case org.apache.uima.util.Level.FINE_INT:
    return logger.isDebugEnabled(marker);
  case org.apache.uima.util.Level.FINER_INT:
    return logger.isTraceEnabled(marker);
  case org.apache.uima.util.Level.FINEST_INT:
    return logger.isTraceEnabled(marker);
  default: // for Level.ALL return false, that's what jul logger does
    return false;
  }
}
 
Example #14
Source File: UimacppAnalysisComponent.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private void logJTafException(UimacppException e) {
  if (e.getEmbeddedException() instanceof InternalTafException) {
    InternalTafException tafExc = (InternalTafException) e.getEmbeddedException();
    long errorCode = tafExc.getTafErrorCode();
    String errorName = "";
    try {
      errorName = UimacppEngine.getErrorMessage(errorCode);
    } catch (UimacppException jtafexc) {
      log.logrb(Level.SEVERE, CLASS_NAME.getName(), "logJTafException", LOG_RESOURCE_BUNDLE,
              "UIMA_error_while_getting_name__SEVERE", jtafexc.getMessage());
      errorName = "";
    }

    log.logrb(Level.SEVERE, CLASS_NAME.getName(), "logJTafException", LOG_RESOURCE_BUNDLE,
            "UIMA_taf_internal_exception__SEVERE",
            new Object[] {errorCode, errorName });
  }
  Exception et = e.getEmbeddedException();

  // log exception
  log.log(Level.SEVERE, et.getMessage(), et);
}
 
Example #15
Source File: AggregateAnalysisEngine_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see AnalysisEngine#processAndOutputNewCASes(CAS)
 */
public CasIterator processAndOutputNewCASes(CAS aCAS) throws AnalysisEngineProcessException {
  // logging and instrumentation
  String resourceName = getMetaData().getName();
  Logger logger = getLogger();
  logger.logrb(Level.FINE, CLASS_NAME.getName(), "process", LOG_RESOURCE_BUNDLE,
          "UIMA_analysis_engine_process_begin__FINE", resourceName);
  try {
    CasIterator iterator = _getASB().process(aCAS);

    // log end of event
    logger.logrb(Level.FINE, CLASS_NAME.getName(), "process", LOG_RESOURCE_BUNDLE,
            "UIMA_analysis_engine_process_end__FINE", resourceName);
    return iterator;
  } catch (Exception e) {
    // log and rethrow exception
    logger.log(Level.SEVERE, "", e);
    if (e instanceof AnalysisEngineProcessException)
      throw (AnalysisEngineProcessException) e;
    else
      throw new AnalysisEngineProcessException(e);
  }
}
 
Example #16
Source File: Checkpoint.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Prints the stats.
 *
 * @param prT the pr T
 */
public static void printStats(ProcessTrace prT) {
  if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
    UIMAFramework.getLogger(Checkpoint.class).log(Level.FINEST,
            "\n\t\t\t----------------------------------------");
    UIMAFramework.getLogger(Checkpoint.class).log(Level.FINEST, "\t\t\t\t PERFORMANCE REPORT ");
    UIMAFramework.getLogger(Checkpoint.class).log(Level.FINEST,
            "\t\t\t----------------------------------------\n");
  }
  // get the list of events from the processTrace
  List eveList = prT.getEvents();
  printEveList(eveList, 0);
  if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
    UIMAFramework.getLogger(Checkpoint.class).log(Level.FINEST,
            "_________________________________________________________________\n");
  }
}
 
Example #17
Source File: JSR47Logger_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.uima.util.Logger#setOutputStream(java.io.PrintStream)
 * 
 * @deprecated use external configuration possibility
 */
@Override
@Deprecated
public void setOutputStream(PrintStream out) {
  // if PrintStream is null set root logger level to OFF
  if (out == null) {
    LogManager.getLogManager().getLogger("").setLevel(java.util.logging.Level.OFF);
    return;
  }

  // get root logger handlers - root logger is parent of all loggers
  Handler[] handlers = LogManager.getLogManager().getLogger("").getHandlers();

  // remove all current handlers
  for (int i = 0; i < handlers.length; i++) {
    LogManager.getLogManager().getLogger("").removeHandler(handlers[i]);
  }

  // add new UIMAStreamHandler with the given output stream
  UIMAStreamHandler streamHandler = new UIMAStreamHandler(out, new UIMALogFormatter());
  streamHandler.setLevel(java.util.logging.Level.ALL);
  LogManager.getLogManager().getLogger("").addHandler(streamHandler);
}
 
Example #18
Source File: NetworkCasProcessorImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public boolean isReadOnly() {
  if (resourceMetadata == null) {
    try {
      resourceMetadata = textAnalysisProxy.getAnalysisEngineMetaData();
    } catch (ResourceServiceException e) {
      //can't throw exception from here so just log it and return the default
      UIMAFramework.getLogger(this.getClass()).log(Level.SEVERE, e.getMessage(), e);
      return false; 
    }
  }
  OperationalProperties opProps =  resourceMetadata.getOperationalProperties();
  if (opProps != null) {
    return !opProps.getModifiesCas();
  }
  return false; //default  
}
 
Example #19
Source File: InformationExtraction2Postgres.java    From newsleak with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Metadata is supposed to be presented in a four-tuple CSV format (docid, key,
 * value, type). @see uhh_lt.newsleak.reader.NewsleakReader should write a
 * temporary metadata file in that format (or assume it was produced by an
 * external process)
 * 
 * The CSV file is imported via postgres directly.
 * 
 * See <i>data/metadata_example.csv</i> for an example.
 */
private void metadataToPostgres() {

	try {
		// we need a mapping of document ids since ElasticsearchDocumentWriter generates
		// new Ids from an autoincrement-value
		String mappedMetadataFilepath = this.dataDirectory + File.separator + this.metadataFile + ".mapped";
		mappingIdsInMetadata(mappedMetadataFilepath);

		// import csv into postgres db
		CopyManager cpManager = new CopyManager((BaseConnection) conn);
		st.executeUpdate("TRUNCATE TABLE metadata;");
		this.logger.log(Level.INFO, "Importing metadata from " + mappedMetadataFilepath);
		Long n = cpManager.copyIn("COPY metadata FROM STDIN WITH CSV", new FileReader(mappedMetadataFilepath));
		this.logger.log(Level.INFO, n + " metadata imported");
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(1);
	}
}
 
Example #20
Source File: NetworkCasProcessorImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * This method gets called when the CPM completes processing the collection. Depending on the type
 * of deployment this routine may issue a shutdown command to the service.
 * 
 * @see org.apache.uima.collection.base_cpm.CasProcessor#collectionProcessComplete(org.apache.uima.util.ProcessTrace)
 */
public void collectionProcessComplete(ProcessTrace aTrace) throws ResourceProcessException,
        IOException {
  if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
    UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
            "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_stopping_cp__FINEST",
            new Object[] { Thread.currentThread().getName(), name });
  }
  // Send shutdown command to Local services, meaning services started by the CPM on the same
  // machine in a different JVM. Remote services will not be shutdown since these may be started
  // for
  // use by different clients not necessarily just by the CPM
  if (textAnalysisProxy != null) {
    if ("local".equals(casProcessorType.getDeployment().toLowerCase())) {
      // true = send shutdown to remote service
      textAnalysisProxy.shutdown(true, doSendNotification());
    } else {
      // false = dont send shutdown to remote service, just close the client
      textAnalysisProxy.shutdown(false, doSendNotification());
    }
  }
  textAnalysisProxy = null;
  metadata = null;
}
 
Example #21
Source File: XMLUtils.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public static DocumentBuilderFactory createDocumentBuilderFactory() { 
  DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
  try {
    if ( ! IS_XML_ENABLE_DOCTYPE_DECL) {  // https://issues.apache.org/jira/browse/UIMA-6064
      documentBuilderFactory.setFeature(DISALLOW_DOCTYPE_DECL, true);
    }
  } catch (ParserConfigurationException e1) {
    UIMAFramework.getLogger().log(Level.WARNING, 
        "DocumentBuilderFactory didn't recognize setting feature " + DISALLOW_DOCTYPE_DECL);
  }
  
  try {
    documentBuilderFactory.setFeature(LOAD_EXTERNAL_DTD, false);
  } catch (ParserConfigurationException e) {
    UIMAFramework.getLogger().log(Level.WARNING, 
        "DocumentBuilderFactory doesn't support feature " + LOAD_EXTERNAL_DTD);
  }
  
  documentBuilderFactory.setXIncludeAware(false);
  documentBuilderFactory.setExpandEntityReferences(false);
  
  return documentBuilderFactory;
}
 
Example #22
Source File: JSR47Logger_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testLogWrapperCreation() throws Exception {
  
  // Set the root logger's level to INFO ... may not be the default
  java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.INFO);

  try {
  org.apache.uima.util.Logger uimaLogger = JSR47Logger_impl.getInstance();
  org.apache.uima.util.Logger classLogger = JSR47Logger_impl.getInstance(this.getClass());
  uimaLogger.setLevel(null);  // causes it to inherit from above
  classLogger.setLevel(null);  // causes it to inherit from above

  // check base configuration
  Assert.assertNotNull(uimaLogger);
  Assert.assertNotNull(classLogger);
  Assert.assertTrue(uimaLogger.isLoggable(Level.INFO));
  Assert.assertTrue(classLogger.isLoggable(Level.INFO));
  } finally {
    java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.INFO);

  }
}
 
Example #23
Source File: NoOpAnnotator.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void initialize(UimaContext aContext) throws ResourceInitializationException {
  super.initialize(aContext);
  
  if (getContext().getConfigParameterValue("FailDuringInitialization") != null) {
    throw new ResourceInitializationException(new FileNotFoundException("Simulated Exception"));
  }

  if (getContext().getConfigParameterValue("ErrorFrequency") != null) {
    errorFrequency = (Integer) getContext().getConfigParameterValue("ErrorFrequency");
    countDown = errorFrequency;
  }

  if (getContext().getConfigParameterValue("CpCDelay") != null) {
    cpcDelay = (Integer) getContext().getConfigParameterValue("CpCDelay");
    System.out.println("NoOpAnnotator.initialize() Initializing With CpC Delay of " + cpcDelay
            + " millis");
  }
  if (getContext().getConfigParameterValue("ProcessDelay") != null) {
    processDelay = (Integer) getContext().getConfigParameterValue("ProcessDelay");
    System.out.println("NoOpAnnotator.initialize() Initializing With Process Delay of "
            + processDelay + " millis");

  }
  if (getContext().getConfigParameterValue("FinalCount") != null) {
    finalCount = (Integer) getContext().getConfigParameterValue("FinalCount");
  }

  // write log messages
  Logger logger = getContext().getLogger();
  logger.log(Level.CONFIG, "NAnnotator initialized");
}
 
Example #24
Source File: Logger_common_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @param marker
 *          the marker data specific to this log statement
 * @param msgSupplier
 *          A function, which when called, produces the desired log message
 */
@Override
public void trace(Marker marker, Supplier<String> msgSupplier, Throwable throwable) {
  if (isLoggable(Level.TRACE, marker) && isNotLimited(Level.TRACE)) {
    log2(marker, fqcnCmn, Level.TRACE, msgSupplier.get(), null, throwable);
  }
}
 
Example #25
Source File: UIMASlf4jWrapperLogger.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
@Override
public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String msgKey,
		Throwable thrown) {
	log(level, String.format("[sourceClass: %s, sourceMethod: %s, bundleName: %s] %s", sourceClass, sourceMethod,
			bundleName, msgKey), thrown);

}
 
Example #26
Source File: Checkpoint.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Prints the list of Process Events in the order that they were produced.
 * 
 * @param lst
 *          List of ProcessEvent
 * @param tCnt
 *          depth of this List in the Process Trace hierarchy
 */
public static void printEveList(List lst, int tCnt) {
  String compNameS;
  String typeS;
  int dur;
  int totDur;
  List subEveList;
  String tabS = "";
  int tabCnt = tCnt;
  for (int j = 0; j < tabCnt; j++) {
    tabS = tabS + "\t";
  }
  for (int i = 0; i < lst.size(); i++) {
    ProcessTraceEvent prEvent = (ProcessTraceEvent) lst.get(i);
    compNameS = prEvent.getComponentName();
    typeS = prEvent.getType();
    dur = prEvent.getDurationExcludingSubEvents();
    totDur = prEvent.getDuration();
    subEveList = prEvent.getSubEvents();
    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(Checkpoint.class).log(
              Level.FINEST,
              tabS + "COMPONENT : " + compNameS + "\tTYPE : " + typeS + "\tDescription : "
                      + prEvent.getDescription());
      UIMAFramework.getLogger(Checkpoint.class).log(Level.FINEST,
              tabS + "TOTAL_TIME : " + totDur + "\tTIME_EXCLUDING_SUBEVENTS : " + dur);
    }
    if (subEveList != null) {
      printEveList(subEveList, (tabCnt + 1));
    }
    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(Checkpoint.class).log(Level.FINEST, " ");
    }
  }
}
 
Example #27
Source File: VinciTAP.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Waits for local/managed service to shutdown. If we dont allow the service time to cleanly
 * terminate, sometimes it just lingers. Since the shutdown command sent in shuthdown() method is
 * one-way call, it was immediately followed by the connection close. That caused an exception on
 * the service side, preventing it from clean exit. So here we just wait until the connection no
 * longer exists and then close it on this side.
 * 
 */
private void waitForServiceShutdown() {
  int retry = 10; // Hard-coded limit.
  // Try until the endpoint is closed by the service OR hard limit of tries
  // has beed exceeded.
  do {
    try {
      // establish ownership of query object, otherwise IllegalMonitorStateException is
      // thrown. Than give the service time to cleanly exit.
      
        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
          UIMAFramework.getLogger(this.getClass()).logrb(
                  Level.FINEST,
                  this.getClass().getName(),
                  "process",
                  CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                  "UIMA_CPM_waiting_for_service_shutdown__FINEST",
                  new Object[] { Thread.currentThread().getName(), String.valueOf(10 - retry),
                      "10" });
        }
        Thread.sleep(100); // wait for 100ms to give the service time to exit cleanly
        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
          UIMAFramework.getLogger(this.getClass()).log(Level.FINEST,
                  " Resuming CPE shutdown.Service should be down now.");
        }
      
    } catch (InterruptedException e) {
    }
    if (retry-- <= 0) {
      break;
    }
  } while (conn.isOpen());

  if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
    UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
            "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
            "UIMA_CPM_service_shutdown_completed__FINEST",
            new Object[] { Thread.currentThread().getName() });
  }
}
 
Example #28
Source File: Logger_common_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @param msgSupplier
 *          A function, which when called, produces the desired log message
 */
@Override
public void info(Supplier<String> msgSupplier) {
  if (isLoggable(Level.INFO) && isNotLimited(Level.INFO)) {
    log2(null, fqcnCmn, Level.INFO, msgSupplier.get(), null, null);
  }
}
 
Example #29
Source File: LocalVNS.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize local VNS instance with a range of ports, and the port for the VNS itself. A given
 * port is tested first for availability. If it is not available the next port is tested, until
 * one is found to be available.
 * 
 * @param aStartPort -
 *          starting port number used
 * @param aEndPort -
 *          end port number. Together with StartPort defines the range of ports (port pool)
 * @param aVNSPort -
 *          port on which this VNS will listen for requests
 * 
 * @throws PortUnreachableException unreachable port after retries
 */
public LocalVNS(int aStartPort, int aEndPort, int aVNSPort) throws PortUnreachableException {
  startport = aStartPort;
  maxport = aEndPort;
  vnsPort = aVNSPort;
  boolean vnsPortAvailable = false;
  int currentRetryCount = 0;
  // Loop until we find a valid port or hard limit of 100 tries is reached
  while (!vnsPortAvailable) {
    if (UIMAFramework.getLogger().isLoggable(Level.INFO)) {
      UIMAFramework.getLogger(this.getClass()).logrb(Level.INFO, this.getClass().getName(),
              "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_test_vns_port__INFO",
              new Object[] { Thread.currentThread().getName(), String.valueOf(vnsPort) });
    }
    vnsPortAvailable = isAvailable(vnsPort);

    if (currentRetryCount > 100) {
      UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE, this.getClass().getName(),
              "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
              "UIMA_CPM_vns_port_not_available__SEVERE",
              new Object[] { Thread.currentThread().getName(), String.valueOf(vnsPort) });

      throw new PortUnreachableException("Unable to aquire a port for VNS Service");
    }
    if (!vnsPortAvailable) {
      vnsPort++;
    }
    currentRetryCount++;
  }
  if (UIMAFramework.getLogger().isLoggable(Level.INFO)) {
    UIMAFramework.getLogger(this.getClass()).logrb(Level.INFO, this.getClass().getName(),
            "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_activating_vns_port__INFO",
            new Object[] { Thread.currentThread().getName(), String.valueOf(vnsPort) });
  }
  onport = startport;
}
 
Example #30
Source File: ProcessingContainer_Impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void resume() {
  synchronized (lockForIsPaused) {
    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
              "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_resuming_container__FINEST",
              new Object[] { Thread.currentThread().getName(), getName() });
    }
    isPaused = false;
    lockForIsPaused.notifyAll();
  }
}