Top Description Fields Constructors Methods
org.jboss.logmanager

public abstract Class ExtHandler

extends Handler
implements AutoCloseable, Flushable
Class Inheritance
All Implemented Interfaces
java.io.Flushable, java.lang.AutoCloseable
Known Direct Subclasses
org.jboss.logmanager.handlers.AsyncHandler, org.jboss.logmanager.handlers.DelayedHandler, org.jboss.logmanager.handlers.QueueHandler, org.jboss.logmanager.handlers.SocketHandler, org.jboss.logmanager.handlers.SyslogHandler, org.jboss.logmanager.handlers.WriterHandler
Imports
java.io.Flushable, .UnsupportedEncodingException, java.nio.charset.Charset, .StandardCharsets, java.security.Permission, java.util.Objects, java.util.concurrent.atomic.AtomicReferenceFieldUpdater, java.util.concurrent.locks.ReentrantLock, java.util.logging.ErrorManager, .Filter, .Formatter, .Handler, .Level, .LogRecord, .LoggingPermission, org.jboss.logmanager.errormanager.OnlyOnceErrorManager

An extended logger handler. Use this class as a base class for log handlers which require ExtLogRecord instances.

Field Summary

Modifier and TypeField and Description
private volatile boolean
private volatile Charset
private volatile boolean
private static final Permission
private static final ErrorManager
private volatile boolean
private volatile ErrorManager
private volatile Filter
private volatile Formatter
protected volatile Handler[]
handlers

The sub-handlers for this handler.

protected static final AtomicArray<ExtHandler, Handler>
handlersUpdater

The atomic updater for the handlers field.

private volatile Level
protected final ReentrantLock

Constructor Summary

AccessConstructor and Description
protected
ExtHandler()

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
public void
addHandler(Handler
the handler to add
handler
)

Add a sub-handler to this handler.

protected static void
checkAccess()

Check access.

protected static void
checkAccess(final ExtHandler
the handler to check access on.
handler
)
Deprecated

Check access.

public Handler[]

Returns:

the old sub-handler array
clearHandlers
()

A convenience method to atomically get and clear all sub-handlers.

public void
close()

Implements abstract java.util.logging.Handler.close.

Implements java.lang.AutoCloseable.close.

Close all child handlers.

protected void
doPublish(final ExtLogRecord
the log record to publish
record
)

Do the actual work of publication; the record will have been filtered already.

public void
flush()

Implements abstract java.util.logging.Handler.flush.

Implements java.io.Flushable.flush.

Flush all child handlers.

private static boolean
public Charset

Returns:

the character set in use (not null)
getCharset
()

Get the handler's character set.

public String

Returns:

the handler character set name
getEncoding
()

Overrides java.util.logging.Handler.getEncoding.

Get the name of the handler's character set.

public ErrorManager
getErrorManager()

Overrides java.util.logging.Handler.getErrorManager.

Retrieves the ErrorManager for this Handler.

public Filter
getFilter()

Overrides java.util.logging.Handler.getFilter.

Get the current Filter for this Handler.

public Formatter
getFormatter()

Overrides java.util.logging.Handler.getFormatter.

Return the Formatter for this Handler.

public Handler[]

Returns:

a copy of the sub-handlers array
getHandlers
()

Get a copy of the sub-handlers array.

public Level
getLevel()

Overrides java.util.logging.Handler.getLevel.

Get the log level specifying which messages will be logged by this Handler.

public boolean

Returns:

true if auto-flush is enabled
isAutoFlush
()

Determine if this handler will auto-flush.

public boolean

Returns:

true if the caller should be calculated, otherwise false if it can be skipped
isCallerCalculationRequired
()

Indicates whether or not the formatter associated with this handler or a formatter from a child handler requires the caller to be calculated.

public boolean

Returns:

true if the children handlers should be closed when this handler is closed, false if children handlers should not be closed when this handler is closed
isCloseChildren
()

Indicates whether or not children handlers should be closed when this handler is closed.

public final boolean

Returns:

true if the handler is enabled, otherwise false.
isEnabled
()

Determine if the handler is enabled.

public void
publish(final LogRecord
description of the log event. A null record is silently ignored and is not published
record
)

Implements abstract java.util.logging.Handler.publish.

Publish a LogRecord.

public void
publish(final ExtLogRecord
the log record to publish
record
)

Publish an ExtLogRecord.

protected void
publishToNestedHandlers(final ExtLogRecord
the log record to publish
record
)

Publish a log record to each nested handler.

public void
removeHandler(Handler
the handler to remove
handler
)

Remove a sub-handler from this handler.

