uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steven Bethard" <steven.beth...@gmail.com>
Subject Re: getting the current logging level
Date Tue, 15 Apr 2008 21:21:33 GMT
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?

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.

Steve

P.S. Are there any plans to replace the UIMA Logger APIs with the
java.util.logging APIs?
-- 
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
 --- Bucky Katt, Get Fuzzy

Mime
View raw message