Custom loggers
About the default logger (Android SDK)
The ForgeRock Android SDK does all of its logging through a custom interface called FRLogger
.
The default implementation of this interface logs the messages through the native Android
Log class.
This allows developers to see messages from the SDK in real time in the Logcat window in Android Studio.
There are 5 log severity levels defined in the Android SDK:
Log level | Description |
---|---|
|
Show debug log messages that are intended only for development, as well as the message levels lower in this list,
|
|
Show expected log messages for regular usage, as well as the message levels lower in this list, |
|
Show possible issues that are not yet errors, as well as the messages of |
|
Show issues that have caused errors. |
|
No log messages are shown. |
The log levels are cumulative.
If a lower severity level is selected, all messages related to higher severity levels are also included.
For example, if By default, the log level of the Android SDK is set to |
Customize the logger (Android SDK)
The ForgeRock Android SDK allows developers to customize the default logger behavior:
-
Create a class which implements the
FRLogger
interface:import androidx.annotation.Nullable; import org.forgerock.android.auth.FRLogger; public class MyCustomLogger implements FRLogger { @Override public void error(@Nullable String tag, @Nullable Throwable t, @Nullable String message, @Nullable Object... values) { /// Custom error message handling... } @Override public void error(@Nullable String tag, @Nullable String message, @Nullable Object... values) { /// Custom error message handling... } @Override public void warn(@Nullable String tag, @Nullable String message, @Nullable Object... values) { /// Custom warning message handling... } @Override public void warn(@Nullable String tag, @Nullable Throwable t, @Nullable String message, @Nullable Object... values) { /// Custom warning message handling... } @Override public void debug(@Nullable String tag, @Nullable String message, @Nullable Object... values) { /// Custom debug message handling... } @Override public void info(@Nullable String tag, @Nullable String message, @Nullable Object... values) { /// Custom info message handling... } @Override public void network(@Nullable String tag, @Nullable String message, @Nullable Object... values) { /// Custom network details handling... } @Override public boolean isNetworkEnabled() { return true; // include network call details in the logs } }
-
In your application, set the custom logger and desired log level:
Logger.setCustomLogger(new MyCustomLogger()); // The default logger will no longer be active Logger.set(Logger.Level.DEBUG);
-
You can now use the
Logger
interface in your app.For example:
String TAG = MainActivity.class.getSimpleName(); Logger.debug (TAG, "Happy logging!");
About the default logger (iOS SDK)
The ForgeRock SDK for iOS does all of its logging through a custom protocol called FRLogger
.
The default implementation of this protocol logs the messages through the native iOS
FRConsoleLogger class.
This allows developers to see messages from the SDK in real time in the Console window in Xcode.
Each log message has an associated log level that describes the type and the severity of the message. Log levels are helpful tool for tracking and analyzing events that take place in your app.
There are 7 log levels defined in the iOS SDK:
Log level | Description |
---|---|
|
Indicates that there is no log |
|
Indicates that the log entry is not important or can be ignored |
|
Indicates that the log entry maybe helpful, or meaningful for debugging, or understanding the flow |
|
Indicates the log entry of any network traffics, including request, and response |
|
Indicates the log entry of any minor issue or error that may occur which can be ignored |
|
Indicates the log entry of any severe issue, or major error that impacts SDK’s functionality or flow |
|
Indicates the log entry of all log levels |
The log levels are not cumulative.
That is, you should explicitly specify all the log levels you want to record.
For example, if By default, the log level of the ForgeRock SDK for iOS is set to |
Customize the logger (iOS SDK)
The ForgeRock SDK for iOS lets developers customize the default logger behavior:
-
Create a class which conforms to
FRLogger
protocol:class MyCustomLogger: FRLogger { func logVerbose(timePrefix: String, logPrefix: String, message: String) { /// Custom verbose message handling... } func logInfo(timePrefix: String, logPrefix: String, message: String) { /// Custom info message handling... } func logNetwork(timePrefix: String, logPrefix: String, message: String) { /// Custom network message handling... } func logWarning(timePrefix: String, logPrefix: String, message: String) { /// Custom warning message handling... } func logError(timePrefix: String, logPrefix: String, message: String) { /// Custom error message handling... } }
-
In your application, set the custom logger and desired log level:
FRLog.setCustomLogger(MyCustomLogger()) // The default logger will no longer be active FRLog.setLogLevel([.all])
-
You can now use the
FRLog
class in your app.For example:
FRLog.v("Happy logging!")