IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Logging Java Discussion :

[log4j]choix de l'affichage


Sujet :

Logging Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de menuge
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    727
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2004
    Messages : 727
    Par défaut [log4j]choix de l'affichage
    Salut à tous,

    Je suis en train de débuter avec log4j...
    J'ai bien compris son utilisation (je crois!!!) mais je ne comprends pas comment est-ce que je dois faire pour choisir ce que je souhaite afficher.
    Par exemple, si je souhaite afficher les infos et pas la partie debug...

    Quelqu'un peut m'aider?

    Merci d'avance.

  2. #2
    Membre émérite Avatar de g_rare
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    608
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 608
    Par défaut
    http://www.vipan.com/htdocs/log4jhelp.html
    "Useful Layouts"
    # PatternLayout lets you specify the output format according to conversion patterns similar to the C language printf function. For example, PatternLayout with the conversion pattern %r [%t] %-5p %c - %m%n will output something like:

    176 [main] INFO org.foo.Bar - Located nearest gas station.

    * The first field is the number of milliseconds elapsed since the start of the program.
    * The second field is the thread making the log request.
    * The third field is the priority of the log statement.
    * The fourth field is the name of the category associated with the log request.
    * The text after the '-' is the message of the statement.

    # You can insert any literal text within the conversion pattern.
    # Conversion characters are:

    * %m: Outputs your message.
    * %p: Outputs the priority of the logging event.
    * %r: Outputs the number of milliseconds elapsed since the start of the application until the creation of the logging event.
    * %c: Outputs the category of the logging event. Example: For the category name "a.b.c", the pattern %c{2} will output "b.c". {2} means "output last two components of the dot-separated category name". If no {n} is there, full Category name is output by default.
    * %t: Outputs the name of the thread that generated the logging event.
    * %x: Outputs the nested diagnostic context (NDC) associated with the thread that generated the logging event. Useful when multiple clients are handled by separate threads such as in Java servlets.
    * %n: Outputs the platform-dependent newline character(s). Preferable to specifying "\n" or "\r\n" etc.
    * %%: Outputs a single percent sign.
    * WARNING: The patterns below will slow down the execution of your program somewhat. Avoid unless execution speed is not an issue.
    * %d: Outputs the date of the logging event. The date conversion specifier may be followed by a date format specifier enclosed between braces. Example: %d{HH:mm:ss,SSS} or %d{dd MMM yyyy HH:mm:ss,SSS}. If no date format specifier is given then ISO8601 format is assumed. The date format specifier admits the same syntax as the time pattern string of Java's SimpleDateFormat which is slow. For faster performance, use %d{ISO8601}, %d{ABSOLUTE}, %d{RELATIVE} (millisecs since program start, fastest) or %d{DATE} which use log4j's ISO8601DateFormat, AbsoluteTimeDateFormat, RelativeTimeDateFormat and DateTimeDateFormat date formatters respectively.
    * %l: Outputs source code location information. Shortcut for %C.%M(%F:%L).
    * %C: Outputs the fully-qualified class name of the caller issuing the logging request. Example: For the class name "org.apache.xyz.SomeClass", the pattern %C{1} will output "SomeClass". {1} means "output last one component of the fully-qualified class name". If no {n} is there, full class name is output by default.
    * %M: Outputs the method name where the logging request was issued.
    * %F: Outputs the file name where the logging request was issued.
    * %L: Outputs the line number from where the logging request was issued.


  3. #3
    Membre éclairé Avatar de menuge
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    727
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2004
    Messages : 727
    Par défaut
    OK, ça c'est comment définir le format de mon affichage.

    Mais je souhaite avoir le choix au lancement de mon appli de dire "ne pas afficher les log DEBUG"....

  4. #4
    in
    in est déconnecté
    Membre Expert Avatar de in
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    1 612
    Détails du profil
    Informations personnelles :
    Localisation : France, Finistère (Bretagne)

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 612
    Par défaut
    c'est pas avec les Level par hasard ?

    extrait javadoc de la classe Level ->
    Defines the minimum set of levels recognized by the system, that is OFF, FATAL, ERROR, WARN, INFODEBUG and ALL.

  5. #5
    Membre éprouvé
    Avatar de mavina
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2004
    Messages
    1 812
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Chine

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2004
    Messages : 1 812
    Par défaut
    Sinon, cf la classe MyLogger que j'ai mise dans la partie code sources libres, qui permet justement de gérer un logger facilement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    logger.setLevel(Level.INFO)
    http://logging.apache.org/log4j/docs/api/index.html
    Fred

  6. #6
    Membre éclairé Avatar de menuge
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    727
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2004
    Messages : 727
    Par défaut
    OK, merci beaucoup.

    Je vais tester ça!! mais ça me semble tout bon!!

Discussions similaires

  1. [AC-2003] Créer un choix pour "Mode Affichage"
    Par willou-78 dans le forum IHM
    Réponses: 3
    Dernier message: 12/01/2012, 12h06
  2. Choix de l'affichage pour projet : tout sauf la console !
    Par bellinzono dans le forum Débuter
    Réponses: 3
    Dernier message: 22/04/2008, 20h08
  3. Choix de valeur, affichage ou non
    Par fatenatwork dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 22/11/2007, 14h08
  4. awk : plusieurs choix possibles à l'affichage
    Par rico3434 dans le forum Shell et commandes GNU
    Réponses: 2
    Dernier message: 26/09/2007, 11h55
  5. Choix de composant affichage messages réseaux
    Par sozie9372 dans le forum Graphisme
    Réponses: 2
    Dernier message: 19/05/2006, 15h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo