Skip to content

Log Configuration

Sampling field migration (ft-sdk >= 1.7.6): setLogSamplingRate uses a floating-point percentage from 0 to 100; the old setSamplingRate keeps the 0–1 unit. When migrating, multiply the value by 100. The new field takes precedence only when explicitly set; invalid values throw an exception and do not change the previous valid value. Versions below this one continue to use the old method; deprecation does not mean removal, and the old method retains its original unit and behavior.

Log Initialization Configuration

FTSdk.initLogWithConfig(new FTLoggerConfig()
    //.setEnableConsoleLog(true, "log prefix")
    .setEnableLinkRumData(true)
    .setEnableCustomLog(true)
    .setEnableWebViewLog(true)
    //.setLogLevelFilters(new Status[]{Status.CRITICAL, Status.ERROR})
    .setLogSamplingRate(80f));
FTSdk.initLogWithConfig(
    FTLoggerConfig()
        //.setEnableConsoleLog(true, "log prefix")
        .setEnableLinkRumData(true)
        .setEnableCustomLog(true)
        .setEnableWebViewLog(true)
        //.setLogLevelFilters(arrayOf(Status.CRITICAL, Status.ERROR))
        .setLogSamplingRate(80f)
)
Method Name Type Required Description
setLogSamplingRate Float No Sampling percentage, range [0,100], default 100; decimals are supported. For example, 0.1 means 0.1%. 0 means no collection, and 100 means full collection. Once the new field is explicitly set, it takes precedence over the old field regardless of the setting order. Supported by ft-sdk >= 1.7.6.
setSamplingRate Float No Deprecated since ft-sdk 1.7.6, retained for compatibility. Sets the sampling rate, value range [0,1]; 0 means no collection, 1 means full collection, default 1.
setEnableConsoleLog Boolean No Whether to report console logs. This configuration depends on ft-plugin, default false. The log level mapping is: Log.v -> ok, Log.i -> info, Log.d -> debug, Log.e -> error, Log.w -> warning. prefix is a console prefix filtering parameter; no filtering is set by default. Note: Android console log volume can be very large. To avoid impacting app performance and reduce unnecessary resource waste, it is recommended to use prefix to filter out valuable logs. ft-plugin 1.3.5 and above supports capturing logs printed with Log.println.
setEnableWebViewLog Boolean No Whether to collect logs generated by the Browser SDK in WebView. Default false, supported by ft-sdk 1.7.5 and above. This configuration is independent of setEnableCustomLog and setEnableConsoleLog. For integration, refer to WebView Log Collection.
setEnableLinkRumData Boolean No Whether to associate with RUM data. Default false.
setEnableCustomLog Boolean No Whether to upload custom logs. Default false.
setLogLevelFilters Array No Set log level filtering; not set by default.
addGlobalContext Dictionary No Add global log attributes. For adding rules, refer to here.
setLogCacheLimitCount Int No Maximum number of log entries in the local cache, range [1000,). The more logs, the greater the disk cache pressure. Default 5000.
setLogCacheDiscardStrategy LogCacheDiscard No Sets the log discard rule after logs reach the upper limit. Default LogCacheDiscard.DISCARD; DISCARD discards newly appended data, and DISCARD_OLDEST discards old data.

Logger Log Output

To output custom logs using FTLogger, you need to enable FTLoggerConfig.setEnableCustomLog(true).

Currently, the log content is limited to 30 KB; characters beyond the limit are truncated.

Usage

/**
 * Store a single log entry to local storage synchronously.
 *
 * @param content  Log content
 * @param status   Log level, enum Status
 * @param property Additional attributes (optional)
 */
public void logBackground(String content, Status status, HashMap<String, Object> property)

/**
 * Store a single log entry to local storage synchronously.
 *
 * @param content  Log content
 * @param status   Log level, String
 * @param property Additional attributes (optional)
 */
public void logBackground(String content, String status, HashMap<String, Object> property)

/**
 * Store multiple log entries to local storage synchronously.
 *
 * @param logDataList {@link LogData} list
 */
public void logBackground(List<LogData> logDataList)
/**
 * Store a single log entry to local storage synchronously.
 *
 * @param content  Log content
 * @param status   Log level
 * @param property Log attributes (optional)
 */
fun logBackground(content: String, status: Status, property: HashMap<String, Any>)

/**
 * Store a single log entry to local storage synchronously.
 *
 * @param content  Log content
 * @param status   Log level
 * @param property Log attributes (optional)
 */
fun logBackground(content: String, status: String, property: HashMap<String, Any>)

/**
 * Store multiple log entries to local storage synchronously.
 *
 * @param logDataList Log data list
 */
fun logBackground(logDataList: List<LogData>)

Log Levels

Method Name Description
Status.DEBUG Debug
Status.INFO Info
Status.WARNING Warning
Status.ERROR Error
Status.CRITICAL Critical
Status.OK Recovered

Code Example

// Upload a single log
FTLogger.getInstance().logBackground("test", Status.INFO);

// Pass parameters to HashMap
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
FTLogger.getInstance().logBackground("test", Status.INFO, map);

// Upload logs in batch
List<LogData> logList = new ArrayList<>();
logList.add(new LogData("test", Status.INFO));
FTLogger.getInstance().logBackground(logList);
// Upload a single log
FTLogger.getInstance().logBackground("test", Status.INFO)

// Pass parameters to HashMap
val map = HashMap<String, Any>()
map["ft_key"] = "ft_value"
FTLogger.getInstance().logBackground("test", Status.INFO, map)

// Upload logs in batch
FTLogger.getInstance().logBackground(mutableListOf(LogData("test", Status.INFO)))

Feedback

Is this page helpful?