You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Steven Bethard <st...@gmail.com> on 2008/04/15 20:33:46 UTC
getting the current logging level
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?
Steve
--
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
Re: getting the current logging level
Posted by Michael Baessler <mb...@michael-baessler.de>.
Steven Bethard wrote:
> On Tue, Apr 15, 2008 at 12:33 PM, Steven Bethard
> <st...@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 work.
To get the current log level by just using the UIMA logging API you could do something like this:
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 later
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 since
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
Re: getting the current logging level
Posted by Steven Bethard <st...@gmail.com>.
On Tue, Apr 15, 2008 at 12:33 PM, Steven Bethard
<st...@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