- java.lang.Object
-
- java.util.logging.Handler
-
- java.util.logging.MemoryHandler
-
public class MemoryHandler extends Handler
Handler that buffers requests in a circular buffer in memory.Normally this Handler simply stores incoming LogRecords into its memory buffer and discards earlier records. This buffering is very cheap and avoids formatting costs. On certain trigger conditions, the MemoryHandler will push out its current buffer contents to a target Handler, which will typically publish them to the outside world.
There are three main models for triggering a push of the buffer:
- An incoming LogRecord has a type that is greater than a pre-defined level, the pushLevel.
- An external class calls the push method explicitly.
- A subclass overrides the log method and scans each incoming LogRecord and calls push if a record matches some desired criteria.
Configuration: By default each MemoryHandler is initialized using the following LogManager configuration properties. If properties are not defined (or have invalid values) then the specified default values are used. If no default value is defined then a RuntimeException is thrown.
- java.util.logging.MemoryHandler.level specifies the level for the Handler (defaults to Level.ALL).
- java.util.logging.MemoryHandler.filter specifies the name of a Filter class to use (defaults to no Filter).
- java.util.logging.MemoryHandler.size defines the buffer size (defaults to 1000).
- java.util.logging.MemoryHandler.push defines the pushLevel (defaults to level.SEVERE).
- java.util.logging.MemoryHandler.target specifies the name of the target Handler class. (no default).
- Since:
- 1.4
-
-
Constructor Summary
Constructors Constructor and Description MemoryHandler()
Create a MemoryHandler and configure it based on LogManager configuration properties.MemoryHandler(Handler target, int size, Level pushLevel)
Create a MemoryHandler.
-
Method Summary
Methods Modifier and Type Method and Description void
close()
Close the Handler and free all associated resources.void
flush()
Causes a flush on the target Handler.Level
getPushLevel()
Get the pushLevel.boolean
isLoggable(LogRecord record)
Check if this Handler would actually log a given LogRecord into its internal buffer.void
publish(LogRecord record)
Store a LogRecord in an internal buffer.void
push()
Push any buffered output to the target Handler.void
setPushLevel(Level newLevel)
Set the pushLevel.-
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
-
-
-
-
Constructor Detail
-
MemoryHandler
public MemoryHandler()
Create a MemoryHandler and configure it based on LogManager configuration properties.
-
MemoryHandler
public MemoryHandler(Handler target, int size, Level pushLevel)
Create a MemoryHandler.The MemoryHandler is configured based on LogManager properties (or their default values) except that the given pushLevel argument and buffer size argument are used.
- Parameters:
target
- the Handler to which to publish output.size
- the number of log records to buffer (must be greater than zero)pushLevel
- message level to push on- Throws:
IllegalArgumentException
- if size is <= 0
-
-
Method Detail
-
publish
public void publish(LogRecord record)
Store a LogRecord in an internal buffer.If there is a Filter, its isLoggable method is called to check if the given log record is loggable. If not we return. Otherwise the given record is copied into an internal circular buffer. Then the record's level property is compared with the pushLevel. If the given level is greater than or equal to the pushLevel then push is called to write all buffered records to the target output Handler.
-
push
public void push()
Push any buffered output to the target Handler.The buffer is then cleared.
-
flush
public void flush()
Causes a flush on the target Handler.Note that the current contents of the MemoryHandler buffer are not written out. That requires a "push".
-
close
public void close() throws SecurityException
Close the Handler and free all associated resources. This will also close the target Handler.- Specified by:
close
in classHandler
- Throws:
SecurityException
- if a security manager exists and if the caller does not have LoggingPermission("control").
-
setPushLevel
public void setPushLevel(Level newLevel) throws SecurityException
Set the pushLevel. After a LogRecord is copied into our internal buffer, if its level is greater than or equal to the pushLevel, then push will be called.- Parameters:
newLevel
- the new value of the pushLevel- Throws:
SecurityException
- if a security manager exists and if the caller does not have LoggingPermission("control").
-
getPushLevel
public Level getPushLevel()
Get the pushLevel.- Returns:
- the value of the pushLevel
-
isLoggable
public boolean isLoggable(LogRecord record)
Check if this Handler would actually log a given LogRecord into its internal buffer.This method checks if the LogRecord has an appropriate level and whether it satisfies any Filter. However it does not check whether the LogRecord would result in a "push" of the buffer contents. It will return false if the LogRecord is null.
- Overrides:
isLoggable
in classHandler
- Parameters:
record
- a LogRecord- Returns:
- true if the LogRecord would be logged.
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/util/logging/MemoryHandler.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.