Skip to content

Mod Logger

Jacky2611 edited this page Dec 28, 2018 · 2 revisions

The Cotton ModLogger allows you to write prettier logs.

Creating a new ModLogger

Creating a new ModLogger couldn't be easier. Simply put the following code in your mod's main file:

public static ModLogger logger = new ModLogger(MODID);

And that's all there really is to it. But you might want to add a custom prefix to your logger so it's easier to recognize your mod's logs:

public static ModLogger logger = new ModLogger(MODID, "Foo");

Now everything this logger writes will have the prefix "[Foo]: "

Using your logger

A ModLogger comes with different levels, which makes it easier to only log what you need. You can log using a level by writing: logger.level("Hello World!"). Each level has a different priority and some of them also have special colors to make them more visible.

Custom Prefix Formatting

To make your prefix even more unique you can add custom ASCI formats to it. The following example will make the prefix bold and green: logger.setPrefixFormat(Ansi.Bold.and(Ansi.Green));