aspose file tools*
The moose likes Other Open Source Projects and the fly likes Filter content before printing to log file using log4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Filter content before printing to log file using log4j" Watch "Filter content before printing to log file using log4j" New topic
Author

Filter content before printing to log file using log4j

Hemant Khurana
Greenhorn

Joined: Jan 11, 2007
Posts: 27
Hi All
I have application which uses log4j and log4j.xml for logging purpose. I need to filter the content in loggers before printing to the log file.

For example I want that no String which is pattern A*BC*123 should get printed in log file through log4j.

So is there a way to add filters for specific content in log4j.

Thanks
Hemant
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't know of a built-in regex filter, but there's a string matching filter that might be a good starting point.

I've never needed to filter on anything other than log levels, what's your use-case?
Hemant Khurana
Greenhorn

Joined: Jan 11, 2007
Posts: 27
Well the application has some confidential data which it is printing in loggers right now. Though the confidential data is getting printed only in debug mode right now but the my requirement is to not to print that piece of data anytime in any logging mode.

Unfortunately I can not go and remove those loggers from the Java classes as there are too many of them and some are even inside jar for which I don't have the source code. Can you please guide me on how to use the String filters you are talking about. I'll see if can use that to satisfy my requirement

Thanks
Hemant
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filter content before printing to log file using log4j