protected void
reportError(String
a descriptive string (may be null)
msg
,
Exception
an exception (may be null)
ex
,
int
an error code defined in ErrorManager
code
)

Overrides java.util.logging.Handler.reportError.

Protected convenience method to report an error to this Handler's ErrorManager.

public static void
reportError(Handler
the handler
handler
,
String
the error message
msg
,
Exception
the exception
ex
,
int
the error code
code
)

Report an error using a handler's specific error manager, if any.

public void
setAutoFlush(final boolean
true to automatically flush after each write; false otherwise
autoFlush
)

Change the autoflush setting for this handler.

public void
setCharset(final Charset
the character set (must not be null)
charset
)

Set the handler's character set.

protected void
setCharsetPrivate(final Charset
the character set (must not be null)
charset
)

Set the handler's character set from within this handler.

public void
setCloseChildren(final boolean
true if all children handlers should be closed when this handler is closed, false if children handlers will not be closed when this handler is closed
closeChildren
)

Sets whether or not children handlers should be closed when this handler is closed.

public final void
setEnabled(final boolean
true to enable the handler or false to disable the handler.
enabled
)

Enables or disables the handler based on the value passed in.

public void
setEncoding(final String
the name of the encoding
encoding
)

Overrides java.util.logging.Handler.setEncoding.

Set the handler's character set by name.

public void
setErrorManager(final ErrorManager
the new ErrorManager
em
)

Overrides java.util.logging.Handler.setErrorManager.

Define an ErrorManager for this Handler.

public void
setFilter(final Filter
a Filter object (may be null)
newFilter
)

Overrides java.util.logging.Handler.setFilter.

Set a Filter to control output on this Handler.

public void
setFormatter(final Formatter
the Formatter to use (may not be null)
newFormatter
)

Overrides java.util.logging.Handler.setFormatter.

Set a Formatter.

public Handler[]

Returns:

the old sub-handler array
setHandlers
(final Handler[]
the new sub-handlers
newHandlers
)

A convenience method to atomically get and replace the sub-handler array.

public void
setLevel(final Level
the new value for the log level
newLevel
)

Overrides java.util.logging.Handler.setLevel.

Set the log level specifying which message levels will be logged by this Handler.

Inherited from java.util.logging.Handler:
isLoggable

Field Detail

autoFlushback to summary
private volatile boolean autoFlush
charsetback to summary
private volatile Charset charset
closeChildrenback to summary
private volatile boolean closeChildren
CONTROL_PERMISSIONback to summary
private static final Permission CONTROL_PERMISSION
DEFAULT_ERROR_MANAGERback to summary
private static final ErrorManager DEFAULT_ERROR_MANAGER
enabledback to summary
private volatile boolean enabled
errorManagerback to summary
private volatile ErrorManager errorManager

Hides java.util.logging.Handler.errorManager.

filterback to summary
private volatile Filter filter

Hides java.util.logging.Handler.filter.

formatterback to summary
private volatile Formatter formatter

Hides java.util.logging.Handler.formatter.

handlersback to summary
protected volatile Handler[] handlers

The sub-handlers for this handler. May only be updated using the handlersUpdater atomic updater. The array instance should not be modified (treat as immutable).

Annotations
@SuppressWarnings:unused
handlersUpdaterback to summary
protected static final AtomicArray<ExtHandler, Handler> handlersUpdater

The atomic updater for the handlers field.

levelback to summary
private volatile Level level
lockback to summary
protected final ReentrantLock lock

Hides java.util.logging.Handler.lock.

Constructor Detail

ExtHandlerback to summary
protected ExtHandler()

Construct a new instance.

Method Detail

addHandlerback to summary
public void addHandler(Handler handler) throws SecurityException

Add a sub-handler to this handler. Some handler types do not utilize sub-handlers.

Parameters
handler:Handler

the handler to add

Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
checkAccessback to summary
protected static void checkAccess() throws SecurityException

Check access.

Exceptions
SecurityException:
if a security manager is installed and the caller does not have the "control" LoggingPermission
checkAccessback to summary
protected static void checkAccess(final ExtHandler handler) throws SecurityException

Deprecated

Check access.

Parameters
handler:ExtHandler

the handler to check access on.

Annotations
@Deprecated
Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
clearHandlersback to summary
public Handler[] clearHandlers() throws SecurityException

A convenience method to atomically get and clear all sub-handlers.

Returns:Handler[]

the old sub-handler array

Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
closeback to summary
public void close() throws SecurityException

Implements abstract java.util.logging.Handler.close.

Implements java.lang.AutoCloseable.close.

Close all child handlers.

Annotations
@Override
Exceptions
SecurityException:

Doc from java.util.logging.Handler.close.

if a security manager exists and if the caller does not have LoggingPermission("control").

doPublishback to summary
protected void doPublish(final ExtLogRecord record)

Do the actual work of publication; the record will have been filtered already. The default implementation does nothing except to flush if the autoFlush property is set to true; if this behavior is to be preserved in a subclass then this method should be called after the record is physically written.

Parameters
record:ExtLogRecord

the log record to publish

flushback to summary
public void flush()

Implements abstract java.util.logging.Handler.flush.

Implements java.io.Flushable.flush.

Flush all child handlers.

Annotations
@Override
formatterRequiresCallerCalculationback to summary
private static boolean formatterRequiresCallerCalculation(final Formatter formatter)
getCharsetback to summary
public Charset getCharset()

Get the handler's character set.

Returns:Charset

the character set in use (not null)

getEncodingback to summary
public String getEncoding()

Overrides java.util.logging.Handler.getEncoding.

Get the name of the handler's character set.

Returns:String

the handler character set name

Annotations
@Override
getErrorManagerback to summary
public ErrorManager getErrorManager()

Overrides java.util.logging.Handler.getErrorManager.

Doc from java.util.logging.Handler.getErrorManager.

Retrieves the ErrorManager for this Handler.

Returns:ErrorManager

the ErrorManager for this Handler

Annotations
@Override
getFilterback to summary
public Filter getFilter()

Overrides java.util.logging.Handler.getFilter.

Doc from java.util.logging.Handler.getFilter.

Get the current Filter for this Handler.

Returns:Filter

a Filter object (may be null)

Annotations
@Override
getFormatterback to summary
public Formatter getFormatter()

Overrides java.util.logging.Handler.getFormatter.

Doc from java.util.logging.Handler.getFormatter.

Return the Formatter for this Handler.

Returns:Formatter

the Formatter (may be null).

Annotations
@Override
getHandlersback to summary
public Handler[] getHandlers()

Get a copy of the sub-handlers array. Since the returned value is a copy, it may be freely modified.

Returns:Handler[]

a copy of the sub-handlers array

getLevelback to summary
public Level getLevel()

Overrides java.util.logging.Handler.getLevel.

Doc from java.util.logging.Handler.getLevel.

Get the log level specifying which messages will be logged by this Handler. Message levels lower than this level will be discarded.

Returns:Level

the level of messages being logged.

Annotations
@Override
isAutoFlushback to summary
public boolean isAutoFlush()

Determine if this handler will auto-flush.

Returns:boolean

true if auto-flush is enabled

isCallerCalculationRequiredback to summary
public boolean isCallerCalculationRequired()

Indicates whether or not the formatter associated with this handler or a formatter from a child handler requires the caller to be calculated.

Calculating the caller on a log record can be an expensive operation. Some handlers may be required to copy some data from the log record, but may not need the caller information. If the formatter is a ExtFormatter the ExtFormatter#isCallerCalculationRequired() is used to determine if calculation of the caller is required.

Returns:boolean

true if the caller should be calculated, otherwise false if it can be skipped

Annotations
@SuppressWarnings:WeakerAccess
See Also
LogRecord#getSourceClassName(), ExtLogRecord#getSourceFileName(), ExtLogRecord#getSourceLineNumber(), LogRecord#getSourceMethodName()
isCloseChildrenback to summary
public boolean isCloseChildren()

Indicates whether or not children handlers should be closed when this handler is closed.

Returns:boolean

true if the children handlers should be closed when this handler is closed, false if children handlers should not be closed when this handler is closed

isEnabledback to summary
public final boolean isEnabled()

Determine if the handler is enabled.

Returns:boolean

true if the handler is enabled, otherwise false.

publishback to summary
public void publish(final LogRecord record)

Implements abstract java.util.logging.Handler.publish.

Doc from java.util.logging.Handler.publish.

Publish a LogRecord.

The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.

The Handler is responsible for formatting the message, when and if necessary. The formatting should include localization.

Parameters
record:LogRecord

description of the log event. A null record is silently ignored and is not published

publishback to summary
public void publish(final ExtLogRecord record)

Publish an ExtLogRecord.

The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.

The ExtHandler is responsible for formatting the message, when and if necessary. The formatting should include localization.

Parameters
record:ExtLogRecord

the log record to publish

publishToNestedHandlersback to summary
protected void publishToNestedHandlers(final ExtLogRecord record)

Publish a log record to each nested handler.

Parameters
record:ExtLogRecord

the log record to publish

Annotations
@SuppressWarnings:deprecation
removeHandlerback to summary
public void removeHandler(Handler handler) throws SecurityException

Remove a sub-handler from this handler. Some handler types do not utilize sub-handlers.

Parameters
handler:Handler

