Skip to content

Log Configuration

Log Initialization Configuration

FTLoggerConfig *loggerConfig = [[FTLoggerConfig alloc] init];
loggerConfig.enableCustomLog = YES;
loggerConfig.printCustomLogToConsole = YES;
loggerConfig.enableLinkRumData = YES;
loggerConfig.logLevelFilter = @[@(FTStatusError), @(FTStatusCritical)];
loggerConfig.discardType = FTDiscardOldest;
[[FTSDKAgent sharedInstance] startLoggerWithConfigOptions:loggerConfig];
let loggerConfig = FTLoggerConfig()
loggerConfig.enableCustomLog = true
loggerConfig.enableLinkRumData = true
loggerConfig.printCustomLogToConsole = true
loggerConfig.logLevelFilter = [NSNumber(value: FTLogStatus.statusError.rawValue), NSNumber(value: FTLogStatus.statusCritical.rawValue)]
loggerConfig.discardType = .discardOldest
FTSDKAgent.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 value 100
enableCustomLog BOOL No Whether to upload custom Log, default NO
logLevelFilter NSArray No Set the array of custom Log statuses to collect, default collects all
enableLinkRumData BOOL No Whether to associate with RUM data, default NO
discardType FTLogCacheDiscard No Set the log discard rule after the log limit is reached, default FTDiscard
printCustomLogToConsole BOOL No Set whether to output custom logs to the console, default NO
globalContext NSDictionary No Add custom tags for Log, for addition rules please refer to Custom Tag Usage

Logger Log Printing

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

Usage

/// Add custom log of info type
-(void)info:(NSString *)content property:(nullable NSDictionary *)property;

/// Add custom log of warning type
-(void)warning:(NSString *)content property:(nullable NSDictionary *)property;

/// Add custom log of error type
-(void)error:(NSString *)content property:(nullable NSDictionary *)property;

/// Add custom log of critical type
-(void)critical:(NSString *)content property:(nullable NSDictionary *)property;

/// Add custom log of ok type
-(void)ok:(NSString *)content property:(nullable NSDictionary *)property;
open class FTLogger : NSObject, FTLoggerProtocol {}
public protocol FTLoggerProtocol : NSObjectProtocol {
    optional func info(_ content: String, property: [AnyHashable : Any]?)
    optional func warning(_ content: String, property: [AnyHashable : Any]?)
    optional func error(_ content: String, property: [AnyHashable : Any]?)
    optional func critical(_ content: String, property: [AnyHashable : Any]?)
    optional func ok(_ content: String, property: [AnyHashable : Any]?)
}

Log Levels

typedef NS_ENUM(NSInteger, FTLogStatus) {
    FTStatusInfo = 0,
    FTStatusWarning,
    FTStatusError,
    FTStatusCritical,
    FTStatusOk,
};
public enum FTLogStatus : Int, @unchecked Sendable {
    case statusInfo = 0
    case statusWarning = 1
    case statusError = 2
    case statusCritical = 3
    case statusOk = 4
}

Code Examples

// Method 1: Via FTSDKAgent
// Note: Ensure the SDK is successfully initialized before use, otherwise it will cause an assertion failure and crash in the test environment.
[[FTSDKAgent sharedInstance] logging:@"test_custom" status:FTStatusInfo];

// Method 2: Via FTLogger (Recommended)
// If the SDK is not successfully initialized, calling methods in FTLogger to add custom logs will fail, but there will be no assertion failure crash issue.
[[FTLogger sharedInstance] info:@"test" property:@{@"custom_key":@"custom_value"}];
// Method 1: Via FTSDKAgent
FTSDKAgent.sharedInstance().logging("contentStr", status: .statusInfo, property: ["custom_key":"custom_value"])

// Method 2: Via FTLogger (Recommended)
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] [MACOS APP] [INFO] content ,{K=V,...,Kn=Vn}
  • 2023-06-29 13:47:56.960021+0800 App[64731:44595791]: Standard prefix for os_log log output
  • [MACOS APP]: Prefix used to distinguish SDK output custom logs
  • [INFO]: Custom log level
  • content: Custom log content
  • {K=V,...,Kn=Vn}: Custom properties