Jump to content

How to set up my logger?


BrainStone

Recommended Posts

Hello.

I am currently trying to set up logger. Meaning I want to determine which logging levels should be logged an which ones not. How can i do this?

 

(I didn't find any tutorials)

 

This is the code I'm currently using:

 

		// Somewhere in my preInit
	logger = event.getModLog();

	//Checks if mod is in debug mode (log all)
	if (BrainStone.debug) {
		logger.setLevel(Level.ALL);
	//Checks if mod is a release (log less)
	} else if (BrainStone.release) {
		logger.setLevel(Level.INFO);
	//Default (log some)
	} else {
		logger.setLevel(Level.FINE);
	}
	// Some other code

 

This does not work!

And I'm pretty sure why this does not work.

 

Here an extract from the documentation of the FMLPreInitializationEvent.getModLog method:

Configurations can be applied through the config/logging.properties file, specifying logging levels for your ModID. Use this!

 

So how do I set everything up?

Link to comment
Share on other sites

If you just want something simple, just use System.out.printf("message here %n") but that doesn't work with logging levels as far as I know

 

Are you kidding me? ???

 

 

That does not work. I'm using this code:

 

		// Somewhere in my preInit
	logger = event.getModLog();

	//Checks if mod is in debug mode (log all)
	if (BrainStone.debug) {
		logger.setLevel(Level.ALL);
	//Checks if mod is a release (log less)
	} else if (BrainStone.release) {
		logger.setLevel(Level.INFO);
	//Default (log some)
	} else {
		logger.setLevel(Level.FINE);
	}
	// Some other code

 

And I'm pretty sure why this does not work.

 

Here an extract from the documentation of the FMLPreInitializationEvent.getModLog method:

Configurations can be applied through the config/logging.properties file, specifying logging levels for your ModID. Use this!

 

So how do I set everything up?

Link to comment
Share on other sites

I figured this out last night in my own code. The console log defaults to INFO level, and is not affected by setting log levels on the FMLLog. However, if you go check your Forge log files, I think you'll find all those missing FINEST/FINER/FINE messages being written out.

 

The console log cannot be changed via the "logging.properties" file; it is hard-coded in the initialization to "INFO", and the console logger object is private and cannot be accessed.

 

I decided for my own project a logging.properties file wasn't necessary because the FMLLog can be set internally, so I did not retain one.

 

However, if you want one, it goes in the top level of your config directory.  You can find an example one the one used by your JRE, with comments, in the jre/lib directory of your JDK. (In my case, that would be C:\Program Files\Java\jdk1.7.0_25\jre\lib\logging.properties). Don't tamper with that one, just use it as an example.  The general use of

it is discussed in the Java LogManager class documentation at http://docs.oracle.com/javase/7/docs/api/java/util/logging/LogManager.html.

 

Here's the important contents:

 

# Default global logging level
.level= INFO

 

would set the FMLlog and all child logs to default level of INFO, unless otherwise specified.

You can either specify otherwise programmatically, or by using the name of the logger (as set by "getLog()")

+ '.level'; e.g.

 

ForgeModLoader.level=ALL 

 

should set the FML file log to level.ALL, for example.

Link to comment
Share on other sites

I figured this out last night in my own code. The console log defaults to INFO level, and is not affected by setting log levels on the FMLLog. However, if you go check your Forge log files, I think you'll find all those missing FINEST/FINER/FINE messages being written out.

 

The console log cannot be changed via the "logging.properties" file; it is hard-coded in the initialization to "INFO", and the console logger object is private and cannot be accessed.

 

I decided for my own project a logging.properties file wasn't necessary because the FMLLog can be set internally, so I did not retain one.

 

However, if you want one, it goes in the top level of your config directory.  You can find an example one the one used by your JRE, with comments, in the jre/lib directory of your JDK. (In my case, that would be C:\Program Files\Java\jdk1.7.0_25\jre\lib\logging.properties). Don't tamper with that one, just use it as an example.  The general use of

it is discussed in the Java LogManager class documentation at http://docs.oracle.com/javase/7/docs/api/java/util/logging/LogManager.html.

 

Here's the important contents:

 

# Default global logging level
.level= INFO

 

would set the FMLlog and all child logs to default level of INFO, unless otherwise specified.

You can either specify otherwise programmatically, or by using the name of the logger (as set by "getLog()")

+ '.level'; e.g.

 

ForgeModLoader.level=ALL 

 

should set the FML file log to level.ALL, for example.

 

Thank you. This helped me! But there's still a problem. When I use this logging.properties file:

.level=ALL
BrainStoneMod.level=ALL
ForgeModLoader.level=ALL

(BrainStoneMod is my ModID) then still the fine/finer/finest levels are not displayed! I put it in mcp/jars/config. (That's the place where all other configs are located and in the beginning it says that ForgeModLoader logging level is set to ALL.)

 

What have I not seen? Or what could I do to fix this?

Link to comment
Share on other sites

Are you looking at the console window in Eclipse for your messages, or at the '\forge\mcp\jars\ForgeModLoader-client-0.log" on your hard drive?  Like I said, you can't change the logging level of the console window; but if they are not showing up in the "ForgeModLoader-client-0.log" log file, something is definitely wrong.

 

 

Link to comment
Share on other sites

Could you tell me where I can find the member or even better where I can the spot where the level.INFO is hard coded?

I'm thinking about using reflection to manipulate the logger during runtime. Which should make it possible to set the console logging Level for my logger to Level.ALL.

 

(Is ist possible to only do this to my logger?)

Link to comment
Share on other sites

Could you tell me where I can find the member or even better where I can the spot where the level.INFO is hard coded?

I'm thinking about using reflection to manipulate the logger during runtime. Which should make it possible to set the console logging Level for my logger to Level.ALL.

 

(Is ist possible to only do this to my logger?)

 

That would be insanely retarded to do :P

I mean, changing a part of the java standard lib, I like to believe it was made as it was for good reasons, and at your current level you probably don't understand them yet!

 

I don't know what the F you are trying to do or why, but I can promise you that if you feel you must resort to manipulating the standard libraries, you are doing something very very VERY wrong. I'd suggest you re-think your implementation plan and WHY you need to do it, there's probably a different way to accomplish whatever you really want to do..

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Ok. To clear things up:

 

I have set up my mod and everything. And I have messages to log to the console. The messages have different levels off logging. (Ranging from SEVERE to FINEST) And depending on some flags I want them either to appear or not. For several reasons I cannot just use the output (Forge-client-log-0.log) for example because I need these messages to debug my code.

Now changing the logging levels of these messages isn't a good solution. I'd have to find the messages (might be pretty hard because there are many) change the logging level and after I'm done I have to change them back. Isn't there another solution to this?

 

I have also written a logger wrapper class: (It's very large)

 

 

Link to the class: https://github.com/BrainStone/brainstone/blob/master/brainstonemod/templates/BSP.java

 

package brainstonemod.templates;

import java.util.logging.Level;
import java.util.logging.Logger;

import brainstonemod.BrainStone;

/**
* <center><b><u>B</u>rain<u>S</u>tone<u>P</u>rinter</b></center><br>
* This class is the printer class for the BrainStoneMod. It contains a lot of
* static final printing methods, that will print the given object under the
* right conditions. Exceptions will be thrown here as well.
* 
* @author Yannick Schinko (alias The_BrainStone)
* @version 2.0.0
* @category Print
*/
public abstract class BSP {
/**
 * A error message addon that is very big, asks the user to send the error
 * log to the mod developer, and contains the email address
 */
public static final String errorMessageAddon = "\n==================================================\n"
		+ "==================================================\n"
		+ "   There occured an error in the BrainStoneMod!   \n"
		+ "   Please send the error log to the developer.    \n"
		+ "   This is important if you want the error to be  \n"
		+ "  fixed. To send the log to me, just send a email \n"
		+ "         with the file of the error log to        \n"
		+ "                yannick@tedworld.de               \n\n"
		+ "              Thank you for your help!            \n"
		+ "==================================================\n"
		+ "==================================================\n";

/**
 * This is the logger for the BSM. Will be initialized in the BrainStone
 * class
 */
private static Logger logger;

/**
 * <b>A</b>dd<b>N</b>ew<b>L</b>ine<b>I</b>f<b>N</b>ecessary<br>
 * This function adds a new line in front of a string if necessary.
 * 
 * @param str
 *            String to be processed
 * @return If the String is no empty, a new line will be added in front of
 *         str
 */
private static final String ANLIN(String str) {
	return (str.isEmpty()) ? str : "\n" + str;
}

/**
 * Logs all Objects to the console with the normal CONFIG level
 * 
 * @param obj
 *            the objects to be logged
 * @return Return whether the log was logged or not
 * @see public static final boolean print(Level.CONFIG, Object... obj)
 */
public static final boolean config(Object... obj) {
	for (final Object log : obj) {
		logger.config(log.toString());
	}

	return logger.isLoggable(Level.CONFIG);
}

/**
 * This logs an error to the console with the CONFIG level and appends the
 * errorMessageAddon
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 * @see printException(Level.CONFIG, Exception ex)
 * @see printException(Exception ex)
 */
public static final boolean configException(Exception ex) {
	return configException(ex, "");
}

/**
 * This logs an error to the console with the CONFIG level and appends the
 * errorMessageAddon and an additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message appended to the standard error message addon
 * @return Return whether the log was logged or not
 * @see printException(Level.CONFIG, Exception ex, String additionalMessage)
 * @see printException(Exception ex, String additionalMessage)
 */
public static final boolean configException(Exception ex,
		String additionalMessage) {
	logger.log(Level.CONFIG, errorMessageAddon + ANLIN(additionalMessage),
			ex);

	return logger.isLoggable(Level.CONFIG);
}

/**
 * This logs an error to the console with the CONFIG level
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 *         printException_noAddon(Level.CONFIG, Exception ex)
 * @see printException_noAddon(Exception ex)
 */
public static final boolean configException_noAddon(Exception ex) {
	return configException_noAddon(ex, "");
}

/**
 * This logs an error to the console with the CONFIG level and an additional
 * message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message put in front of the error log
 * @return Return whether the log was logged or not
 * @see printException_noAddon(Level.CONFIG, Exception ex, String
 *      additionalMessage)
 * @see printException_noAddon(Exception ex, String additionalMessage)
 */
public static final boolean configException_noAddon(Exception ex,
		String additionalMessage) {
	logger.log(Level.CONFIG, additionalMessage, ex);

	return logger.isLoggable(Level.CONFIG);
}

/**
 * Logs all Objects to the console with the normal FINE level
 * 
 * @param obj
 *            the objects to be logged
 * @return Return whether the log was logged or not
 * @see public static final boolean print(Level.FINE, Object... obj)
 */
public static final boolean fine(Object... obj) {
	for (final Object log : obj) {
		logger.fine(log.toString());
	}

	return logger.isLoggable(Level.FINE);
}

/**
 * This logs an error to the console with the FINE level and appends the
 * errorMessageAddon
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 * @see printException(Level.FINE, Exception ex)
 * @see printException(Exception ex)
 */
public static final boolean fineException(Exception ex) {
	return fineException(ex, "");
}

/**
 * This logs an error to the console with the FINE level and appends the
 * errorMessageAddon and an additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message appended to the standard error message addon
 * @return Return whether the log was logged or not
 * @see printException(Level.FINE, Exception ex, String additionalMessage)
 * @see printException(Exception ex, String additionalMessage)
 */
public static final boolean fineException(Exception ex,
		String additionalMessage) {
	logger.log(Level.FINE, errorMessageAddon + ANLIN(additionalMessage), ex);

	return logger.isLoggable(Level.FINE);
}

/**
 * This logs an error to the console with the FINE level
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 *         printException_noAddon(Level.FINE, Exception ex)
 * @see printException_noAddon(Exception ex)
 */
public static final boolean fineException_noAddon(Exception ex) {
	return fineException_noAddon(ex, "");
}

/**
 * This logs an error to the console with the FINE level and an additional
 * message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message put in front of the error log
 * @return Return whether the log was logged or not
 * @see printException_noAddon(Level.FINE, Exception ex, String
 *      additionalMessage)
 * @see printException_noAddon(Exception ex, String additionalMessage)
 */
public static final boolean fineException_noAddon(Exception ex,
		String additionalMessage) {
	logger.log(Level.FINE, additionalMessage, ex);

	return logger.isLoggable(Level.FINE);
}

/**
 * Logs all Objects to the console with the normal FINER level
 * 
 * @param obj
 *            the objects to be logged
 * @return Return whether the log was logged or not
 * @see public static final boolean print(Level.FINER, Object... obj)
 */
public static final boolean finer(Object... obj) {
	for (final Object log : obj) {
		logger.finer(log.toString());
	}

	return logger.isLoggable(Level.FINER);
}

/**
 * This logs an error to the console with the FINER level and appends the
 * errorMessageAddon
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 * @see printException(Level.FINER, Exception ex)
 * @see printException(Exception ex)
 */
public static final boolean finerException(Exception ex) {
	return finerException(ex, "");
}

/**
 * This logs an error to the console with the FINER level and appends the
 * errorMessageAddon and an additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message appended to the standard error message addon
 * @return Return whether the log was logged or not
 * @see printException(Level.FINER, Exception ex, String additionalMessage)
 * @see printException(Exception ex, String additionalMessage)
 */
public static final boolean finerException(Exception ex,
		String additionalMessage) {
	logger.log(Level.FINER, errorMessageAddon + ANLIN(additionalMessage),
			ex);

	return logger.isLoggable(Level.FINER);
}

/**
 * This logs an error to the console with the FINER level
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 *         printException_noAddon(Level.FINER, Exception ex)
 * @see printException_noAddon(Exception ex)
 */
public static final boolean finerException_noAddon(Exception ex) {
	return finerException_noAddon(ex, "");
}

/**
 * This logs an error to the console with the FINER level and an additional
 * message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message put in front of the error log
 * @return Return whether the log was logged or not
 * @see printException_noAddon(Level.FINER, Exception ex, String
 *      additionalMessage)
 * @see printException_noAddon(Exception ex, String additionalMessage)
 */
public static final boolean finerException_noAddon(Exception ex,
		String additionalMessage) {
	logger.log(Level.FINER, additionalMessage, ex);

	return logger.isLoggable(Level.FINER);
}

/**
 * Logs all Objects to the console with the normal FINEST level
 * 
 * @param obj
 *            the objects to be logged
 * @return Return whether the log was logged or not
 * @see public static final boolean print(Level.FINEST, Object... obj)
 */
public static final boolean finest(Object... obj) {
	for (final Object log : obj) {
		logger.finest(log.toString());
	}

	return logger.isLoggable(Level.FINEST);
}

/**
 * This logs an error to the console with the FINEST level and appends the
 * errorMessageAddon
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 * @see printException(Level.FINEST, Exception ex)
 * @see printException(Exception ex)
 */
public static final boolean finestException(Exception ex) {
	return finestException(ex, "");
}

/**
 * This logs an error to the console with the FINEST level and appends the
 * errorMessageAddon and an additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message appended to the standard error message addon
 * @return Return whether the log was logged or not
 * @see printException(Level.FINEST, Exception ex, String additionalMessage)
 * @see printException(Exception ex, String additionalMessage)
 */
public static final boolean finestException(Exception ex,
		String additionalMessage) {
	logger.log(Level.FINEST, errorMessageAddon + ANLIN(additionalMessage),
			ex);

	return logger.isLoggable(Level.FINEST);
}

/**
 * This logs an error to the console with the FINEST level
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 *         printException_noAddon(Level.FINEST, Exception ex)
 * @see printException_noAddon(Exception ex)
 */
public static final boolean finestException_noAddon(Exception ex) {
	return finestException_noAddon(ex, "");
}

/**
 * This logs an error to the console with the FINEST level and an additional
 * message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message put in front of the error log
 * @return Return whether the log was logged or not
 * @see printException_noAddon(Level.FINEST, Exception ex, String
 *      additionalMessage)
 * @see printException_noAddon(Exception ex, String additionalMessage)
 */
public static final boolean finestException_noAddon(Exception ex,
		String additionalMessage) {
	logger.log(Level.FINEST, additionalMessage, ex);

	return logger.isLoggable(Level.FINEST);
}

/**
 * Logs all Objects to the console with the normal INFO level
 * 
 * @param obj
 *            the objects to be logged
 * @return Return whether the log was logged or not
 * @see public static final boolean print(Object... obj)
 * @see public static final boolean print(Level.INFO, Object... obj)
 */
public static final boolean info(Object... obj) {
	for (final Object log : obj) {
		logger.info(log.toString());
	}

	return logger.isLoggable(Level.INFO);
}

/**
 * This logs an error to the console with the normal INFO level and appends
 * the errorMessageAddon
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 * @see printException(Level.INFO, Exception ex)
 * @see printException(Exception ex)
 */
public static final boolean infoException(Exception ex) {
	return infoException(ex, "");
}

/**
 * This logs an error to the console with the normal INFO level and appends
 * the errorMessageAddon and an additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message appended to the standard error message addon
 * @return Return whether the log was logged or not
 * @see printException(Level.INFO, Exception ex, String additionalMessage)
 * @see printException(Exception ex, String additionalMessage)
 */
public static final boolean infoException(Exception ex,
		String additionalMessage) {
	logger.log(Level.INFO, errorMessageAddon + ANLIN(additionalMessage), ex);

	return logger.isLoggable(Level.INFO);
}

/**
 * This logs an error to the console with the normal INFO level
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 *         printException_noAddon(Level.INFO, Exception ex)
 * @see printException_noAddon(Exception ex)
 */
public static final boolean infoException_noAddon(Exception ex) {
	return infoException_noAddon(ex, "");
}

/**
 * This logs an error to the console with the normal INFO level and an
 * additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message put in front of the error log
 * @return Return whether the log was logged or not
 * @see printException_noAddon(Level.INFO, Exception ex, String
 *      additionalMessage)
 * @see printException_noAddon(Exception ex, String additionalMessage)
 */
public static final boolean infoException_noAddon(Exception ex,
		String additionalMessage) {
	logger.log(Level.INFO, additionalMessage, ex);

	return logger.isLoggable(Level.INFO);
}

/**
 * Logs all Objects to the console with the level to be logged
 * 
 * @param level
 *            the level the objects will be logged
 * @param obj
 *            the objects to be logged
 * @return Return whether the log was logged or not
 */
public static final boolean print(Level level, Object... obj) {
	for (final Object log : obj) {
		logger.log(level, log.toString());
	}

	return logger.isLoggable(level);
}

/**
 * Logs all Objects to the console with the normal INFO level
 * 
 * @param obj
 *            the objects to be logged
 * @return Return whether the log was logged or not
 * @see public static final boolean info(Object... obj)
 * @see public static final boolean print(Level.INFO, Object... obj)
 */
public static final boolean print(Object... obj) {
	for (final Object log : obj) {
		logger.info(log.toString());
	}

	return logger.isLoggable(Level.INFO);
}

/**
 * This logs an error to the console with the normal INFO level and appends
 * the errorMessageAddon
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 * @see printException(Level.INFO, Exception ex)
 * @see infoException(Exception ex)
 */
public static final boolean printException(Exception ex) {
	return printException(ex, "");
}

/**
 * This logs an error to the console with the normal INFO level and appends
 * the errorMessageAddon and an additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message appended to the standard error message addon
 * @return Return whether the log was logged or not
 * @see printException(Level.INFO, Exception ex, String additionalMessage)
 * @see infoException(Exception ex, String additionalMessage)
 */
public static final boolean printException(Exception ex,
		String additionalMessage) {
	logger.log(Level.INFO, errorMessageAddon + ANLIN(additionalMessage), ex);

	return logger.isLoggable(Level.INFO);
}

/**
 * This logs an error to the console with the level to be logged
 * 
 * @param level
 *            the level the objects will be logged
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 */
public static final boolean printException(Level level, Exception ex) {
	return printException(level, ex, "");
}

/**
 * This logs an error to the console with an additional message and the
 * level to be logged
 * 
 * @param level
 *            the level the objects will be logged
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message appended to the standard error message addon
 * @return Return whether the log was logged or not
 */
public static final boolean printException(Level level, Exception ex,
		String additionalMessage) {
	logger.log(level, errorMessageAddon + ANLIN(additionalMessage), ex);

	return logger.isLoggable(level);
}

/**
 * This logs an error to the console with the normal INFO level
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 *         printException_noAddon(Level.INFO, Exception ex)
 * @see infoException_noAddon(Exception ex)
 */
public static final boolean printException_noAddon(Exception ex) {
	return printException_noAddon(ex, "");
}

/**
 * This logs an error to the console with the normal INFO level and an
 * additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message put in front of the error log
 * @return Return whether the log was logged or not
 * @see printException_noAddon(Level.INFO, Exception ex, String
 *      additionalMessage)
 * @see infoException_noAddon(Exception ex, String additionalMessage)
 */
public static final boolean printException_noAddon(Exception ex,
		String additionalMessage) {
	logger.log(Level.INFO, additionalMessage, ex);

	return logger.isLoggable(Level.INFO);
}

/**
 * This logs an error to the console with the level to be logged
 * 
 * @param level
 *            the level the objects will be logged
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 */
public static final boolean printException_noAddon(Level level, Exception ex) {
	return printException_noAddon(level, ex, "");
}

/**
 * This logs an error to the console with an additional message and the
 * level to be logged
 * 
 * @param level
 *            the level the objects will be logged
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message put in front of the error log
 * @return Return whether the log was logged or not
 */
public static final boolean printException_noAddon(Level level,
		Exception ex, String additionalMessage) {
	logger.log(level, additionalMessage, ex);

	return logger.isLoggable(level);
}

/**
 * Sets up the logger and also sets up the corresponding filter
 * 
 * @param logger
 *            - the logger for this class
 */
public static void setUpLogger(Logger logger) {
	BSP.logger = logger;

	if (BrainStone.debug) {
		BSP.logger.setLevel(Level.ALL);
	} else if (BrainStone.release) {
		BSP.logger.setLevel(Level.INFO);
	} else {
		BSP.logger.setLevel(Level.FINE);
	}
}

/**
 * Logs all Objects to the console with the normal SEVERE level
 * 
 * @param obj
 *            the objects to be logged
 * @return Return whether the log was logged or not
 * @see public static final boolean print(Level.SEVERE, Object... obj)
 */
public static final boolean severe(Object... obj) {
	for (final Object log : obj) {
		logger.severe(log.toString());
	}

	return logger.isLoggable(Level.SEVERE);
}

/**
 * This logs an error to the console with the SEVERE level and appends the
 * errorMessageAddon
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 * @see printException(Level.SEVERE, Exception ex)
 * @see printException(Exception ex)
 */
public static final boolean severeException(Exception ex) {
	return severeException(ex, "");
}

/**
 * This logs an error to the console with the SEVERE level and appends the
 * errorMessageAddon and an additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message appended to the standard error message addon
 * @return Return whether the log was logged or not
 * @see printException(Level.SEVERE, Exception ex, String additionalMessage)
 * @see printException(Exception ex, String additionalMessage)
 */
public static final boolean severeException(Exception ex,
		String additionalMessage) {
	logger.log(Level.SEVERE, errorMessageAddon + ANLIN(additionalMessage),
			ex);

	return logger.isLoggable(Level.SEVERE);
}

/**
 * This logs an error to the console with the SEVERE level
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 *         printException_noAddon(Level.SEVERE, Exception ex)
 * @see printException_noAddon(Exception ex)
 */
public static final boolean severeException_noAddon(Exception ex) {
	return severeException_noAddon(ex, "");
}

/**
 * This logs an error to the console with the SEVERE level and an additional
 * message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message put in front of the error log
 * @return Return whether the log was logged or not
 * @see printException_noAddon(Level.SEVERE, Exception ex, String
 *      additionalMessage)
 * @see printException_noAddon(Exception ex, String additionalMessage)
 */
public static final boolean severeException_noAddon(Exception ex,
		String additionalMessage) {
	logger.log(Level.SEVERE, additionalMessage, ex);

	return logger.isLoggable(Level.SEVERE);
}

/**
 * Throws a ArithmeticException with the error message addon
 */
public static final void throwArithmeticException() {
	throwArithmeticException("");
}

/**
 * Throws a ArithmeticException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwArithmeticException(String additionalMessage) {
	throw new ArithmeticException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a ArrayIndexOutOfBoundsException with the error message addon
 */
public static final void throwArrayIndexOutOfBoundsException() {
	throwArrayIndexOutOfBoundsException("");
}

/**
 * Throws a ArrayIndexOutOfBoundsException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwArrayIndexOutOfBoundsException(
		String additionalMessage) {
	throw new ArrayIndexOutOfBoundsException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a ArrayStoreException with the error message addon
 */
public static final void throwArrayStoreException() {
	throwArrayStoreException("");
}

/**
 * Throws a ArrayStoreException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwArrayStoreException(String additionalMessage) {
	throw new ArrayStoreException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a ClassCastException with the error message addon
 */
public static final void throwClassCastException() {
	throwClassCastException("");
}

/**
 * Throws a ClassCastException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwClassCastException(String additionalMessage) {
	throw new ClassCastException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a ClassNotFoundException with the error message addon
 * 
 * @throws ClassNotFoundException
 */
public static final void throwClassNotFoundException()
		throws ClassNotFoundException {
	throwClassNotFoundException("");
}

/**
 * Throws a ClassNotFoundException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 * @throws ClassNotFoundException
 */
public static final void throwClassNotFoundException(
		String additionalMessage) throws ClassNotFoundException {
	throw new ClassNotFoundException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a CloneNotSupportedException with the error message addon
 * 
 * @throws CloneNotSupportedException
 */
public static final void throwCloneNotSupportedException()
		throws CloneNotSupportedException {
	throwCloneNotSupportedException("");
}

/**
 * Throws a CloneNotSupportedException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 * @throws CloneNotSupportedException
 */
public static final void throwCloneNotSupportedException(
		String additionalMessage) throws CloneNotSupportedException {
	throw new CloneNotSupportedException(errorMessageAddon
			+ ((additionalMessage.equals("")) ? "" : "\n"
					+ additionalMessage));
}

/**
 * Throws a Exception with the error message addon
 * 
 * @throws Exception
 */
public static final void throwException() throws Exception {
	throwException("");
}

/**
 * Throws a exception with the error message addon. This is for all
 * <b><u>non-RuntimeExceptions</u></b>
 * 
 * @param exception
 *            the exception to throw
 * @throws E
 *             the exception type
 */
public static final <E extends Throwable> void throwException(E exception)
		throws E {
	throwException(exception, "");
}

/**
 * Throws a exception with the error message addon. This is for all
 * <b><u>RuntimeExceptions</u></b>
 * 
 * @param exception
 *            the exception to throw
 */
public static final <E extends RuntimeException> void throwException(
		E exception) {
	throwException(exception, "");
}

/**
 * Throws a exception with the error message addon and a custom message.
 * This is for all <b><u>non-RuntimeExceptions</u></b>
 * 
 * @param exception
 *            the exception to throw
 * @param additionalMessage
 *            the custom message that will be added
 * @throws E
 *             the exception type
 */
public static final <E extends Throwable> void throwException(E exception,
		String additionalMessage) throws E {
	throw (E) new Throwable("(" + exception.getClass().getName() + ")"
			+ BSP.errorMessageAddon + ANLIN(additionalMessage + "\n")
			+ "\nOriginal message: \"" + exception.getMessage() + "\"\n",
			exception);
}

/**
 * Throws a exception with the error message addon and a custom message.
 * This is for all <b><u>RuntimeExceptions</u></b>
 * 
 * @param exception
 *            the exception to throw
 * @param additionalMessage
 *            the custom message that will be added
 */
public static final <E extends RuntimeException> void throwException(
		E exception, String additionalMessage) {
	throw (E) new RuntimeException("(" + exception.getClass().getName()
			+ ")" + errorMessageAddon + ANLIN(additionalMessage + "\n")
			+ "\nOriginal message: \"" + exception.getMessage() + "\"\n",
			exception);
}

/**
 * Throws a Exception with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 * @throws Exception
 */
public static final void throwException(String additionalMessage)
		throws Exception {
	throw new Exception(errorMessageAddon + ANLIN(additionalMessage));
}

/**
 * Throws a IllegalAccessException with the error message addon
 * 
 * @throws IllegalAccessException
 */
public static final void throwIllegalAccessException()
		throws IllegalAccessException {
	throwIllegalAccessException("");
}

/**
 * Throws a IllegalAccessException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 * @throws IllegalAccessException
 */
public static final void throwIllegalAccessException(
		String additionalMessage) throws IllegalAccessException {
	throw new IllegalAccessException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a IllegalArgumentException with the error message addon
 */
public static final void throwIllegalArgumentException() {
	throwIllegalArgumentException("");
}

/**
 * Throws a IllegalArgumentException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwIllegalArgumentException(
		String additionalMessage) {
	throw new IllegalArgumentException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a IllegalMonitorStateException with the error message addon
 */
public static final void throwIllegalMonitorStateException() {
	throwIllegalMonitorStateException("");
}

/**
 * Throws a IllegalMonitorStateException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwIllegalMonitorStateException(
		String additionalMessage) {
	throw new IllegalMonitorStateException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a IllegalThreadStateException with the error message addon
 */
public static final void throwIllegalThreadStateException() {
	throwIllegalThreadStateException("");
}

/**
 * Throws a IllegalThreadStateException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwIllegalThreadStateException(
		String additionalMessage) {
	throw new IllegalThreadStateException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a IndexOutOfBoundsException with the error message addon
 */
public static final void throwIndexOutOfBoundsException() {
	throwIndexOutOfBoundsException("");
}

/**
 * Throws a IndexOutOfBoundsException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwIndexOutOfBoundsException(
		String additionalMessage) {
	throw new IndexOutOfBoundsException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a InstantiationException with the error message addon
 * 
 * @throws InstantiationException
 */
public static final void throwInstantiationException()
		throws InstantiationException {
	throwInstantiationException("");
}

/**
 * Throws a InstantiationException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 * @throws InstantiationException
 */
public static final void throwInstantiationException(
		String additionalMessage) throws InstantiationException {
	throw new InstantiationException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a InterruptedException with the error message addon
 * 
 * @throws InterruptedException
 */
public static final void throwInterruptedException()
		throws InterruptedException {
	throwInterruptedException("");
}

/**
 * Throws a InterruptedException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 * @throws InterruptedException
 */
public static final void throwInterruptedException(String additionalMessage)
		throws InterruptedException {
	throw new InterruptedException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a NegativeArraySizeException with the error message addon
 */
public static final void throwNegativeArraySizeException() {
	throwNegativeArraySizeException("");
}

/**
 * Throws a NegativeArraySizeException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwNegativeArraySizeException(
		String additionalMessage) {
	throw new NegativeArraySizeException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a NoSuchMethodException with the error message addon
 * 
 * @throws NoSuchMethodException
 */
public static final void throwNoSuchMethodException()
		throws NoSuchMethodException {
	throwNoSuchMethodException("");
}

/**
 * Throws a NoSuchMethodException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 * @throws NoSuchMethodException
 */
public static final void throwNoSuchMethodException(String additionalMessage)
		throws NoSuchMethodException {
	throw new NoSuchMethodException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a NullPointerException with the error message addon
 */
public static final void throwNullPointerException() {
	throwNullPointerException("");
}

/**
 * Throws a NullPointerException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwNullPointerException(String additionalMessage) {
	throw new NullPointerException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a NumberFormatException with the error message addon
 */
public static final void throwNumberFormatException() {
	throwNumberFormatException("");
}

/**
 * Throws a NumberFormatException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwNumberFormatException(String additionalMessage) {
	throw new NumberFormatException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a RuntimeException with the error message addon
 */
public static final void throwRuntimeException() {
	throwRuntimeException("");
}

/**
 * Throws a RuntimeException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwRuntimeException(String additionalMessage) {
	throw new RuntimeException(errorMessageAddon + ANLIN(additionalMessage));
}

/**
 * Throws a SecurityException with the error message addon
 */
public static final void throwSecurityException() {
	throwSecurityException("");
}

/**
 * Throws a SecurityException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwSecurityException(String additionalMessage) {
	throw new SecurityException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a StringIndexOutOfBoundsException with the error message addon
 */
public static final void throwStringIndexOutOfBoundsException() {
	throwStringIndexOutOfBoundsException("");
}

/**
 * Throws a StringIndexOutOfBoundsException with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 */
public static final void throwStringIndexOutOfBoundsException(
		String additionalMessage) {
	throw new StringIndexOutOfBoundsException(errorMessageAddon
			+ ANLIN(additionalMessage));
}

/**
 * Throws a Throwable with the error message addon
 * 
 * @throws Throwable
 */
public static final void throwThrowable() throws Throwable {
	throwThrowable("");
}

/**
 * Throws a Throwable with the error message addon
 * 
 * @param additionalMessage
 *            a additional message added after the addon
 * @throws Throwable
 */
public static final void throwThrowable(String additionalMessage)
		throws Throwable {
	throw new Throwable(errorMessageAddon + ANLIN(additionalMessage));
}

/**
 * Logs all Objects to the console with the normal WARNING level
 * 
 * @param obj
 *            the objects to be logged
 * @return Return whether the log was logged or not
 * @see public static final boolean print(Level.WARNING, Object... obj)
 */
public static final boolean warning(Object... obj) {
	for (final Object log : obj) {
		logger.warning(log.toString());
	}

	return logger.isLoggable(Level.WARNING);
}

/**
 * This logs an error to the console with the WARNING level and appends the
 * errorMessageAddon
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 * @see printException(Level.WARNING, Exception ex)
 * @see printException(Exception ex)
 */
public static final boolean warningException(Exception ex) {
	return warningException(ex, "");
}

/**
 * This logs an error to the console with the WARNING level and appends the
 * errorMessageAddon and an additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message appended to the standard error message addon
 * @return Return whether the log was logged or not
 * @see printException(Level.WARNING, Exception ex, String
 *      additionalMessage)
 * @see printException(Exception ex, String additionalMessage)
 */
public static final boolean warningException(Exception ex,
		String additionalMessage) {
	logger.log(Level.WARNING, errorMessageAddon + ANLIN(additionalMessage),
			ex);

	return logger.isLoggable(Level.WARNING);
}

/**
 * This logs an error to the console with the WARNING level
 * 
 * @param ex
 *            the exception to be logged
 * @return Return whether the log was logged or not
 *         printException_noAddon(Level.WARNING, Exception ex)
 * @see printException_noAddon(Exception ex)
 */
public static final boolean warningException_noAddon(Exception ex) {
	return warningException_noAddon(ex, "");
}

/**
 * This logs an error to the console with the WARNING level and an
 * additional message
 * 
 * @param ex
 *            the exception to be logged
 * @param additionalMessage
 *            a message put in front of the error log
 * @return Return whether the log was logged or not
 * @see printException_noAddon(Level.WARNING, Exception ex, String
 *      additionalMessage)
 * @see printException_noAddon(Exception ex, String additionalMessage)
 */
public static final boolean warningException_noAddon(Exception ex,
		String additionalMessage) {
	logger.log(Level.WARNING, additionalMessage, ex);

	return logger.isLoggable(Level.WARNING);
}
}

 

Link to comment
Share on other sites

why cant you just use System.out.println like 99% of us ? this seems like a lot of effort to see

[sTDOUT][MyMod] penis 1

[sTDOUT][MyMod] penis 2

[sTDOUT][MyMod] penis 3

[sTDOUT][MyMod] penis 4

[sTDOUT][MyMod] penis 5

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

why cant you just use System.out.println like 99% of us ? this seems like a lot of effort to see

[sTDOUT][MyMod] penis 1

[sTDOUT][MyMod] penis 2

[sTDOUT][MyMod] penis 3

[sTDOUT][MyMod] penis 4

[sTDOUT][MyMod] penis 5

 

You obviously haven't understood the use of a logger. It basically rates messages. And also can disable them based on their rating.

Link to comment
Share on other sites

i obviously use a logger every single day of my life at work. but clearly it may be overkill for a minecraft mod... just saying. maybe im wrong and your mod is reaaaaaally big and you actualy need it. but i consider that im doing a big one and i dont need a logger

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

i obviously use a logger every single day of my life at work. but clearly it may be overkill for a minecraft mod... just saying. maybe im wrong and your mod is reaaaaaally big and you actualy need it. but i consider that im doing a big one and i dont need a logger

 

I don't NEED a logger but I really like the advantages of it. I first did not like it either. But now I really enjoy seeing instantly how important a message in the console is.

(And I guess a mod of 10k lines is no longer considered a small mod, is it?  ;))

Link to comment
Share on other sites

yeah i understand, but this is a java issue not a forge issue, you should be able to find this in google easily

 

(btw mine has 18-19k :P, but yeah id consider 10k a big mod xD)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Well after doing some sirious research I found out that the following code should work:

 

logger.setLevel(myLevel);

for(Handler handler : loger.getHandlers()) {
  handler.setLevel(myLevel);
}

 

It does not and that for a specific reason:

 

In the class where the main logger is set up there is this line:

ConsoleLogThread.wrappedHandler.setLevel(Level.parse(System.getProperty("fml.log.level","INFO")));

 

Which basically sets the logging level for the console to Level.INFO in a way that makes it (almost (not sure if possible or not)) impossible to overwrite with your own logger. "ConsoleLogThread" is a private class in this class so I cannot access it.

 

So how could I still change this level for my logger? (The class the code is found: cpw.mods.fml.relauncher.FMLRelaunchLog)

 

I hope you understand my problem!

Link to comment
Share on other sites

So why can't you just monitor the Forge-client log (or server log)? There are ways to tee that to a window, depending on what OS you are using. (In linux it would be "tail -f <filename>", of course)  Why does it have to be the console log?

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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