Re: [logback-user] Delete log file

Hi Patrick,
Sifting appender could probably help. Here is a sample config file:
public class MyTest { Logger logger = LoggerFactory.getLogger(Foo.class); @Before public void setUp() { MDC.put("testname", "myTest"); } @Test a() { logger.info("a says hello"); ... } @Test b() { logger.info("b says hello"); ... } } public class MyOtherTest { Logger logger = LoggerFactory.getLogger(Foo.class); @Before public void setUp() { MDC.put("testname", "MyOtherTest"); } @Test x() { logger.info("a says hello"); ... } }
Let us know if it works... -- Ceki
Hi Ceki, It works except for the delete. When I call the test (class) MyTest (multiple times) logback don't delete the log file but append it. The first time when the Logger initialize the file is truncated but not for the second and more times until the Logger must initialize again. -Patrick

On 18.11.2010 17:35, pwillems66@zonnet.nl wrote:
Hi Ceki,
It works except for the delete. When I call the test (class) MyTest (multiple times) logback don't delete the log file but append it.
The first time when the Logger initialize the file is truncated but not for the second and more times until the Logger must initialize again.
It is not clear to me what you mean by "test". Is a test the class containing the various test methods or does "test" refer to each test method? For example, Given the MyTest class mention in my previous post, is MyTest the "test" or are the methods a() and b() "tests"? If the latter, you could try, public class MyTest { Logger logger = LoggerFactory.getLogger(MyTest.class); @Test a() { MDC.put("testname", "myTest_a"); logger.info("a says hello"); ... } @Test b() { MDC.put("testname", "myTest_b"); logger.info("b says hello"); ... } }
-Patrick
participants (2)
-
Ceki Gulcu
-
pwillems66@zonnet.nl