API java : Handler


java.util.logging
Class Handler

java.lang.Object
  extended by java.util.logging.Handler
Direct Known Subclasses:
MemoryHandler, StreamHandler

public abstract class Handler
extends Object

A Handler object takes log messages from a Logger and exports them. It might for example, write them to a console or write them to a file, or send them to a network logging service, or forward them to an OS log, or whatever.

A Handler can be disabled by doing a setLevel(Level.OFF) and can be re-enabled by doing a setLevel with an appropriate level.

Handler classes typically use LogManager properties to set default values for the Handler's Filter, Formatter, and Level. See the specific documentation for each concrete Handler class.

Since:
1.4

Constructor Summary
protected Handler()
          Default constructor.
 
Method Summary
abstract  void close()
          Close the Handler and free all associated resources.
abstract  void flush()
          Flush any buffered output.
 String getEncoding()
          Return the character encoding for this Handler.
 ErrorManager getErrorManager()
          Retrieves the ErrorManager for this Handler.
 Filter getFilter()
          Get the current Filter for this Handler.
 Formatter getFormatter()
          Return the Formatter for this Handler.
 Level getLevel()
          Get the log level specifying which messages will be logged by this Handler.
 boolean isLoggable(LogRecord record)
          Check if this Handler would actually log a given LogRecord.
abstract  void publish(LogRecord record)
          Publish a LogRecord.
protected  void reportError(String msg, Exception ex, int code)
          Protected convenience method to report an error to this Handler's ErrorManager.
 void setEncoding(String encoding)
          Set the character encoding used by this Handler.
 void setErrorManager(ErrorManager em)
          Define an ErrorManager for this Handler.
 void setFilter(Filter newFilter)
          Set a Filter to control output on this Handler.
 void setFormatter(Formatter newFormatter)
          Set a Formatter.
 void setLevel(Level newLevel)
          Set the log level specifying which message levels will be logged by this Handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Handler

protected Handler()
Default constructor. The resulting Handler has a log level of Level.ALL, no Formatter, and no Filter. A default ErrorManager instance is installed as the ErrorManager.

Method Detail

publish

public abstract void publish(LogRecord record)
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 - description of the log event. A null record is silently ignored and is not published

flush

public abstract void flush()
Flush any buffered output.


close

public abstract void close()
                    throws SecurityException
Close the Handler and free all associated resources.

The close method will perform a flush and then close the Handler. After close has been called this Handler should no longer be used. Method calls may either be silently ignored or may throw runtime exceptions.

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

setFormatter

public void setFormatter(Formatter newFormatter)
                  throws SecurityException
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 - the Formatter to use (may not be null)
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

getFormatter

public Formatter getFormatter()
Return the Formatter for this Handler.

Returns:
the Formatter (may be null).

setEncoding

public void setEncoding(String encoding)
                 throws SecurityException,
                        UnsupportedEncodingException
Set the character encoding used by this Handler.

The encoding should be set before any LogRecords are written to the Handler.

Parameters:
encoding - The name of a supported character encoding. May be null, to indicate the default platform encoding.
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").
UnsupportedEncodingException - if the named encoding is not supported.

getEncoding

public String getEncoding()
Return the character encoding for this Handler.

Returns:
The encoding name. May be null, which indicates the default encoding should be used.

setFilter

public void setFilter(Filter newFilter)
               throws SecurityException
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 - a Filter object (may be null)
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

getFilter

public Filter getFilter()
Get the current Filter for this Handler.

Returns:
a Filter object (may be null)

setErrorManager

public void setErrorManager(ErrorManager em)
Define an ErrorManager for this Handler.

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

Parameters:
em - the new ErrorManager
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

getErrorManager

public ErrorManager getErrorManager()
Retrieves the ErrorManager for this Handler.

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

reportError

protected void reportError(String msg,
                           Exception ex,
                           int code)
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 - a descriptive string (may be null)
ex - an exception (may be null)
code - an error code defined in ErrorManager

setLevel

public void setLevel(Level newLevel)
              throws SecurityException
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 - the new value for the log level
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

getLevel

public Level getLevel()
Get the log level specifying which messages will be logged by this Handler. Message levels lower than this level will be discarded.

Returns:
the level of messages being logged.

isLoggable

public boolean isLoggable(LogRecord record)
Check if this Handler would actually log a given LogRecord.

This method checks if the LogRecord has an appropriate Level and whether it satisfies any Filter. It also may make other Handler specific checks that might prevent a handler from logging the LogRecord. It will return false if the LogRecord is Null.

Parameters:
record - a LogRecord
Returns:
true if the LogRecord would be logged.

Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

7 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-1521
Document créé le 30/08/06 02:46, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-java/util/logging/Handler.html Document affiché 1 fois ce mois de Juin.
St.Gaudry©07.01.02
 
l'infobrol
Nous sommes le Samedi 02 Juin 2012, 00:04, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)