Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

  • Author

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.

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.