|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.logging.Handler
bb.util.logging.HandlerAbstract
bb.util.logging.HandlerConsole
public class HandlerConsole
Same as ConsoleHandler
except that instead of always logging to System.err
,
this class only logs serious issues to System.err
while non-serious issues get logged to System.out
.
The problem with ConsoleHandler
always logging to System.err
is that there may be monitoring code
which looks at System.err
and concludes that if anything appears, then it must signal a problem.
This is obviously a mistake for many log records (typically Level.INFO
and below logs are not problems).
It can be useful to attach an instance to the root Logger, and have it publish all logs.
It is unclear whether or not this class is multithread safe.
There may be issues with its superclass; see HandlerAbstract
for more discussion.
Concerning the state added by this class, every method is synchronized.
Nested Class Summary | |
---|---|
static class |
HandlerConsole.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private StreamHandler |
errHandler
Used to write serious logs. |
private Level |
levelSerious
All LogRecords with this or a higher Level are considered to be "serious" log events by isSerious . |
private StreamHandler |
outHandler
Used to write non-serious logs. |
Constructor Summary | |
---|---|
HandlerConsole()
Convenience constructor. |
|
HandlerConsole(Level levelSerious)
Fundamental constructor. |
Method Summary | |
---|---|
void |
close()
If isAlive returns true,
then calls super.close before calling . |
void |
flush()
|
boolean |
isSerious(LogRecord record)
Returns true if record's Level has at the same or higher value than levelSerious . |
void |
publish(LogRecord record)
If isAlive or isLoggable (record) returns false, then immediately returns. |
void |
setEncoding(String encoding)
|
void |
setErrorManager(ErrorManager errorManager)
|
void |
setFilter(Filter filter)
|
void |
setFormatter(Formatter formatter)
|
void |
setLevel(Level level)
|
Methods inherited from class bb.util.logging.HandlerAbstract |
---|
configure, getEncodingDefault, getFilterDefault, getFilterProperty, getFormatterDefault, getFormatterProperty, getIntProperty, getLevelDefault, getLevelProperty, getStringProperty, isAlive, isLoggable, setAlive |
Methods inherited from class java.util.logging.Handler |
---|
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, reportError |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private Level levelSerious
isSerious
.
If this field has the value Level.ALL
(which is the lowest valued Level),
then all LogRecords will be logged to System.err
.
Else if this field has the value Level.OFF
(which is the highest valued Level),
then all LogRecords will be logged to System.out
.
Else if this field has some other value,
then the "high value" LogRecords will be logged to System.err
and the "low value" LogRecords will be logged to System.out
.
For example, if this value is Level.WARNING
,
then (ignoring OFF LogRecords) only Level.SEVERE
and WARNING LogRecords will be logged to System.err
,
while all others go to System.out
).
Contract: is never null after construction, but is nulled out once and for all when close
is first called.
private StreamHandler outHandler
Contract: is never null after construction, but is nulled out once and for all when close
is first called.
private StreamHandler errHandler
Contract: is never null after construction, but is nulled out once and for all when close
is first called.
Constructor Detail |
---|
public HandlerConsole()
All this instance's initial configuration comes from the LogManager
properties described in HandlerAbstract.configure
,
except for the levelSerious
field which is assigned from calling
.
In other words, getLevelProperty
(getClass().getName() + ".levelSerious", Level.SEVERE)levelSerious
is set to whatever is defined for it in the logging properties file,
else it defaults to Level.SEVERE if not defined there.
public HandlerConsole(Level levelSerious) throws IllegalArgumentException
All this instance's initial configuration comes from the LogManager
properties described in HandlerAbstract.configure
,
except for the levelSerious
field which is assigned from the param.
IllegalArgumentException
- if levelSerious is nullMethod Detail |
---|
public void close() throws SecurityException
HandlerAbstract
isAlive
returns true,
then calls super.close
before calling setAlive
(false)
.
close
in class HandlerAbstract
SecurityException
public void flush()
flush
in class Handler
public void publish(LogRecord record)
isAlive
or isLoggable
(record) returns false, then immediately returns.
Else publishes record to System.err
if isSerious
(record)
returns true,
else publishes record to System.out
.
publish
in class Handler
public void setFormatter(Formatter formatter) throws SecurityException
setFormatter
in class Handler
SecurityException
public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException
setEncoding
in class Handler
SecurityException
UnsupportedEncodingException
public void setFilter(Filter filter) throws SecurityException
setFilter
in class Handler
SecurityException
public void setErrorManager(ErrorManager errorManager)
setErrorManager
in class Handler
public void setLevel(Level level) throws SecurityException
setLevel
in class Handler
SecurityException
public boolean isSerious(LogRecord record)
value
than levelSerious
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |