Package org.jboss.logmanager
Class ExtHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- org.jboss.logmanager.ExtHandler
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable,FlushableCloseable,Protectable
- Direct Known Subclasses:
AsyncHandler,NullHandler,QueueHandler,SyslogHandler,WriterHandler
public abstract class ExtHandler extends java.util.logging.Handler implements FlushableCloseable, Protectable
An extended logger handler. Use this class as a base class for log handlers which requireExtLogRecordinstances.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanautoFlushprivate static java.security.PermissionCONTROL_PERMISSIONprivate static java.util.logging.ErrorManagerDEFAULT_ERROR_MANAGERprivate booleanenabledprivate java.lang.ThreadLocal<java.lang.Boolean>grantedprotected java.util.logging.Handler[]handlersThe sub-handlers for this handler.protected static AtomicArray<ExtHandler,java.util.logging.Handler>handlersUpdaterThe atomic updater for thehandlersfield.private java.lang.ObjectprotectKeyprivate static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ExtHandler,java.lang.Object>protectKeyUpdater
-
Constructor Summary
Constructors Modifier Constructor Description protectedExtHandler()Construct a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static java.lang.SecurityExceptionaccessDenied()voidaddHandler(java.util.logging.Handler handler)Add a sub-handler to this handler.protected static voidcheckAccess()Deprecated.protected static voidcheckAccess(ExtHandler handler)Check access.java.util.logging.Handler[]clearHandlers()A convenience method to atomically get and clear all sub-handlers.voidclose()Close all child handlers.voiddisableAccess()Disable previous access to the object for modifications on the current thread.protected voiddoPublish(ExtLogRecord record)Do the actual work of publication; the record will have been filtered already.voidenableAccess(java.lang.Object protectKey)Enable access to the object for modifications on the current thread.voidflush()Flush all child handlers.java.util.logging.Handler[]getHandlers()Get a copy of the sub-handlers array.booleanisAutoFlush()Determine if this handler will auto-flush.booleanisEnabled()Determine if the handler is enabled.voidprotect(java.lang.Object protectionKey)Protect this object from modifications.voidpublish(java.util.logging.LogRecord record)voidpublish(ExtLogRecord record)Publish anExtLogRecord.voidremoveHandler(java.util.logging.Handler handler)Remove a sub-handler from this handler.voidsetAutoFlush(boolean autoFlush)Change the autoflush setting for this handler.voidsetEnabled(boolean enabled)Enables or disables the handler based on the value passed in.voidsetEncoding(java.lang.String encoding)voidsetErrorManager(java.util.logging.ErrorManager em)voidsetFilter(java.util.logging.Filter newFilter)voidsetFormatter(java.util.logging.Formatter newFormatter)java.util.logging.Handler[]setHandlers(java.util.logging.Handler[] newHandlers)A convenience method to atomically get and replace the sub-handler array.voidsetLevel(java.util.logging.Level newLevel)voidunprotect(java.lang.Object protectionKey)Allows the object to be modified if theprotectionKeymatches the key used toprotectthe object.
-
-
-
Field Detail
-
CONTROL_PERMISSION
private static final java.security.Permission CONTROL_PERMISSION
-
autoFlush
private volatile boolean autoFlush
-
enabled
private volatile boolean enabled
-
DEFAULT_ERROR_MANAGER
private static final java.util.logging.ErrorManager DEFAULT_ERROR_MANAGER
-
protectKey
private volatile java.lang.Object protectKey
-
granted
private final java.lang.ThreadLocal<java.lang.Boolean> granted
-
protectKeyUpdater
private static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ExtHandler,java.lang.Object> protectKeyUpdater
-
handlers
protected volatile java.util.logging.Handler[] handlers
The sub-handlers for this handler. May only be updated using thehandlersUpdateratomic updater. The array instance should not be modified (treat as immutable).
-
handlersUpdater
protected static final AtomicArray<ExtHandler,java.util.logging.Handler> handlersUpdater
The atomic updater for thehandlersfield.
-
-
Method Detail
-
publish
public void publish(java.util.logging.LogRecord record)
- Specified by:
publishin classjava.util.logging.Handler
-
publish
public void publish(ExtLogRecord record)
Publish anExtLogRecord. The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here. TheExtHandleris responsible for formatting the message, when and if necessary. The formatting should include localization.- Parameters:
record- the log record to publish
-
doPublish
protected void doPublish(ExtLogRecord record)
Do the actual work of publication; the record will have been filtered already. The default implementation does nothing except to flush if theautoFlushproperty is set totrue; if this behavior is to be preserved in a subclass then this method should be called after the record is physically written.- Parameters:
record- the log record to publish
-
addHandler
public void addHandler(java.util.logging.Handler handler) throws java.lang.SecurityExceptionAdd a sub-handler to this handler. Some handler types do not utilize sub-handlers.- Parameters:
handler- the handler to add- Throws:
java.lang.SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)or the handler isprotected.
-
removeHandler
public void removeHandler(java.util.logging.Handler handler) throws java.lang.SecurityExceptionRemove a sub-handler from this handler. Some handler types do not utilize sub-handlers.- Parameters:
handler- the handler to remove- Throws:
java.lang.SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)or the handler isprotected.
-
getHandlers
public java.util.logging.Handler[] getHandlers()
Get a copy of the sub-handlers array. Since the returned value is a copy, it may be freely modified.- Returns:
- a copy of the sub-handlers array
-
clearHandlers
public java.util.logging.Handler[] clearHandlers() throws java.lang.SecurityExceptionA convenience method to atomically get and clear all sub-handlers.- Returns:
- the old sub-handler array
- Throws:
java.lang.SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)or the handler isprotected.
-
setHandlers
public java.util.logging.Handler[] setHandlers(java.util.logging.Handler[] newHandlers) throws java.lang.SecurityExceptionA convenience method to atomically get and replace the sub-handler array.- Parameters:
newHandlers- the new sub-handlers- Returns:
- the old sub-handler array
- Throws:
java.lang.SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)or the handler isprotected.
-
isAutoFlush
public boolean isAutoFlush()
Determine if this handler will auto-flush.- Returns:
trueif auto-flush is enabled
-
setAutoFlush
public void setAutoFlush(boolean autoFlush) throws java.lang.SecurityExceptionChange the autoflush setting for this handler.- Parameters:
autoFlush-trueto automatically flush after each write; false otherwise- Throws:
java.lang.SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)or the handler isprotected.
-
setEnabled
public final void setEnabled(boolean enabled) throws java.lang.SecurityExceptionEnables or disables the handler based on the value passed in.- Parameters:
enabled-trueto enable the handler orfalseto disable the handler.- Throws:
java.lang.SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)or the handler isprotected.
-
isEnabled
public final boolean isEnabled()
Determine if the handler is enabled.- Returns:
trueif the handler is enabled, otherwisefalse.
-
protect
public final void protect(java.lang.Object protectionKey) throws java.lang.SecurityExceptionDescription copied from interface:ProtectableProtect this object from modifications.- Specified by:
protectin interfaceProtectable- Parameters:
protectionKey- the key used to protect the object.- Throws:
java.lang.SecurityException- if the object is already protected.
-
unprotect
public final void unprotect(java.lang.Object protectionKey) throws java.lang.SecurityExceptionDescription copied from interface:ProtectableAllows the object to be modified if theprotectionKeymatches the key used toprotectthe object.- Specified by:
unprotectin interfaceProtectable- Parameters:
protectionKey- the key used to protect the object.- Throws:
java.lang.SecurityException- if the object is protected and the key doesn't match.
-
enableAccess
public final void enableAccess(java.lang.Object protectKey)
Description copied from interface:ProtectableEnable access to the object for modifications on the current thread.- Specified by:
enableAccessin interfaceProtectable- Parameters:
protectKey- the key used toprotectmodifications.
-
disableAccess
public final void disableAccess()
Description copied from interface:ProtectableDisable previous access to the object for modifications on the current thread.- Specified by:
disableAccessin interfaceProtectable
-
accessDenied
private static java.lang.SecurityException accessDenied()
-
checkAccess
@Deprecated protected static void checkAccess() throws java.lang.SecurityExceptionDeprecated.Check access.- Throws:
java.lang.SecurityException- if a security manager is installed and the caller does not have the"control" LoggingPermission
-
checkAccess
protected static void checkAccess(ExtHandler handler) throws java.lang.SecurityException
Check access.- Parameters:
handler- the handler to check access on.- Throws:
java.lang.SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)or the handler isprotected.
-
flush
public void flush()
Flush all child handlers.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.util.logging.Handler
-
close
public void close() throws java.lang.SecurityExceptionClose all child handlers.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.util.logging.Handler- Throws:
java.lang.SecurityException
-
setFormatter
public void setFormatter(java.util.logging.Formatter newFormatter) throws java.lang.SecurityException- Overrides:
setFormatterin classjava.util.logging.Handler- Throws:
java.lang.SecurityException
-
setFilter
public void setFilter(java.util.logging.Filter newFilter) throws java.lang.SecurityException- Overrides:
setFilterin classjava.util.logging.Handler- Throws:
java.lang.SecurityException
-
setEncoding
public void setEncoding(java.lang.String encoding) throws java.lang.SecurityException, java.io.UnsupportedEncodingException- Overrides:
setEncodingin classjava.util.logging.Handler- Throws:
java.lang.SecurityExceptionjava.io.UnsupportedEncodingException
-
setErrorManager
public void setErrorManager(java.util.logging.ErrorManager em)
- Overrides:
setErrorManagerin classjava.util.logging.Handler
-
setLevel
public void setLevel(java.util.logging.Level newLevel) throws java.lang.SecurityException- Overrides:
setLevelin classjava.util.logging.Handler- Throws:
java.lang.SecurityException
-
-