Java Code Examples for org.apache.uima.util.Logger#logrb()

The following examples show how to use org.apache.uima.util.Logger#logrb() . 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: 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 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: 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 4
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 5
Source File: PrimitiveAnalysisEngine_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * @see org.apache.uima.resource.Resource#initialize(ResourceSpecifier, Map)
 */
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  try {
    // Primitive AnalysisEngine can be build from any ResourceCreationSpecifier-
    // this includes CollectionReader, and CasConsumer descriptors
    // as well as AnalysisEngine descriptors.

    if (!(aSpecifier instanceof ResourceCreationSpecifier)) {
      return false;
    }

    // BUT, for AnalysisEngineDescriptions, must not be an aggregate
    if (aSpecifier instanceof AnalysisEngineDescription
            && !((AnalysisEngineDescription) aSpecifier).isPrimitive()) {
      return false;
    }

    mDescription = (ResourceCreationSpecifier) aSpecifier;

    // also framework implementation must start with org.apache.uima.java
    final String fwImpl = mDescription.getFrameworkImplementation();
    if (!fwImpl.startsWith(Constants.JAVA_FRAMEWORK_NAME)) {
      return false;
    }

    super.initialize(aSpecifier, aAdditionalParams);
    ProcessingResourceMetaData md = (ProcessingResourceMetaData) mDescription.getMetaData();
    if (null == md) {
      md = UIMAFramework.getResourceSpecifierFactory().createProcessingResourceMetaData();
      md.setName("(null)");
    }

    // Get logger for this class
    Logger logger = getLogger();
    logger.logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", LOG_RESOURCE_BUNDLE,
            "UIMA_analysis_engine_init_begin__CONFIG", md.getName());

    // Normalize language codes. Need to do this since a wide variety of
    // spellings are acceptable according to ISO.
    normalizeIsoLangCodes(md);

    // clone this metadata and assign a UUID if not already present
    ResourceMetaData mdCopy = (ResourceMetaData) md.clone();

    if (mdCopy.getUUID() == null) {
      mdCopy.setUUID(UUIDGenerator.generate());
    }
    setMetaData(mdCopy);

    // validate the AnalysisEngineDescription and throw a
    // ResourceInitializationException if there is a problem
    mDescription.validate(getResourceManager());

    // Read parameters from the aAdditionalParams map.
    if (aAdditionalParams == null) {
      aAdditionalParams = Collections.emptyMap();
    }
    // determine if verification mode is on
    mVerificationMode = aAdditionalParams.containsKey(PARAM_VERIFICATION_MODE);

    // determine if this component is Sofa-aware (based on whether it
    // declares any input or output sofas in its capabilities)
    mSofaAware = getAnalysisEngineMetaData().isSofaAware();

    initializeAnalysisComponent(aAdditionalParams);

    // Initialize ResultSpec based on output capabilities
    // TODO: should only do this for outermost AE
    resetResultSpecificationToDefault();

    logger.logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", LOG_RESOURCE_BUNDLE,
            "UIMA_analysis_engine_init_successful__CONFIG", md.getName());
    return true;
  } catch (ResourceConfigurationException e) {
    throw new ResourceInitializationException(
            ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] {
                getMetaData().getName(), aSpecifier.getSourceUrlString() });
  }
}