ForgeRock SDKs

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

DEBUG

Show debug log messages that are intended only for development, as well as the message levels lower in this list, INFO, WARN, and ERROR. In addition, all network activities of the SDK are included in the logs.

INFO

Show expected log messages for regular usage, as well as the message levels lower in this list, WARN, and ERROR.

WARN

Show possible issues that are not yet errors, as well as the messages of ERROR log level.

ERROR

Show issues that have caused errors.

NONE

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 DEBUG level is selected, the log will include all events logged at DEBUG, INFO, WARN, and ERROR levels.

By default, the log level of the Android SDK is set to Logger.Level.WARN.

Customize the logger (Android SDK)

The ForgeRock Android SDK allows developers to customize the default logger behavior:

  1. 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
        }
    }
  2. 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);
  3. 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

none

Indicates that there is no log

verbose

Indicates that the log entry is not important or can be ignored

info

Indicates that the log entry maybe helpful, or meaningful for debugging, or understanding the flow

network

Indicates the log entry of any network traffics, including request, and response

warning

Indicates the log entry of any minor issue or error that may occur which can be ignored

error

Indicates the log entry of any severe issue, or major error that impacts SDK’s functionality or flow

all

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 debug level is selected, the log will only include events logged at debug level. To include other levels, you must specify an array of desired log levels.

By default, the log level of the ForgeRock SDK for iOS is set to LogLevel.none.

Customize the logger (iOS SDK)

The ForgeRock SDK for iOS lets developers customize the default logger behavior:

  1. 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...
        }
    }
  2. 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])
  3. You can now use the FRLog class in your app.

    For example:

    FRLog.v("Happy logging!")
Copyright © 2010-2023 ForgeRock, all rights reserved.