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 :

Configuration de Log4J


Sujet :

Logging Java

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    728
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 728
    Points : 250
    Points
    250
    Par défaut Configuration de Log4J
    Bonjour, je travaille sous eclipse Luna

    J'ai créé un enterprise application project avec un module web dont voici un screenshoot

    Nom : Capture d’écran 2014-10-08 à 12.47.30.png
Affichages : 1294
Taille : 71,3 Ko

    J'ai créé Le dossier resources est ajouté au classpath

    Nom : Capture d’écran 2014-10-08 à 12.48.30.png
Affichages : 1123
Taille : 107,0 Ko


    Voici mon fichier log4j.properties où le mot stdout est souligné en rouge (est-ce un bug ?) avec l'explication suivante : The word 'stdout' is not correctly spelled

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    # Root logger option
    log4j.rootLogger=DEBUG, file, stdout
     
    # Direct log messages to a log file
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=Log/log.log
    log4j.appender.file.MaxFileSize=1MB
    log4j.appender.file.MaxBackupIndex=1
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
     
    # Direct log messages to stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.Target=System.out
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
    Voici un extrait de ma classe où je mets des logs

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    public class TestThread extends Thread {
    	boolean interrupted = false;
    
    	Context ctx = null;
    
    	LibrarySessionBeanRemote libraryBean = null;
    	InstanciateBeanInterface instanciateBeanInterface = null;
    
    	//String viewClassName = LibrarySessionBeanRemote.class.getName();
    	String viewClassName = InstanciateBeanInterface.class.getName();
    
    	Set<LibrarySessionBeanRemote> slsbSet = new HashSet<LibrarySessionBeanRemote>();
    
    
    	static Logger log = LogManager.getLogger(TestThread.class.getName());
    
    
    
    	public String postURL(URL a_Url, String a_sParamsToPost)
    	{
    		StringBuilder o_oSb = new StringBuilder();
    
    		//recup du saut de ligne
    		String o_sLineSep = null;
    		try
    		{
    			o_sLineSep = System.getProperty("line.separator");
    		}
    		catch (Exception e)
    		{
    			o_sLineSep = "\n";
    		}
    
    		try
    		{
    			HttpURLConnection o_oUrlConn = (HttpURLConnection) a_Url.openConnection();
    			o_oUrlConn.setRequestMethod("POST");
    			o_oUrlConn.setAllowUserInteraction(false);
    			//envoyer des params
    			o_oUrlConn.setDoOutput(true);
    
    			//poster les params
    			PrintWriter o_oParamWriter = new PrintWriter(o_oUrlConn.getOutputStream());
    
    			o_oParamWriter.print(a_sParamsToPost);
    			//fermer le post avant de lire le resultat ... logique
    			o_oParamWriter.flush();
    			o_oParamWriter.close();
    
    			//Lire la reponse
    			InputStream  o_oResponse = o_oUrlConn.getInputStream();
    			BufferedReader o_oBufReader = new BufferedReader(new InputStreamReader(o_oResponse));
    			String sLine;
    
    			while ((sLine = o_oBufReader.readLine()) != null)
    			{
    				o_oSb.append(sLine);
    				o_oSb.append(o_sLineSep);
    			}
    			//deconnection
    			o_oUrlConn.disconnect();
    		}
    		catch(ConnectException ctx)
    		{
    			log.fatal("Connection lost : server may be down");
    			ctx.printStackTrace();
    		}
    		catch (Exception e)
    		{
    			log.error("postURL : "+e.getMessage());
    			e.printStackTrace();
    		}
    		log.debug("retour url="+o_oSb.toString());
    		return o_oSb.toString();
    	}
    Or je n'ai aucune sortie ni dans ma console ni dans mon fichier Log/log.log (qui est bien créé mais qui est vide).

    Il devrait y avoir la ligne en rouge. J'ai vérifié en mode debug que mon programme passe bien dedans

    Auriez vous une idée ? Merci d'avance pour vos réponses.
    Images attachées Images attachées   

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Février 2008
    Messages
    114
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 114
    Points : 83
    Points
    83
    Par défaut
    Voici la réponse:

    https://twitter.com/mschayna/status/248721740010774528

    Avais-tu résolu ton problème?

    Emmanuel ARON

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Février 2008
    Messages
    114
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 114
    Points : 83
    Points
    83
    Par défaut
    En fait , je cherchais une réponse pour le meme probleme que le tiens , et personnellement en rajoutant un system.out.println en dessous de mon logger j'ai ce message assez explicite , ainsi que le system out qui s'affiche dans la console alors qu'il ne s'affichait pas auparavant (avec la "faute d'orthographe") ...on y est ! C'est l'appender apparemment!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    mars 15, 2016 12:51:09 PM org.apache.catalina.startup.Embedded start
    INFOS: Starting tomcat server
    mars 15, 2016 12:51:10 PM org.apache.catalina.core.StandardEngine start
    INFOS: Starting Servlet Engine: Apache Tomcat/6.0.29
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    mars 15, 2016 12:51:10 PM org.apache.coyote.http11.Http11Protocol init
    INFOS: Initializing Coyote HTTP/1.1 on http-8080
    mars 15, 2016 12:51:10 PM org.apache.coyote.http11.Http11Protocol start
    INFOS: Starting Coyote HTTP/1.1 on http-8080
    log4j:ERROR Could not find value for key log4j.appender.stout
    log4j:ERROR Could not instantiate appender named "stout".
    log4j:WARN No appenders could be found for logger (freemarker.cache).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
    login failed

Discussions similaires

  1. [Commons-logging]Pb configuration pour log4j
    Par royto dans le forum Logging
    Réponses: 5
    Dernier message: 19/12/2007, 11h05
  2. Configuration de Log4j dans une Webapp
    Par fabszn dans le forum Logging
    Réponses: 1
    Dernier message: 07/11/2007, 09h56
  3. [Integration] configuration de log4j
    Par lanfeustdetroll dans le forum Spring
    Réponses: 3
    Dernier message: 07/10/2007, 20h19
  4. [LOG4J] configuration de log4j sous tomcat
    Par java_fun dans le forum Logging
    Réponses: 4
    Dernier message: 26/09/2005, 11h30
  5. [ log4j ] configuration de log4j
    Par felix79 dans le forum Logging
    Réponses: 5
    Dernier message: 18/10/2004, 14h50

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