Java Code Examples for org.apache.uima.UIMAFramework#getLogger()

The following examples show how to use org.apache.uima.UIMAFramework#getLogger() . 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: GuiErrorImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void newError(int severity, String message, Exception exception) {
  Logger log = UIMAFramework.getLogger();
  log.log(logLevels[severity], GUI.theGUI.pnG.showInStatus("JCasGen " + sevMsg[severity] + ": "
          + message), exception);
  if (null != exception) {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(b);
    exception.printStackTrace(ps);
    ps.flush();
    GUI.theGUI.pnG.showInStatus(b.toString());
    ps.close();
  }

  if (IError.WARN < severity)
    throw new ErrorExit();
}
 
Example 2
Source File: LoggingTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testDefaultLoggerCreation() throws Exception {
  try {
    // get default logger
    Logger logger = UIMAFramework.getLogger();
    Assert.assertNotNull(logger);

    // create another logger
    Logger logger1 = UIMAFramework.getLogger();

    // both loggers must reference the same instance
    Assert.assertEquals(logger, logger1);

    // test base logging functions
    logger.log(Level.SEVERE, "Log test messege with Level SEVERE");

    // https://issues.apache.org/jira/browse/UIMA-5719
    logger.logrb(Level.WARNING, "testClass", "testMethod", "org.apache.uima.impl.log_messages", "UIMA_external_override_ignored__CONFIG", new Object[] { "n1", "${abc}" });
  } catch (Exception ex) {
    JUnitExtension.handleException(ex);
  }
}
 
Example 3
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 4
Source File: UimacppAnalysisComponent.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public static void log(int msglevel, String sourceClass, String sourceMethod, String message) {
  Logger uimacppLogger = UIMAFramework.getLogger(UimacppAnalysisComponent.class);
  Level level = Level.INFO; // default
  if (msglevel == TAF_LOGLEVEL_MESSAGE) {
    level = Level.INFO;
  } else if (msglevel == TAF_LOGLEVEL_WARNING) {
    level = Level.WARNING;
  } else if (msglevel == TAF_LOGLEVEL_ERROR) {
    level = Level.SEVERE;
  }
  if (sourceMethod.length() > 0)
    uimacppLogger.log(level, sourceClass + "::" + sourceMethod + ": " + message);
  else
    uimacppLogger.log(level, sourceClass + ": " + message);

  // TODO: add Logger method log(level, sourceClass, sourceMethod, message);
}
 
Example 5
Source File: TestLog4jLogger_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testLoggerFromUIMAFramework() {
   org.apache.uima.util.Logger logger = UIMAFramework.getLogger(this
         .getClass());

   logger.setLevel(Level.INFO);

   // File file = File.createTempFile("LoggingTest","log");
   // file.deleteOnExit();

   // change output temporary file
   // logger.setOutputStream(new PrintStream(new FileOutputStream(file)));

   // log test with method log(Level,String)
   logger.log(Level.INFO,
         "------------------------------------------------------------");
   logger.log(Level.INFO, "My first test message");
   logger.log(Level.INFO, "message with \"{0}\"", "substitute");
   logger.info("message with \"{}\"", "substitute");  // new logger style
   logger.info("message with \"{}\"", new Object[] {"substitute"});  // new logger style
   
   // https://issues.apache.org/jira/browse/UIMA-5719
   logger.logrb(Level.WARNING, "testClass", "testMethod", "org.apache.uima.impl.log_messages", "UIMA_external_override_ignored__CONFIG", new Object[] { "n1", "${abc}" });


}
 
Example 6
Source File: PearAnalysisEngineWrapper.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public CasIterator processAndOutputNewCASes(CAS aCAS)
       throws AnalysisEngineProcessException {

  Logger logger = UIMAFramework.getLogger(this.getClass()); 
  if (logger.isLoggable(Level.FINE)) {
    UIMAFramework.getLogger(this.getClass()).logrb(Level.FINE,
          this.getClass().getName(), "processAndOutputNewCASes",
          LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_process_begin__FINE",
          new Object[] { this.ae.getAnalysisEngineMetaData().getName() });
  }
  
  CasIterator result = this.ae.processAndOutputNewCASes(aCAS);
  if (logger.isLoggable(Level.FINE)) {    
    UIMAFramework.getLogger(this.getClass()).logrb(Level.FINE,
          this.getClass().getName(), "processAndOutputNewCASes",
          LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_process_end__FINE",
          new Object[] { this.ae.getAnalysisEngineMetaData().getName() });
  }
  return result;
}
 
