[SOLVED?] How should i Use Logger, Or Save Error Game Files with Libgdx?

How should i Use Logger, Or Save Error Game Files with Libgdx?

Hi guys, im wondering, how should i make the logger in my game?
Should i have a class that records all errors in a .txt file before it crashes the game or i should use log4j or does libgdx have its own logger?

Whats the best practice???

Thanks Guys!

Im almost there… :slight_smile:

+1 on this
is it possible to redirect the stream to a text file before the game exits. We wrote our own stream before but now we wanna try the libgdx logger.

also the debug method never printed anything for me, no matter what level I set. info and error worked though D:

Ah another thing: calls are asynchron… which is horrible for game debugging


		logger = new Logger("TAG", Logger.DEBUG);
		logger.debug("debug");
		logger.info("info");
		logger.error("error");
		System.out.println("Test\n");

Result:

also showcases debug missing

Hm, I’ve always used this Gdx.app.log (https://code.google.com/p/libgdx/wiki/ApplicationLogging) and Gdx.app.error and I’ve never had any problems with it.

@OP exactly why do you need to save error files? Unless you plan on widely distributing the game, and have a method to relay the error message back from other computers to you, it’s not really necessary.
If you decide you still need it, check this out.

You just answered your own question. Once you sell a game, we have to have a mechanism to learn about crashes, to improve upon code stability.
The Stream to file is actually very easily to do with the default stream, but yeah

maybe we should go log4j

Use a proper logging framework. You can plug in different SPIs\bindings into the framework that will handle the logs differently.

JevaEngine uses this one:
http://www.slf4j.org/

Logs are obviously important, even if you just spit them back to the user. I have had users who experience problems with my applications provide me a log that I would’ve been left guessing without.

When you want to distribute your software, you can easily No-Operation your logs if you use slf4j with little performance impact by plugging in the No-Operation binding without making any mutations to the code, and just plugging in a different binding.

Will i have any problems if i just use a .txt File to record bad things?
I plan to run in HTML,desktop and Android

No, not really. It all depends on what you want to do. You’ll have to make your own logging system if you don’t use someone else’s, but it all depends upon what you want!

@Cero, if he wants the log files to have any sort of effect he will need a way to send log files back to the master server/computer, so if he doesn’t know networking or anything it might not be worth it, especially if it’s not a long term project.

Nope, but keep in mind:

  • Logging frameworks (like slf4j) batch I/O operations to logging repositories (i.e, a text file) rather than write per function call. This prevents them from consuming a lot of CPU time when you’re in the middle of a time-sensitive task (like rendering\updating)
  • If you use slf4j, you can very easily change your binding, so if you want to (for example) print the logs to a console, save them to a file, dispatch them to a server or ignore them, you can do that without altering any of your existing code (and just swapping bindings).