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

The following examples show how to use org.apache.uima.util.Logger#log() . 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: 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 3
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 4
Source File: Misc.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Issues message at warning or fine level (fine if enabled, includes stack trace)
 * @param errorCount the count of errors used to decrease the frequency
 * @param message the message
 * @param logger the logger to use
 */
public static void decreasingWithTrace(AtomicInteger errorCount, String message, Logger logger) {
  if (logger != null) {
    final int c = errorCount.incrementAndGet();
    final int cTruncated = Integer.highestOneBit(c); 
    // log with decreasing frequency
    if (cTruncated == c) {
      if (logger.isLoggable(Level.FINE)) {
        try { throw new Throwable();}
        catch (Throwable e) {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          PrintStream ps = new PrintStream(baos);
          e.printStackTrace(ps);
          message = "Message count: " + c + "; " + message + " Message count indicates messages skipped to avoid potential flooding.\n" + baos.toString();
          logger.log(Level.FINE, message);
        }
      } else {
        message = "Message count: " + c + "; " + message + " Message count indicates messages skipped to avoid potential flooding.";
        logger.log(Level.WARNING, message);
      }
    }
  }
}
 
Example 5
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 6
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 7
Source File: LanguageDetectorResource.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Log language statistics.
 *
 * @param logger
 *            the logger
 */
public synchronized void logLanguageStatistics(Logger logger) {
	if (!statisticsLogged) {
		StringBuilder sb = new StringBuilder();
		sb.append("Languages detected in current collection\n");
		sb.append("-------------------------------------\n");
		for (String language : languageCounter.keySet()) {
			sb.append(language + ": " + languageCounter.get(language) + "\n");
		}
		logger.log(Level.INFO, sb.toString());
		statisticsLogged = true;
	}
}
 
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: 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 10
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 11
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);
  }
}