user1401472
user1401472

Reputation: 2301

Java Logging messages following a custom regex pattern

I have various modules logging information using various levels. I would like to implement a controller that would log the information only if the message follows certain pattern.

For example - Module A logger.info("log this message - A");

Module B logger.info("log this message - B");

Module C logger.info("don't log this message - C");

I cannot make changes to A and B to change their level as the number of modules talking to each other is huge.

I would like to have a logging.properties that would log all messages not having "don't log this messages*" pattern.

Can you assist me?

Upvotes: 0

Views: 711

Answers (1)

jmehrens
jmehrens

Reputation: 11045

There is no regex filter included with the logging package in the JDK. However, you can create your own Filter to throw out messages that match your regex then install it on the handler you want to filter. If you want to install a custom filter on a specific logger then you have to use the config property to programmatically install the filter.

Upvotes: 1

Related Questions