G
Guest
Gast
Hallo,
kennst sich jemand mit log4j aus, oder kennt jemand ein gutes Tutorial?
kennst sich jemand mit log4j aus, oder kennt jemand ein gutes Tutorial?
package Start;
import org.apache.log4j.Logger;
import Test.Test;
public class Start {
public static void main(String[] args)
{
//LogTests
Test t1 = new Test();
t1.testAusgabe("t1", 1);
Test t2 = new Test(1,2);
t2.testAusgabe("t2", 2);
Test t3 = new Test(1,2,3);
t3.testAusgabe("t3",3);
}
}
package Test;
public class Test
{
private int a,b,c;
public Test()
{
this.a = 0;
this.b = 0;
this.c = 0;
}
public Test(int a, int b)
{
this.a = a;
this.b = b;
this.c = 0;
}
public Test(int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
}
public String testAusgabe(String ausgabe, int anzahl)
{
for(int i = 0; i<anzahl; i++)
System.out.println(ausgabe);
return ausgabe + Integer.toString(anzahl);
}
}
package Start;
import org.apache.log4j.Logger;
import Test.Test;
public class Start {
public static Logger logger = Logger.getLogger(Test.class.getName());
public static void main(String[] args)
{
logger.info("Programm gestartet");
Test t1 = new Test();
t1.testAusgabe("t1", 1);
logger.info(t1);
Test t2 = new Test(1,2);
t2.testAusgabe("t2", 2);
Test t3 = new Test(1,2,3);
t3.testAusgabe("t3",3);
logger.info("Programm beendet");
}
}
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.File=logFile
log4j.appender.A2.Append=false
Aber wie könnte ich jetzt mir sämtliche Übergabeparamter und Returnvalues loggen lassen.
Hä?Ohne in jede einzelne Methode rein zu gehen?
public Test(int a, int b, int c)
{
LogWriter.logger.info(a + " " + b + " " + c);
this.a = a;
this.b = b;
this.c = c;
}
Anonymous hat gesagt.:Ok,
z.B. habe ich das so gemacht. Aber da müsste ich ja in meinen Programm in jeder Methode das einbauen.
Und das will ich echt ungerne, deshalb wollte ich wissen ob es da eine andere Möglichkeit gibt das zu lösen?
if (LOG.isInfoEnabled()) {
LOG.info("TestMethod -> Parameter a: " + a);
}
if (LOG.isInfoEnabled()){
LOG.info("${enclosing_method} -> ${cursor}");
}
if (LOG.isInfoEnabled()){
LogWriter.logger.info("${enclosing_method} \n" +
" ${enclosing_method_arguments}" ${enclosing_method_arguments});
}
public String testAusgabe(String ausgabe, int anzahl)
{
if (LOG.isInfoEnabled()){
LogWriter.logger.info("testAusgabe \n" +
"ausgabe, anzahl" + ausgabe, anzahl); ////////FEHLER
}