Skip to content

Log Configuration

Log Initialization Configuration

FTSdk.initLogWithConfig(new FTLoggerConfig()
    //.setEnableConsoleLog(true, "log prefix")
    .setEnableLinkRumData(true)
    .setEnableCustomLog(true)
    .setEnableWebViewLog(true)
    //.setLogLevelFilters(new Status[]{Status.CRITICAL, Status.ERROR})
    .setSamplingRate(0.8f));
FTSdk.initLogWithConfig(
    FTLoggerConfig()
        //.setEnableConsoleLog(true, "log prefix")
        .setEnableLinkRumData(true)
        .setEnableCustomLog(true)
        .setEnableWebViewLog(true)
        //.setLogLevelFilters(arrayOf(Status.CRITICAL, Status.ERROR))
        .setSamplingRate(0.8f)
)
Method Type Required Description
setSamplingRate Float No Sets the sampling rate. Range [0,1]; 0 means no collection, 1 means full collection. Default value is 1
setEnableConsoleLog Boolean No Whether to report console logs. This configuration depends on ft-plugin. Default is false. Log level mapping: Log.v -> ok, Log.i -> info, Log.d -> debug, Log.e -> error, Log.w -> warning. prefix is a control prefix filter parameter; no filter is applied by default. Note: The volume of Android console logs can be large. To avoid impacting application performance and reduce unnecessary resource waste, it is recommended to use prefix to filter out valuable logs. Versions of ft-plugin above 1.3.5 support capturing logs printed by Log.println
setEnableWebViewLog Boolean No Whether to collect logs generated by the Browser SDK in WebView. Default is false. Supported in 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 is false
setEnableCustomLog Boolean No Whether to upload custom logs. Default is false
setLogLevelFilters Array No Sets log level filters. No filter by default
addGlobalContext Dictionary No Adds global log properties. See here for property addition rules
setLogCacheLimitCount Int No Maximum number of log entries in local cache. Range [1000,). Larger logs increase disk cache pressure. Default is 5000
setLogCacheDiscardStrategy LogCacheDiscard No Sets the discard strategy when the log cache limit is reached. Default is LogCacheDiscard.DISCARD. DISCARD discards newly appended data; DISCARD_OLDEST discards old data

Logger Log Output

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

The log content is currently limited to 30 KB. Characters exceeding this limit will be truncated.

Usage

/**
 * Stores a single log entry locally for synchronous upload
 *
 * @param content  Log content
 * @param status   Log level, enum Status
 * @param property Additional properties (optional)
 */
public void logBackground(String content, Status status, HashMap<String, Object> property)

/**
 * Stores a single log entry locally for synchronous upload
 *
 * @param content  Log content
 * @param status   Log level, String
 * @param property Additional properties (optional)
 */
public void logBackground(String content, String status, HashMap<String, Object> property)

/**
 * Stores multiple log entries locally for synchronous upload
 *
 * @param logDataList List of {@link LogData}
 */
public void logBackground(List<LogData> logDataList)
/**
 * Stores a single log entry locally for synchronous upload
 *
 * @param content  Log content
 * @param status   Log level
 * @param property Log properties (optional)
 */
fun logBackground(content: String, status: Status, property: HashMap<String, Any>)

/**
 * Stores a single log entry locally for synchronous upload
 *
 * @param content  Log content
 * @param status   Log level
 * @param property Log properties (optional)
 */
fun logBackground(content: String, status: String, property: HashMap<String, Any>)

/**
 * Stores multiple log entries locally for synchronous upload
 *
 * @param logDataList List of log data
 */
fun logBackground(logDataList: List<LogData>)

Log Levels

Method 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);

// Batch upload logs
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)

// Batch upload logs
FTLogger.getInstance().logBackground(mutableListOf(LogData("test", Status.INFO)))

Feedback

Is this page helpful?