the handler to remove

Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
reportErrorback to summary
protected void reportError(String msg, Exception ex, int code)

Overrides java.util.logging.Handler.reportError.

Doc from java.util.logging.Handler.reportError.

Protected convenience method to report an error to this Handler's ErrorManager. Note that this method retrieves and uses the ErrorManager without doing a security check. It can therefore be used in environments where the caller may be non-privileged.

Parameters
msg:String

a descriptive string (may be null)

ex:Exception

an exception (may be null)

code:int

an error code defined in ErrorManager

Annotations
@Override
reportErrorback to summary
public static void reportError(Handler handler, String msg, Exception ex, int code)

Report an error using a handler's specific error manager, if any.

Parameters
handler:Handler

the handler

msg:String

the error message

ex:Exception

the exception

code:int

the error code

setAutoFlushback to summary
public void setAutoFlush(final boolean autoFlush) throws SecurityException

Change the autoflush setting for this handler.

Parameters
autoFlush:boolean

true to automatically flush after each write; false otherwise

Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
setCharsetback to summary
public void setCharset(final Charset charset) throws SecurityException

Set the handler's character set. If not set, the handler's character set is initialized to the platform default character set.

Parameters
charset:Charset

the character set (must not be null)

Exceptions
SecurityException:
if a security manager is installed and the caller does not have the "control" LoggingPermission
setCharsetPrivateback to summary
protected void setCharsetPrivate(final Charset charset) throws SecurityException

Set the handler's character set from within this handler. If not set, the handler's character set is initialized to the platform default character set.

Parameters
charset:Charset

the character set (must not be null)

setCloseChildrenback to summary
public void setCloseChildren(final boolean closeChildren)

Sets whether or not children handlers should be closed when this handler is closed.

Parameters
closeChildren:boolean

true if all children handlers should be closed when this handler is closed, false if children handlers will not be closed when this handler is closed

setEnabledback to summary
public final void setEnabled(final boolean enabled) throws SecurityException

Enables or disables the handler based on the value passed in.

Parameters
enabled:boolean

true to enable the handler or false to disable the handler.

Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
setEncodingback to summary
public void setEncoding(final String encoding) throws SecurityException, UnsupportedEncodingException

Overrides java.util.logging.Handler.setEncoding.

Set the handler's character set by name. This is roughly equivalent to calling setCharset(Charset) with the results of Charset#forName(String).

Parameters
encoding:String

the name of the encoding

Annotations
@Override
Exceptions
SecurityException:
if a security manager is installed and the caller does not have the "control" LoggingPermission
UnsupportedEncodingException:
if no character set could be found for the encoding name
setErrorManagerback to summary
public void setErrorManager(final ErrorManager em)

Overrides java.util.logging.Handler.setErrorManager.

Doc from java.util.logging.Handler.setErrorManager.

Define an ErrorManager for this Handler.

The ErrorManager's "error" method will be invoked if any errors occur while using this Handler.

Parameters
em:ErrorManager

the new ErrorManager

Annotations
@Override
setFilterback to summary
public void setFilter(final Filter newFilter) throws SecurityException

Overrides java.util.logging.Handler.setFilter.

Doc from java.util.logging.Handler.setFilter.

Set a Filter to control output on this Handler.

For each call of publish the Handler will call this Filter (if it is non-null) to check if the LogRecord should be published or discarded.

Parameters
newFilter:Filter

a Filter object (may be null)

Annotations
@Override
Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission("control").
setFormatterback to summary
public void setFormatter(final Formatter newFormatter) throws SecurityException

Overrides java.util.logging.Handler.setFormatter.

Doc from java.util.logging.Handler.setFormatter.

Set a Formatter. This Formatter will be used to format LogRecords for this Handler.

Some Handlers may not use Formatters, in which case the Formatter will be remembered, but not used.

Parameters
newFormatter:Formatter

the Formatter to use (may not be null)

Annotations
@Override
Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission("control").
setHandlersback to summary
public Handler[] setHandlers(final Handler[] newHandlers) throws SecurityException

A convenience method to atomically get and replace the sub-handler array.

Parameters
newHandlers:Handler[]

the new sub-handlers

Returns:Handler[]

the old sub-handler array

Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
setLevelback to summary
public void setLevel(final Level newLevel) throws SecurityException

Overrides java.util.logging.Handler.setLevel.

Doc from java.util.logging.Handler.setLevel.

Set the log level specifying which message levels will be logged by this Handler. Message levels lower than this value will be discarded.

The intention is to allow developers to turn on voluminous logging, but to limit the messages that are sent to certain Handlers.

Parameters
newLevel:Level

the new value for the log level

Annotations
@Override
Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission("control").