
Hi, The prudent propertie doesn't work. Any other idea? It looks like the log file is in use. Is their a way to 'unlock' that use by code? This is what I must realize: For every test I need to create a log file. When the same test start again the previous file must be deleted (or renamed and delete thereafter) and a new one created. Also (test is not running) it must be possible to delete the log file. -Patrick pwillems66 at zonnet.nl wrote:
Maybe someone else have a (different) solution?
FileAppender.setPrudent() looks promising for this purpose. However, using the example from PrudentTimeBasedRolling.xml, when I rm the file it is not recreated on the next log statement. Also, if it did work, it doesn't support your file appender, but maybe it is ok to change that. http://logback.qos.ch/codes.html#tbr_fnp_prudent_unsupported says,
prudent mode is not allowed in conjuction with a FixedWindowRollingPolicy.
-Gordon

Hi Patrick, Sifting appender could probably help. Here is a sample config file: <configuration> <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender"> <discriminator> <key>testname</key> <defaultValue>unknown</defaultValue> </discriminator> <sift> <appender name="FILE-${testname}" class="ch.qos.logback.core.FileAppender"> <file>${testname}.log</file> <append>false</append> <encoder> <pattern>%d %level %mdc %logger{35} - %msg%n</pattern> </encoder> </appender> </sift> </appender> <root level="DEBUG"> <appender-ref ref="SIFT" /> </root> </configuration> At the beginning each test, you need to set the test's anme in the MDC. For eaxmple, 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 On 18.11.2010 17:01, pwillems66@zonnet.nl wrote:
Hi,
The prudent propertie doesn't work. Any other idea? It looks like the log file is in use. Is their a way to 'unlock' that use by code?
This is what I must realize: For every test I need to create a log file. When the same test start again the previous file must be deleted (or renamed and delete thereafter) and a new one created. Also (test is not running) it must be possible to delete the log file.
-Patrick
participants (2)
-
Ceki Gulcu
-
pwillems66@zonnet.nl