Jump to content

Proper way to use a Logger


yooksi

Recommended Posts

What is the proper way of using a logger to log errors, debug information and other stuff I don't know about? I've tried to use it for debugging by calling logger.debug(msg) but I haven't been able to make it work, despite being in the actual debug mode. It was some time ago but I don't think I've been able to make it work for errors as well. How do you guys use the logger, and for what purposes?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

Are you sure it didn't work?

 

Regardless of where you're running Minecraft, only messages logged at

INFO

or higher are printed to the console. Every message (including

DEBUG

and

TRACE

messages) is written to the log file.

 

I use this wrapper for logging. You can see where I use it here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Very nice, thank you for giving me examples. I will try them out in a second, but I am wondering what are these markers. Searching on the internet about them gives me a bunch of technical information, but for starters I just want to know what is the simplest application of them?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

Very nice, thank you for giving me examples. I will try them out in a second, but I am wondering what are these markers. Searching on the internet about them gives me a bunch of technical information, but for starters I just want to know what is the simplest application of them?

 

Markers are objects that can be used to filter log messages. For example, you could configure all messages except those with the marker

FOO

to be printed to one log file and all messages with the marker

FOO

to be printed to a separate log file.

 

You generally don't need to use markers and Forge's log config won't print them to the console or log file.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Are you sure it didn't work?

 

Regardless of where you're running Minecraft, only messages logged at

INFO

or higher are printed to the console. Every message (including

DEBUG

and

TRACE

messages) is written to the log file.

 

I use this wrapper for logging. You can see where I use it here.

Aha, now I understand. The error log is displayed in the console but the debug log is not, instead it goes into the log file. I didn't know that. Can you give me a quick example of how to simply setup a marker to post all my mod debug stuff in a separate log file? When I check the log file for debug logs there is too much info I don't want to see, and sorting through that to find what I need can be a bit tiresome.

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

Can you give me a quick example of how to simply setup a marker to post all my mod debug stuff in a separate log file? When I check the log file for debug logs there is too much info I don't want to see, and sorting through that to find what I need can be a bit tiresome.

 

It looks the version of log4j used by Minecraft only supports a single global configuration file, so you'll need to add this in code. I haven't done this myself, but the log4j website briefly explains it here.

 

Like in the example, you'll probably need to create an

Appender

to append to your file and a

LoggerConfig

with the same name as your

Logger

(this is your mod ID if you're using the one returned by

FMLPreInitializationEvent

). The

LoggerConfig

should be non-additive and have an

AppenderRef

to your

Appender

. You can also give it a

MarkerFilter

to only include messages with a specific marker.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

It seems to me that it would be a lot easier to just setup my own logger and have it write to a dedicated text file. I don't know where to add that code and I think this all requires me to setup a log4j.properties file, which I've created with default values but don't know how to test to see if it loads. Well, at least I got the error and debug messages to work. That's gonna do good for now, thanks.

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

I use this wrapper for logging. You can see where I use it here.

I decided to use your wrapper and come up with a secondary mod logging system. The system is currently setup to write errors, warnings and fatal logs to a separate text file in addition to being already printed to the console and written to the main log4j log file. This way I have a copy of all the logs I am really interested in. I can use that info (by checking the date and time) to find the stack trace in the FML-client log file. This is the best thing I could come up with, you can check it out here.

 

I've also discovered this in the comment of the FMLPreInitializationEvent.getModLog() method:

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

Could this be where we should create out log4j property file or is this some kind of custom Forge configuration file?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

I've also discovered this in the comment of the FMLPreInitializationEvent.getModLog() method:

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

Could this be where we should create out log4j property file or is this some kind of custom Forge configuration file?

 

No, that's an outdated comment from before Minecraft switched to log4j.

 

Edit: I've reported it here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

    • Try deliting feur builder  It caused this issue in my modpack
    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

×
×
  • Create New...

Important Information

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