[logback-user] Delete log file

pwillems66 at zonnet.nl pwillems66 at zonnet.nl
Fri Nov 19 11:34:03 CET 2010


> 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");
>       ...
>    }
> }

Let me try to explain what I am after:
First:  For me a "test" is a process. Executing 1,2,3,n-1,n method 
which could log information.
  But to keep it simple, executing method a() in class MyTest is a test 
(Create/append/truncate file myTest_a.log)
  An other test, executing method b() in class MyTest is a test 
(Create/append/truncate file myTest_b.log)

Second:
  Lets use your class and methods for a simple application:

Public Class MyApp {
   public static void main(String args[]) {
    MyTest myTest = new MyTest();
    myTest.a();
    myTest.b();

    if (errors in method a) {
      delete file (myTest_a.log)
      myTest.a();
    }
  }
}

If you run the code in file myTest_a.log there are 2 lines mentioned:
  a says hello
  a says hello
because the file is in use.
In case there are errors the (call myTest.a() again) the file 
myTest_a.log must be deleted and the next call must recreate the file.

-Patrick




More information about the Logback-user mailing list