How to do a JUnit assert on a message in a logger

I have some code-under-test that calls on a Java logger to report its status. In the JUnit test code, I would like to verify that the correct log entry was made in this logger. Something along the following lines: methodUnderTest(bool x){ if(x) logger.info(“x happened”) } @Test tester(){ // perhaps setup a logger first. methodUnderTest(true); assertXXXXXX(loggedLevel(),Level.INFO); … Read more

Should a “static final Logger” be declared in UPPER-CASE?

In Java, static final variables are constants and the convention is that they should be in upper-case. However, I have seen that most people declare loggers in lower-case which comes up as a violation in PMD. e.g: private static final Logger logger = Logger.getLogger(MyClass.class); Just search googleor SO for “static final logger” and you will … Read more

How to Customize the time format for Python logging?

I am new to Python’s logging package and plan to use it for my project. I would like to customize the time format to my taste. Here is a short code I copied from a tutorial: import logging # create logger logger = logging.getLogger(“logging_tryout2”) logger.setLevel(logging.DEBUG) # create console handler and set level to debug ch … Read more