Skip to content

Log Configuration

Log Initialization Configuration

    //Enable logger
    FTLoggerConfig *loggerConfig = [[FTLoggerConfig alloc]init];
    loggerConfig.enableCustomLog = YES;
    loggerConfig.enableLinkRumData = YES;
    loggerConfig.logLevelFilter = @[@(FTStatusError),@(FTStatusCritical)];
    loggerConfig.discardType = FTDiscardOldest;
    [[FTMobileAgent sharedInstance] startLoggerWithConfigOptions:loggerConfig];
    let loggerConfig = FTLoggerConfig()
    loggerConfig.enableCustomLog = true
    loggerConfig.enableLinkRumData = true
    loggerConfig.logLevelFilter = [NSNumber(value: FTLogStatus.statusError.rawValue),NSNumber(value: FTLogStatus.statusCritical.rawValue)] // loggerConfig.logLevelFilter = [2,3]
    loggerConfig.discardType = .discardOldest
    FTMobileAgent.sharedInstance().startLogger(withConfigOptions: loggerConfig)
Property Type Required Description
samplerate int No Sampling rate. Value range [0,100], 0 means no collection, 100 means full collection, default is 100
enableCustomLog BOOL No Whether to upload custom logs. Default NO
printCustomLogToConsole BOOL No Sets whether to output custom logs to the console. Default NO, custom log output format
logLevelFilter NSArray No Sets level log filtering, not set by default. Example: 1. To collect logs of level Info and Error, set to @[@(FTStatusInfo),@(FTStatusError)] or @[@0,@1]; 2. To collect logs including custom levels, such as collecting "customLevel" and Error, set to @[@"customLevel",@(FTStatusError)]. SDK version 1.5.16 and above supports filtering custom levels
enableLinkRumData BOOL No Whether to associate with RUM data. Default NO
globalContext NSDictionary No Adds custom tags to logs. Addition rules please refer to here
logCacheLimitCount int No Local cache maximum log entry count limit [1000,), larger logs represent greater disk cache pressure, default 5000
discardType FTLogCacheDiscard No Sets the log discard rule after reaching the limit. Default FTDiscard. FTDiscard discards appended data when log data count exceeds the maximum (5000); FTDiscardOldest discards old data when log data exceeds the maximum

Logger Log Printing

When initializing the SDK Log configuration, configure enableCustomLog to allow adding custom logs.

Currently, log content is limited to 30 KB, characters exceeding this limit will be truncated.

Usage

//
//  FTLogger.h
//  FTMobileSDK

/// Add custom log of info level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
-(void)info:(NSString *)content property:(nullable NSDictionary *)property;

/// Add custom log of warning level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
-(void)warning:(NSString *)content property:(nullable NSDictionary *)property;

/// Add custom log of error level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
-(void)error:(NSString *)content  property:(nullable NSDictionary *)property;

/// Add custom log of critical level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
-(void)critical:(NSString *)content property:(nullable NSDictionary *)property;

/// Add custom log of ok level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
-(void)ok:(NSString *)content property:(nullable NSDictionary *)property;

/// Add custom log
/// - Parameters:
///   - content: Log content
///   - status: Log status level
///   - property: Custom properties (optional)
- (void)log:(NSString *)content status:(NSString *)status property:(nullable NSDictionary *)property;
open class FTLogger : NSObject, FTLoggerProtocol {}
public protocol FTLoggerProtocol : NSObjectProtocol {
/// Add custom log of info level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
optional func info(_ content: String, property: [AnyHashable : Any]?)

/// Add custom log of warning level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
optional func warning(_ content: String, property: [AnyHashable : Any]?)

/// Add custom log of error level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
optional func error(_ content: String, property: [AnyHashable : Any]?)

/// Add custom log of critical level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
optional func critical(_ content: String, property: [AnyHashable : Any]?)

/// Add custom log of ok level
/// - Parameters:
///   - content: Log content
///   - property: Custom properties (optional)
optional func ok(_ content: String, property: [AnyHashable : Any]?)

/// Add custom log
/// - Parameters:
///   - content: Log content
///   - status: Log status level
///   - property: Custom properties (optional)
optional func log(_ content: String, status: String, property: [AnyHashable : Any]?)
}

Log Levels

///Event level and status, default: FTStatusInfo
typedef NS_ENUM(NSInteger, FTLogStatus) {
    /// Info
    FTStatusInfo         = 0,
    /// Warning
    FTStatusWarning,
    /// Error
    FTStatusError,
    /// Critical
    FTStatusCritical,
    /// Ok
    FTStatusOk,
};
///Event level and status, default: FTStatusInfo
public enum FTLogStatus : Int, @unchecked Sendable {
    /// Info
    case statusInfo = 0
    /// Warning
    case statusWarning = 1
    /// Error
    case statusError = 2
    /// Critical
    case statusCritical = 3
    /// Ok
    case statusOk = 4
}

Code Example

// Adding custom logs will fail if the SDK is not initialized successfully
[[FTLogger sharedInstance] info:@"test" property:@{@"custom_key":@"custom_value"}];
// Adding custom logs will fail if the SDK is not initialized successfully
FTLogger.shared().info("contentStr", property: ["custom_key":"custom_value"])

Output Custom Logs to Console

Set printCustomLogToConsole = YES to enable outputting custom logs to the console. You will see logs in the following format in the Xcode debug console:

2023-06-29 13:47:56.960021+0800 App[64731:44595791] [IOS APP] [INFO] content ,{K=V,...,Kn=Vn}

2023-06-29 13:47:56.960021+0800 App[64731:44595791]: Standard prefix for os_log output;

[IOS APP]: Prefix to distinguish SDK output custom logs;

[INFO]: Custom log level;

content: Custom log content;

{K=V,...,Kn=Vn}: Custom properties.