Update to Logging in Android Applications

We just updated how logging is handled for Android applications due to some issue with how Android uses java.util.logging.Logger. As it turns out, Android has an issue where the standard Handler provided by Android does not post log messages with a Level set to a value less than Level.INFO. Since most of the engine logging is set to FINE or lower, there wasn’t a way to get the startup debug log messages to post, specifically the device OpenGL capabilities and supported configurations. This has now been fixed by replacing the standard Android Handler with a JME specific one.

The default Level setting for the logger is set to Level.INFO. This way the log is not filled with jme debug information by default. If you want to set the logger to post more debug information, place the following line in the constructor of MainActivity.java

[java]LogManager.getLogManager().getLogger("").setLevel(Level.ALL);[/java]

Obviously, by using Level.ALL, you will get all of the debug logging provided by the engine. If you use Level.FINE, you get a little less. Set as appropriate for what you want to display in the log.

If you want a little more control of the logger so that you only print the debug message during startup, you can override the onCreate method and change the logging Level before and after calling super.onCreate

[java]
@Override
public void onCreate(Bundle savedInstanceState) {
LogManager.getLogManager().getLogger("").setLevel(Level.ALL);
super.onCreate(savedInstanceState);
LogManager.getLogManager().getLogger("").setLevel(Level.INFO);
}
[/java]

When providing debug information in the forum, please add the line to increase the logging level before posting the log to the forum. This will provide useful device information to help others debug the issue.

While you can still change the logging level in simpleInitApp(), doing so will not display much of the startup and device configuration information for Android applications since simpleInitApp() is called well after this part of the startup sequence.

Lastly, we added a new protected method in AndroidHarness.java that allows users to override the log handler initialization. To use your own implementation of a Handler and/or Formatter, place the following method in MainActivity.java.

[java]
@Override
protected void initializeLogHandler() {
// provide your own log Handler and / or Formatter initialization
}
[/java]

4 Likes