Jump to content

How to enable "debug" logging in eclipse?


Bedrock_Miner

Recommended Posts

Window -> Show View -> Console

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

eclipse.log.level ?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

The Eclipse runtime options

 

Version 3.6 - Last revised August 5, 2009

 

The Eclipse platform is highly configurable. Configuration input takes the form of command line arguments and System property settings. In many cases the command line arguments are simply short cuts for setting the related System properties. In fact, there are many more System property settings than command line arguments.

 

It's a program option flag you can set when launching Eclipse (either via command line or via a shortcut).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I haven't used it TBH.  I just googled around.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Hello

 

Do you use this logger:

event.getModLog(); //event is preInit event

 

Because for this one, the javadoc sais:

Get a logger instance configured to write to the FML Log as a parent, identified by modid. Handy for mod logging! Configurations can be applied through the config/logging.properties file, specifying logging levels for your ModID. Use this!

 

The point that I dont get, is which config folder do I have to use? The one that is child of eclipse/ ?

 

Then again, log4j 2 tells us to use either a JSON, XML or YAML file - why forge wants us to use a properties file?

 

Sincerely -pick

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

Link to comment
Share on other sites

Tried this but didn't work. Why?!

((Logger)LogManager.getLogger(Minersbasic.MODID)).setLevel(Level.ALL);
((Logger)LogManager.getLogger(Minersbasic.MODID)).info("test"); //Only this was logged
((Logger)LogManager.getLogger(Minersbasic.MODID)).debug("test");
((Logger)LogManager.getLogger(Minersbasic.MODID)).trace("test");

 

Logger is org.apache.logging.log4j.core.Logger.

Link to comment
Share on other sites

OK, little bit of research showed the following:

 

The LoggerConfig of the FML Logger is set to Level.INFO in the file log4j2.xml:

<Root level="all">
    <AppenderRef ref="FmlSysOut" level="INFO" />
    <AppenderRef ref="ServerGuiConsole" level="INFO" />
    <AppenderRef ref="FmlFile"/>
</Root>

 

I need to get this LoggerConfig object, then I can change the level.

Problem: The object is wrapped in another object of the class PrivateConfig which is defined as a protected class inside Logger.

Can I get the Object via reflection somehow?

Link to comment
Share on other sites

  • 9 months later...

Did you ever find out how to turn on debug messages to the gui?

 

I understand sending debug and trace messages to the gui is not a good idea. However during development of a private mod I don't mind seeing my mod's debug and trace messages in the gui.

 

I have tried a log4j2.xml with select <Logger> named and leveled settings, one file in each part of the entire class path, to no avail. Meaning I clearly missed something. I used several loggers:

org.apache.logging.log4j.Logger

and

FMLog()

I get log messages, just not with TRACE or DEBUG levels.I presume that those logger levels don't have appenders to the console. I have failed to get it to work with trace and debug. I've tried .fine() and .finer() as well.

 

I've seen many working examples of FMLLog.info() or FMLLog.warn() or FMLLog.log() or using non-fml loggers, just not for debug and trace. I understand debug and trace go to the log files. I saw somewhere that a core forge developer wanted mod developers to setup our own mod logging.

 

I just seems that the rootlogger is preconfigured in a way that add perhaps some confusion, at least for me.

 

Link to comment
Share on other sites

While I haven't tried it myself (I plan to though because this has bugged me for a long time), a friend said you can get around the hard-coded limitation as follows:

 

You have to edit the forge-jar for that. What you do is open the jar that gradle downloaded and automatically includes in the buildpath for you. It is at C:/Users/<user>/.gradle/caches/minecraft/net/minecraftforge/forge/1.8-11.14.3.1450/snapshot/<YYYYMMDD>/forgeSrc-<version>.jar.

 

There should be a file named log4j2.xml in there, extract it and edit the line where it says

            <AppenderRef ref="FmlSysOut" level="INFO" />

to

            <AppenderRef ref="FmlSysOut" level="DEBUG" />

Save and override the file in the jar. You should now see debug output on your console.

 

The only thing is you have to remember to repeat this every time the workspace is refreshed. Which is every time the version is changed and you used setupDecompWorkspace.

 

Try it out and let me know if it works. I don't have time at the moment.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Basically this must work because its the normal way you change logging behaviour with log4j. Butdoes anyone know where this file is actually loaded and in which variables the content is stored? I was looking for a possibility to enable this from code via reflection.

Link to comment
Share on other sites

I may have found a way to "enable" logging the way we are used to. Please, verify my train of thoughts:

 

[*]Fact: I'm using eclipse.

[*]Fact: Forge uses log4j2

[*]Fact: log4j2 is configured using properties/XML files.

If missing log4j(2) will log an error right at the beginning.

No error observed, log4j must be configured somewhere.

[*]Fact: The lib forgeSrc-<version>.jar contains a log4j2.xml

[*]Action: Copy this file to the root directory of the project.

Question: Which directory is the root?

[*]Observation: When starting the client using the eclipse launcher, a directory structure just like the one known from a normal forge installation is created within the "eclipse" dir.

[*]Action: Putting log4j2.xml into eclipse dir.

[*]Action: Verify which logger my mod gets in the pre-init phase.

FMLPreInitializationEvent event;
event.getModLog().getName()

Is seems to be one named like my MOD-ID.

[*]Action: Adding a logger for my mod to my log4j2.xml

<Loggers>
   [...]
    <Logger level="debug" name="myModId">
        <AppenderRef ref="FmlSysOut" />
    </Logger>
</Loggers>

(Not yet investigated what the 5 defined appenders do.)

[*]Action: Start client.

Observation: I'm still logging INFO.

[*]Action: Force log4j2 to load my file by adding a VM argument to the launcher config next to the memory size:

-Xincgc -Xmx1024M -Xms1024M -Dlog4j.configurationFile=log4j2.xml

[*]Action: Start client.

Observation: I'm logging DEBUG.

 

My idea is to have the dev env configured to log the way I want and not having to change my code or alter libs. Therefore, tweaking the launcher config and copying the logging config is acceptable, I think.

Link to comment
Share on other sites

Yeah, that is the way I thought I tried a few times. Basically supercede the xml with my own. However I never quite got it to work. Although I'm pretty sure I tried each of the things you mention, I may have missed putting them together in combination correctly.

 

I'll try it out.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.