Saturday, July 25, 2015

LibGDX - Logging facilities

In this post I will describe the two logging facilities provided by LibGDX, Logger class and Application logging interface.

Application logging interface

Application class offers several static method to send log messages with different priorities:

  • debug (LOG_DEBUG)
  • error (LOG_ERROR)
  • log  (LOG_INFO)
You can set the log level using the setLogLevel(int logLevel) API; to disable logs, it is sufficient to set LOG_NONE.

debug, error and log methods can accept two or three parameters:
  • a tag (String), to identify the component that it is logging and simplify the filter of the log output;
  • a message (String), with the useful information
  • an exception (Throwable) - opt parameter, this exception will be raised if the after a check among the message log level and the current log level.
In your application you can access log facilities using this syntax:"LoggApp", "Test message");

You can find more information here:


You can add this lines to the create() method of Logging class from the previous example (;"logging", "Debug level log");"logging", "Info level log");"logging", "Error level log");"logging", "Debug level log + exception", 
new Exception("debug level"));"logging", "Error level log + exception", 
new Exception("error level"));

Since the log level is info, debug messages will be ignored. Here you can see the output:

logging: Error level log
logging: Info level log
logging: Error level log + exception
java.lang.Exception: error level
  at com.blogspot.mytechpg.libgdx.test1.Logging.create(
  at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(
  at com.badlogic.gdx.backends.lwjgl.LwjglApplication$

As expected, the exception is generated with the error method.

To download the source code repo:
git clone -b dev

To select the correct release:
git checkout 19af8c7478e8671ac5ebe83a26790c419a9ab686

Logger class

This class uses the Application logging facilities and offers the same methods with a similar syntax.
It is possible configure the tag and the log level using the class constructor.

You can also use setLevel() method to configure the log level. If you use Application.setLogLevel() method you will override the value configured using Logger APIs.
debug, error and info methods accept one or two parameters:
  • a message (String)
  • an exception (Throwable) - opt parameter
You can find more information here:

No comments:

Post a Comment