Jump to content

[SOLVED] [1.9] Filtering console output not working


sblectric

Recommended Posts

Here's my code atm, showing Java and Apache logger filters, called from the preInit phase:

// Java
LogManager m = LogManager.getLogManager();
Enumeration<String> names = m.getLoggerNames();
while(names.hasMoreElements()) {
String name = names.nextElement();
m.getLogger(name).setFilter(new SpamFilter());
}

// Apache
Logger root = (Logger)org.apache.logging.log4j.LogManager.getRootLogger();
root.addFilter(new SpamFilter());

 

and here's the SpamFilter class:

 

package sblectric.logspamfilter.filter;

import java.util.logging.LogRecord;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Filter.Result;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.message.Message;

import sblectric.logspamfilter.config.FilterConfig;

/** The spam filter class for all logging */
public class SpamFilter implements java.util.logging.Filter, Filter {

/** All other filtering methods call this one */
public static Result filter(String message) {
	System.out.println("Message available");
	for(String s : FilterConfig.spamBlackList) {
		if (message.toLowerCase().contains(s.toLowerCase())) {
			return Result.DENY;
		}
	}
	return null;
}


@Override
public boolean isLoggable(LogRecord record) {
	return filter(record.getMessage()) != Result.DENY;
}

@Override
public Result filter(LogEvent event) {
	return filter(event.getMessage().toString());
}

@Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) {
	return filter(msg);
}

@Override
public Result filter(Logger arg0, Level arg1, Marker arg2, Message msg, Throwable arg4) {
	return filter(msg.toString());
}

@Override
public Result filter(Logger arg0, Level arg1, Marker arg2, Object arg3, Throwable arg4) {
	return null;
}

@Override
public Result getOnMatch() {
	return null;
}

@Override
public Result getOnMismatch() {
	return null;
}

}

 

The only time the static "filter" method was called was when MY mod's logger logged its status (the filter is working there), and not any of the other FML / MC stuff being logged.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.