Methods Summary |
---|
public abstract void | close()Closes this handler. A flush operation will be performed and all the
associated resources will be freed. Client applications should not use
this handler after closing it.
|
public abstract void | flush()Flushes any buffered output.
|
private java.lang.Object | getCustomizeInstance(java.lang.String className)
Class<?> c = AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws Exception {
ClassLoader loader = Thread.currentThread()
.getContextClassLoader();
if (null == loader) {
loader = ClassLoader.getSystemClassLoader();
}
return loader.loadClass(className);
}
});
return c.newInstance();
|
private java.lang.Object | getDefaultInstance(java.lang.String className)
Object result = null;
if (null == className) {
return result;
}
try {
result = Class.forName(className).newInstance();
} catch (Exception e) {
//ignore
}
return result;
|
public java.lang.String | getEncoding()Gets the character encoding used by this handler, {@code null} for
default encoding.
return this.encoding;
|
public java.util.logging.ErrorManager | getErrorManager()Gets the error manager used by this handler to report errors during
logging.
LogManager.getLogManager().checkAccess();
return this.errorMan;
|
public java.util.logging.Filter | getFilter()Gets the filter used by this handler.
return this.filter;
|
public java.util.logging.Formatter | getFormatter()Gets the formatter used by this handler to format the logging messages.
return this.formatter;
|
public java.util.logging.Level | getLevel()Gets the logging level of this handler, records with levels lower than
this value will be dropped.
return this.level;
|
void | initProperties(java.lang.String defaultLevel, java.lang.String defaultFilter, java.lang.String defaultFormatter, java.lang.String defaultEncoding)
LogManager manager = LogManager.getLogManager();
//set filter
final String filterName = manager.getProperty(prefix + ".filter"); //$NON-NLS-1$
if (null != filterName) {
try {
filter = (Filter) getCustomizeInstance(filterName);
} catch (Exception e1) {
printInvalidPropMessage("filter", filterName, e1); //$NON-NLS-1$
filter = (Filter) getDefaultInstance(defaultFilter);
}
} else {
filter = (Filter) getDefaultInstance(defaultFilter);
}
//set level
String levelName = manager.getProperty(prefix + ".level"); //$NON-NLS-1$
if (null != levelName) {
try {
level = Level.parse(levelName);
} catch (Exception e) {
printInvalidPropMessage("level", levelName, e); //$NON-NLS-1$
level = Level.parse(defaultLevel);
}
} else {
level = Level.parse(defaultLevel);
}
//set formatter
final String formatterName = manager.getProperty(prefix + ".formatter"); //$NON-NLS-1$
if (null != formatterName) {
try {
formatter = (Formatter) getCustomizeInstance(formatterName);
} catch (Exception e) {
printInvalidPropMessage("formatter", formatterName, e); //$NON-NLS-1$
formatter = (Formatter) getDefaultInstance(defaultFormatter);
}
} else {
formatter = (Formatter) getDefaultInstance(defaultFormatter);
}
//set encoding
final String encodingName = manager.getProperty(prefix + ".encoding"); //$NON-NLS-1$
try {
internalSetEncoding(encodingName);
} catch (UnsupportedEncodingException e) {
printInvalidPropMessage("encoding", encodingName, e); //$NON-NLS-1$
}
|
void | internalSetEncoding(java.lang.String newEncoding)Sets the character encoding used by this handler. A {@code null} value
indicates the use of the default encoding. This internal method does
not check security.
// accepts "null" because it indicates using default encoding
if (null == newEncoding) {
this.encoding = null;
} else {
if (Charset.isSupported(newEncoding)) {
this.encoding = newEncoding;
} else {
// logging.13=The encoding "{0}" is not supported.
throw new UnsupportedEncodingException(Messages.getString(
"logging.13", //$NON-NLS-1$
newEncoding));
}
}
|
void | internalSetFormatter(java.util.logging.Formatter newFormatter)Sets the formatter to be used by this handler. This internal method does
not check security.
if (null == newFormatter) {
throw new NullPointerException();
}
this.formatter = newFormatter;
|
public boolean | isLoggable(java.util.logging.LogRecord record)Determines whether the supplied log record needs to be logged. The
logging levels will be checked as well as the filter.
if (null == record) {
throw new NullPointerException();
}
if (this.level.intValue() == Level.OFF.intValue()) {
return false;
} else if (record.getLevel().intValue() >= this.level.intValue()) {
return null == this.filter || this.filter.isLoggable(record);
}
return false;
|
void | printInvalidPropMessage(java.lang.String key, java.lang.String value, java.lang.Exception e)
// logging.12=Invalid property value for
String msg = new StringBuilder().append(Messages.getString("logging.12")) //$NON-NLS-1$
.append(prefix).append(":").append(key).append("/").append( //$NON-NLS-1$//$NON-NLS-2$
value).toString();
errorMan.error(msg, e, ErrorManager.GENERIC_FAILURE);
|
public abstract void | publish(java.util.logging.LogRecord record)Accepts a logging request and sends it to the the target.
|
protected void | reportError(java.lang.String msg, java.lang.Exception ex, int code)Reports an error to the error manager associated with this handler,
{@code ErrorManager} is used for that purpose. No security checks are
done, therefore this is compatible with environments where the caller
is non-privileged.
this.errorMan.error(msg, ex, code);
|
public void | setEncoding(java.lang.String encoding)Sets the character encoding used by this handler, {@code null} indicates
a default encoding.
LogManager.getLogManager().checkAccess();
internalSetEncoding(encoding);
|
public void | setErrorManager(java.util.logging.ErrorManager em)Sets the error manager for this handler.
LogManager.getLogManager().checkAccess();
if (null == em) {
throw new NullPointerException();
}
this.errorMan = em;
|
public void | setFilter(java.util.logging.Filter newFilter)Sets the filter to be used by this handler.
LogManager.getLogManager().checkAccess();
this.filter = newFilter;
|
public void | setFormatter(java.util.logging.Formatter newFormatter)Sets the formatter to be used by this handler.
LogManager.getLogManager().checkAccess();
internalSetFormatter(newFormatter);
|
public void | setLevel(java.util.logging.Level newLevel)Sets the logging level of the messages logged by this handler, levels
lower than this value will be dropped.
if (null == newLevel) {
throw new NullPointerException();
}
LogManager.getLogManager().checkAccess();
this.level = newLevel;
|