Example 7
Source File: FSClassRegistry.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private static void reportErrors() {
    boolean throwWhenDone = false;
    List<ErrorReport> es = errorSet.get();
    if (es != null) {
      StringBuilder msg = new StringBuilder(100);
//      msg.append('\n');  // makes a break in the message at the beginning, unneeded
      for (ErrorReport f : es) {
        msg.append(f.e.getMessage());
        throwWhenDone = throwWhenDone || f.doThrow;
        msg.append('\n');
      }
      errorSet.set(null); // reset after reporting
      if (throwWhenDone) {
        throw new CASRuntimeException(CASException.JCAS_INIT_ERROR, "\n" + msg);
      } else {
        Logger logger = UIMAFramework.getLogger();
        if (null == logger) {
          throw new CASRuntimeException(CASException.JCAS_INIT_ERROR, "\n" + msg);
        } else {
          logger.log(Level.WARNING, msg.toString());
        }          
      }
    }
  }
 
Example 8
Source File: MultiPageEditor.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void newError(int severity, String message, Exception ex) {
  Logger log = UIMAFramework.getLogger();
  log.log(logLevels[severity], "JCasGen: " + message); //$NON-NLS-1$
  System.out.println(Messages.getString("MultiPageEditor.JCasGenErr") //$NON-NLS-1$
          + message);
  if (null != ex)
    ex.printStackTrace();
  if (IError.WARN < severity) {
    m_message = message;
    throw new Jg.ErrorExit();
  }
}
 
Example 9
Source File: LoggingTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testSetLevel() throws Exception {
  Logger uimaLogger = UIMAFramework.getLogger(); // should affect everything in
  // org.apache.uima.*
  try {

    // get class logger
    Logger logger = UIMAFramework.getLogger(this.getClass());

    // set level to WARNING
    uimaLogger.setLevel(Level.WARNING);
    Assert.assertTrue(uimaLogger.isLoggable(Level.WARNING));
    Assert.assertTrue(uimaLogger.isLoggable(Level.SEVERE));
    Assert.assertFalse(uimaLogger.isLoggable(Level.INFO));
    Assert.assertTrue(logger.isLoggable(Level.WARNING));
    Assert.assertTrue(logger.isLoggable(Level.SEVERE));
    Assert.assertFalse(logger.isLoggable(Level.INFO));

    // set level to FINE
    uimaLogger.setLevel(Level.FINE);
    Assert.assertTrue(uimaLogger.isLoggable(Level.WARNING));
    Assert.assertTrue(uimaLogger.isLoggable(Level.SEVERE));
    Assert.assertTrue(uimaLogger.isLoggable(Level.INFO));
    Assert.assertFalse(uimaLogger.isLoggable(Level.FINER));
    Assert.assertFalse(uimaLogger.isLoggable(Level.ALL));
    Assert.assertTrue(logger.isLoggable(Level.WARNING));
    Assert.assertTrue(logger.isLoggable(Level.SEVERE));
    Assert.assertTrue(logger.isLoggable(Level.INFO));
    Assert.assertFalse(logger.isLoggable(Level.FINER));
    Assert.assertFalse(logger.isLoggable(Level.ALL));
  } catch (Exception ex) {
    JUnitExtension.handleException(ex);
  } finally {
    uimaLogger.setLevel(Level.INFO); // otherwise, is stuck at INFO, too much logging
  }

}
 
Example 10
Source File: LoggingTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testClassLoggerCreation() throws Exception {
  try {
    // get class logger
    Logger logger = UIMAFramework.getLogger(this.getClass());
    Assert.assertNotNull(logger);

    // create another class logger
    Logger logger1 = UIMAFramework.getLogger(this.getClass());

    // create default logger
    Logger defaultLogger = UIMAFramework.getLogger();

    // both loggers must reference the same instance
    Assert.assertEquals(logger, logger1);

    // should not be the same
    Assert.assertNotSame(defaultLogger, logger1);

    // test base logging functions
    logger.log(Level.SEVERE, "Log test messege with Level SEVERE");
    
    // https://issues.apache.org/jira/browse/UIMA-5719
    logger.logrb(Level.WARNING, "testClass", "testMethod", "org.apache.uima.impl.log_messages", "UIMA_external_override_ignored__CONFIG", new Object[] { "n1", "${abc}" });
  } catch (Exception ex) {
    JUnitExtension.handleException(ex);
  }
}
 
Example 11
Source File: TypeSystemImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
   * ******** OBSOLETE  - only left in for supporting some jcas style in alpha level *************
 * This code is run when a JCas class is loaded and resolved, for the first time, as part of type system commit, or
 * as part of statically loading the FSClassRegister class (where this is done for all the built-ins, once).
 * It looks up the offset value in the type system (via a thread-local)
 *
 * hidden parameter: threadLocal value: referencing this type
 * @param featName -
 * @return the offset in the int or ref data arrays for the named feature
 */
// ******** OBSOLETE  - only left in for supporting some jcas style in alpha level *************
public static synchronized int getAdjustedFeatureOffset(String featName) {
  /* The JCas class being loaded was generated for the "alpha" level of UIMA v3,
   * and is not supported for Beta and later levels.
   * 
   * This can be fixed by regenerating this using the current v3 version of UIMA tooling
   * (JCasgen, or the migration tooling to migrate from v2).
   */
  Logger logger = UIMAFramework.getLogger(TypeSystemImpl.class);
  logger.warn(() -> logger.rb_ue(CASRuntimeException.JCAS_ALPHA_LEVEL_NOT_SUPPORTED)); 
  return -1;
}
 
Example 12
Source File: LogThrowErrorImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void newError(int severity, String message, Exception exception) {
  Logger log = UIMAFramework.getLogger();
  log.log(logLevels[severity], "JCasGen: " + message, exception);
  if (IError.WARN < severity)
    throw new ErrorExit();
}
 
Example 13
Source File: FunctionErrorStore.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
protected FunctionErrorStore(String exception, int functionCount, String functionName) {
  functionCounter = functionCount;
  functionError = exception;
  this.functionName = functionName;
  logger = UIMAFramework.getLogger(this.getClass());
  // logger = Logger_impl.getInstance();
}
 
Example 14
Source File: Resource_ImplBase.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Get the logger for this UIMA framework class.
 * Note that this is NOT the user's logger in the UimaContext
 */
@Override
public Logger getLogger() {
  return UIMAFramework.getLogger(this.getClass());
}
 
Example 15
Source File: FlowControllerContainer.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  UimaContext prevContext = setContextHolder();   // Get this early so the restore in correct
  try {
    // specifier must be a FlowControllerDescription. (Eventually, we
    // might support remote specifiers, but not yet)
    if (!(aSpecifier instanceof FlowControllerDescription)) {
      throw new ResourceInitializationException(
              ResourceInitializationException.NOT_A_FLOW_CONTROLLER_DESCRIPTOR, new Object[] {
                  aSpecifier.getSourceUrlString(), aSpecifier.getClass().getName() });
    }
    ResourceCreationSpecifier desc = (ResourceCreationSpecifier) aSpecifier;

    // also framework implementation must start with org.apache.uima.java
    final String fwImpl = desc.getFrameworkImplementation();
    if (fwImpl == null
            || !fwImpl.equalsIgnoreCase(Constants.JAVA_FRAMEWORK_NAME)) {
      throw new ResourceInitializationException(
              ResourceInitializationException.UNSUPPORTED_FRAMEWORK_IMPLEMENTATION, new Object[] {
                  fwImpl, aSpecifier.getSourceUrlString() });
    }

    super.initialize(aSpecifier, aAdditionalParams);

    // validate the descriptor
    desc.validate(getResourceManager());

    // instantiate FlowController
    mFlowController = instantiateFlowController(desc);

    // record metadata
    setMetaData(desc.getMetaData());

    // add our metadata to the CasManager, so that it will pick up our
    // type system, priorities, and indexes
    getCasManager().addMetaData(getProcessingResourceMetaData());

    // determine if this component is Sofa-aware (based on whether it
    // declares any input or output sofas in its capabilities)
    mSofaAware = getProcessingResourceMetaData().isSofaAware();
    
    // Set Logger, to enable component-specific logging configuration
    UimaContextAdmin uimaContext = getUimaContextAdmin();
    Logger logger = UIMAFramework.getLogger(mFlowController.getClass());
    logger.setResourceManager(this.getResourceManager());
    uimaContext.setLogger(logger);
    
    Logger classLogger = getLogger();
    classLogger.logrb(Level.CONFIG, this.getClass().getName(), "initialize", LOG_RESOURCE_BUNDLE,
            "UIMA_flow_controller_init_begin__CONFIG", getMetaData().getName());
    
    // initialize FlowController
    mFlowController.initialize(getFlowControllerContext());

    mMBeanServer = null;
    String mbeanNamePrefix = null;
    if (aAdditionalParams != null) {
      mMBeanServer = aAdditionalParams.get(AnalysisEngine.PARAM_MBEAN_SERVER);
      mbeanNamePrefix = (String)aAdditionalParams.get(AnalysisEngine.PARAM_MBEAN_NAME_PREFIX);
    }
    // update MBean with the name taken from metadata
    getMBean().setName(getMetaData().getName(), getUimaContextAdmin(), mbeanNamePrefix);
    // register MBean with MBeanServer. If no MBeanServer specified in the
    // additionalParams map, this will use the platform MBean Server
    // (Java 1.5 only)
    JmxMBeanAgent.registerMBean(getMBean(), mMBeanServer);

    classLogger.logrb(Level.CONFIG, this.getClass().getName(), "initialize", LOG_RESOURCE_BUNDLE,
            "UIMA_flow_controller_init_successful__CONFIG", getMetaData().getName());
    
    initialized = true;
    return true;
  } catch (ResourceConfigurationException e) {
    throw new ResourceInitializationException(e);
  } finally {
    UimaContextHolder.setContext(prevContext);
  }
}
 
