Is there a log4j appender connected to TestNG?

I use log4j and want the log messages that usually end in my logging tool to appear in the test report created by TestNG during my unit test.

I think this means a log4j Appender output to TestNG Listener and a proper log4j configuration in the src/test/resources directory of my Maven project. Is that correct?

It seems quite easy to write, but is there anything I can import through Maven?

I have the same problem, and eventually I wrote an appender. It’s actually very simple: < p>

Copy the following classes:

public class TestNGReportAppender extends AppenderSkeleton {

@Override
protected void append (final LoggingEvent event) {
Reporter.log(eventToString(event));
}

private String eventToString(final LoggingEvent event) {
final StringBuilder result = new StringBuilder(layout.format(event));

if(layout.ignoresThrowable()) {
final String[] s = event.getThrowableStrRep();
if ( s != null) {
for (final String value: s) {
result.append(value).append(Layout.LINE_SEP);
}
}
}
return result.toString();
}

@Override
public void close() {

}

@Override
public boolean requiresLayout() {
return true;
}
}

and configure it as a console appe nder. For example. Like this:

log4j.appender.testNG=some.package.TestNGReportAppender
log4j.appender.testNG.layout=org.apache.log4j. EnhancedPatternLayout
log4j.appender.testNG.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L-%m%

Me Use log4j and hope that the log messages that usually end in my logging tool appear in the test report created by TestNG during my unit test.

I think this means a log4j Appender output To the TestNG Listener and an appropriate log4j configuration in the src/test/resources directory of my Maven project. Is that correct?

It seems quite easy to write, but is there anything I can import through Maven?

I had the same problem and eventually wrote an appender myself. It is actually very simple:

Copy the following class :

public class TestNGReportAppender extends AppenderSkeleton {

@Override
protected void append(final LoggingEvent event) {
Reporter. log(eventToString(event));
}

private String eventToString(final LoggingEvent event) {
final StringBuilder result = new StringBuilder(layout.format(event));< br />
if(layout.ignoresThrowable()) {
final String[] s = event.getThrowableStrRep();
if (s != null) {
for ( final String value: s) {
result.append(value).append(Layout.LINE_SEP);
}
}
}
return result.toString() ;
}

@Override
public void close() {

}

@Override
public boolean requiresLayout() {
return true;
}
}

and configure it as a console appender. For example. Like this:

log4j.appender.testNG=som e.package.TestNGReportAppender
log4j.appender.testNG.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.testNG.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1} :%L-%m%

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2257 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.