uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Baessler <...@michael-baessler.de>
Subject Re: getting the current logging level
Date Wed, 16 Apr 2008 09:06:12 GMT
Steven Bethard wrote:
> On Tue, Apr 15, 2008 at 12:33 PM, Steven Bethard
> <steven.bethard@gmail.com> wrote:
>> So I'm writing some unit tests that check that my AnalysisEngines are
>>  throwing exceptions in the right places, however, before my test code
>>  can catch the exception, UIMA has already written the exception to the
>>  logger at level SEVERE. The tests still complete correctly, which is
>>  good, but I'd like to be able to suppress UIMA's logging output. To do
>>  this correctly, I should really:
>>  * get the current logging level
>>  * set the logging level to Level.OFF
>>  * run my exception checking test
>>  * restore the logging level to the original value
>>  Now org.apache.uima.util.Logger has a setLevel method, but no getLevel
>>  method. How can I get the current logging level?  Or is there another
>>  way to temporarily disable logging?

Right, the current UIMA logger interface cannot return the log level. To
disable the logging you have to set the log level to OFF for the current used
logger. The current used logger can either be a UIMA component logger (e.g. for annotator
components) or the UIMA root logger ("org.apache.uima" - used in the UIMA framework). The
UIMA root
logger is the parent logger for all UIMA component loggers.

> So I dug through the UIMA source code, and I've developed the
> following utility functions which use the java.util.logging APIs
> instead of the UIMA APIs::
>     public static Level disableLogging() {
>         Logger logger = Logger.getLogger("org.apache.uima");
>         while (logger.getLevel() == null) {
>             logger = logger.getParent();
>         }
>         Level level = logger.getLevel();
>         logger.setLevel(Level.OFF);
>         return level;
>     }
>     public static void enableLogging(Level level) {
>         Logger logger = Logger.getLogger("org.apache.uima");
>         logger.setLevel(level);
>     }
> If anyone sees anything easier than this, please let me know.
This works as long as UIMA use the Java logging as underlying logging framework.
If you configure to use for example a different logging framework, e.g. Log4J this doesn't

To get the current log level by just using the UIMA logging API you could do something like

   private Level getCurrentUIMALogLevel() {
      if (UIMAFramework.getLogger().isLoggable(Level.ALL)) {
         return Level.ALL;
      } else if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
         return Level.FINEST;
      } else if (UIMAFramework.getLogger().isLoggable(Level.FINER)) {
         return Level.FINER;
      } else if (UIMAFramework.getLogger().isLoggable(Level.FINE)) {
         return Level.FINE;
      } else if (UIMAFramework.getLogger().isLoggable(Level.CONFIG)) {
         return Level.CONFIG;
      } else if (UIMAFramework.getLogger().isLoggable(Level.INFO)) {
         return Level.INFO;
      } else if (UIMAFramework.getLogger().isLoggable(Level.WARNING)) {
         return Level.WARNING;
      } else if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
         return Level.SEVERE;
      } else {
         return Level.OFF;

UIMAFramework.getLogger() returns the UIMA root logger "org.apache.uima". This logger can
also be used to reset the log level.

> P.S. Are there any plans to replace the UIMA Logger APIs with the
> java.util.logging APIs?

There are no plans to replace the UIMA Logger APIs with a specific logging implementation
we would like to support more than one logging implementation e.g. Java Logging and Log4j.
But maybe we can extend the logging interface to return the current log level.
Feel free to open a JIRA task/improvement to track that.

-- Michael

View raw message