mardi 7 juillet 2015

How to write a test case to verify log4j logs are generated in proper format

I want to write a testng test case to verify that the logs (log4j) generated are following exactly the given conversion pattern from the log4j.properties file. As an example if I have conversion pattern : [%d] %-5p [%t]: %m%n a sample log would looks like [2015-07-07 16:42:09,937] DEBUG [main]: Message 1 I want to make sure that the log follows the exact pattern.

So for now what I'm doing is first read all the logs in to a String array and loop that array to find whether the expected log without the date i.e. DEBUG [main]: Message 1 contains in the recorded.

Is this way of testing log records is correct ? If you have any idea about a good way to test logs rather than this please point out.

Aucun commentaire:

Enregistrer un commentaire