Example 16
Source File: NewsleakPreprocessor.java    From newsleak with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Instantiates a new newsleak preprocessor.
 */
public NewsleakPreprocessor() {
	super();
	logger = UIMAFramework.getLogger();
}
 
Example 17
Source File: AnalysisEngineDescription_implTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void testMulticoreInitialize() throws Exception {
    ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
    ConfigurationManager configManager = UIMAFramework.newConfigurationManager();
    Logger logger = UIMAFramework.getLogger(this.getClass());
    logger.setResourceManager(resourceManager);
 
    UimaContext uimaContext = UIMAFramework.newUimaContext(logger, resourceManager, configManager);
    
    final Map<String, Object> p = new HashMap<>();
    p.put(UIMAFramework.CAS_INITIAL_HEAP_SIZE,  200);
    p.put(Resource.PARAM_CONFIG_MANAGER, configManager);
    p.put(Resource.PARAM_RESOURCE_MANAGER,  UIMAFramework.newDefaultResourceManager());
    p.put(Resource.PARAM_UIMA_CONTEXT, uimaContext);
    int numberOfThreads = Math.min(50, Misc.numberOfCores * 5); 
    final AnalysisEngine[] aes = new AnalysisEngine[numberOfThreads];
    System.out.format("test multicore initialize with %d threads%n",
        numberOfThreads);
    
    
    MultiThreadUtils.Run2isb run2isb = new MultiThreadUtils.Run2isb() {
      
      public void call(int i, int r, StringBuilder sb) throws Exception {
        Random random = new Random();
        for (int j = 0; j < 2; j++) {
          aes[i] = UIMAFramework.produceAnalysisEngine(primitiveDesc, p);     
  //        System.out.println(sb.toString());
  //        System.out.print('.');
          if ((i % 2) == 0) {
            Thread.sleep(0, random.nextInt(2000));
          }
        }
      }
    };  
    MultiThreadUtils.tstMultiThread("MultiCoreInitialize",  numberOfThreads,  100, run2isb, MultiThreadUtils.emptyReset);
    assertTrue(!aes[0].equals(aes[1]));
    
    run2isb = new MultiThreadUtils.Run2isb() {
      
      public void call(int i, int r, StringBuilder sb) throws Exception {
        Random random = new Random();
        for (int j = 0; j < 2; j++) {
          aes[i] = UIMAFramework.produceAnalysisEngine(aggregateDesc, p);     
  //        System.out.println(sb.toString());
  //        System.out.print('.');
          if ((i % 2) == 0) {
            Thread.sleep(0, random.nextInt(5000));
          }
        }
      }
    };
    MultiThreadUtils.tstMultiThread("MultiCoreInitialize",  numberOfThreads,  100, run2isb, MultiThreadUtils.emptyReset);
    assertTrue(!aes[0].equals(aes[1]));

    
//    System.out.println("");
  }
 
Example 18
Source File: XmiCasSerializer.java    From uima-uimaj with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new XmiCasSerializer
 * @param ts
 *          An optional typeSystem (or null) to filter the types that will be serialized. If any CAS that is later passed to
 *          the <code>serialize</code> method that contains types and features that are not in
 *          this typesystem, the serialization will not contain instances of those types or values
 *          for those features. So this can be used to filter the results of serialization.
 * @param nsUriToSchemaLocationMap
 *          Map if supplied, this map is used to generate a "schemaLocation" attribute in the XMI
 *          output. This argument must be a map from namespace URIs to the schema location for
 *          that namespace URI.
 * @param isFormattedOutput true makes serialization pretty print
 */
public XmiCasSerializer(TypeSystem ts, Map<String, String> nsUriToSchemaLocationMap, boolean isFormattedOutput) {
  css.filterTypeSystem = (TypeSystemImpl) ts;
  this.nsUriToSchemaLocationMap = nsUriToSchemaLocationMap;
  css.logger = UIMAFramework.getLogger(XmiCasSerializer.class);
  css.isFormattedOutput = isFormattedOutput;
}