SDL Java Suite has a built-in logging framework that is designed to make debugging easier. It provides many of the features common to other 3rd party logging frameworks for java and can be used by your own app as well. We recommend that your app's integration with SDL provide logging using this framework rather than any other 3rd party framework your app may be using or System.out.print
. This will consolidate all SDL related logs into a common format and to a common destination.
To make sure that log messages are displayed, you should enable the SDL Debug Tool:
DebugTool.enableDebugTool();
If you don't want the messages to be logged, you can disable the Debug Tool anytime:
DebugTool.disableDebugTool();
If you use SDL Debug Tool to log messages without enabling the DebugTool nothing wrong will happen. It will simply not display the log messages. This gives the develop control on whether the logs should be displayed or not.
The SDL debug tool can be used to log messages with different log levels. The log level defines how serious the log message is. This table summarizes when to use each log level:
Log Level | When to use |
---|---|
Info | Use this to post useful information to the log |
Warning | Use this when you suspect something shady is going on |
Error | Use this when bad stuff happens |
To log an info message:
DebugTool.logInfo(TAG, "info message goes here");
To log a warning message:
DebugTool.logWarning(TAG, "warning message goes here");
To log an error message:
DebugTool.logError(TAG, "error message goes here");
If you want to log error message with exception, you can add the exception as a second parameter to the logError
method:
DebugTool.logError(TAG, "error message goes here", new SdlException("Sdl connection failed", SdlExceptionCause.SDL_CONNECTION_FAILED));