tencent cloud

Tencent Cloud Observability Platform

API Description

Download
Focus Mode
Font Size
Last updated: 2026-05-25 18:01:58
This article describes the feature APIs of the Terminal Performance Monitoring Pro (RUM Pro) log SDK to facilitate flexible and in-depth integration.

Log Printing Module

The SDK's built-in log printing capability is based on the WeChat Mars-xlog solution. The public interfaces are defined in TDLoggingIMPProtocol (TDOS_Diagnose/Classes/LogReport/TDLoggingIMPProtocol.h), which includes features such as local log printing, log coloring, and log file retrieval. The usage is as follows:
// Header file
#import <TDOS_Diagnose/TDOSLoggerProxy.h>

// Initialization method:
@interface TDOSLogger : NSObject <TDLoggingIMPProtocol>

/// Initializes the log SDK based on the configuration.
/// @param config configuration
- (instancetype)initWithConfig:(TDOSLoggerConfig *)config;

@end

// TDOSLoggerConfig includes the following optional settings:

/// Log directory
@property (nonatomic, readonly) NSString *logPath;
/// Default log level. Default: RAFTLogLevel_Error
@property (nonatomic, readonly) RAFTLogLevel defaultLogLevel;
/// Encryption Key
@property (nonatomic, readonly) NSString *publicKey;
/// Whether to output logs to the console. Default: NO (disabled).
@property (nonatomic, assign) BOOL enableConsoleLog;
/// Log file name prefix (optional)
@property (nonatomic, copy) NSString *logFilePrefix;

For detailed capability descriptions, see the sections below.

Basic Capabilities

Includes printing logs, setting log levels, forcing log flush, and so on. Log levels follow the RAFT log definition, RAFTLogDef(Log/RAFTLogDef.h), which provides 7 levels.
RAFTLogLevelVerbose = 0,
RAFTLogLevelDebug = 1,
RAFTLogLevelInfo = 2,
RAFTLogLevelWarn = 3,
RAFTLogLevelError = 4,
RAFTLogLevelFatal = 5,
RAFTLogLevelNone = 6,
On this basis, TDOS_DiagnoseSDK provides 5 macro definitions in TDOSLoggerProxy for quick integration:
#define TDLogDebug(tag, format, ...)
#define TDLogInfo(tag, format, ...)
#define TDLogWarn(tag, format, ...)
#define TDLogError(tag, format, ...)
#define TDLogFatal(tag, format, ...)
The underlying APIs are as follows:
/// log printing API (without format string)
- (void)log:(RAFTLogLevel)level
tag:(NSString *)tag
file:(const char *)file
func:(const char *)func
line:(int)line
msg:(NSString *)msg;

/// log printing API (with format string)
- (void)log:(RAFTLogLevel)level
tag:(NSString *)tag
file:(const char *)file
func:(const char *)func
line:(int)line
format:(NSString *)format, ... __attribute__((format(__NSString__, 6, 7))) NS_REQUIRES_NIL_TERMINATION;

/// Checks if coloring is currently enabled.
- (BOOL)isColorState;

/// Resets the cloloring level.
- (void)resetColorLevel;

/// Sets the log level.
/// @param level Log level
- (void)setLogLevel:(RAFTLogLevel)level;

/// Sets the special level for printing log and the expiration time for the special level.
/// @param level Log level
/// @param endtime End time
- (void)setLogLevel:(RAFTLogLevel)level endTimestamp:(time_t)endtime;

/// Forces writes logs to file.
/// @param isSync Whether to write synchronously
- (void)flushLog:(BOOL)isSync;

Additional Log Settings

These include setting the maximum retention time for local logs (default: 10 days), setting the maximum total size of locally retained logs, setting console log output, and setting the timing for log persistence, and so on.
/// Sets the maximum log retention time.
/// @param time Unit: seconds. Default: 10 days (10 * 24 * 60 * 60)
- (void)setMaxLogAliveTime:(long)time;

/// Sets the total log file size. When exceeded, old logs are automatically cleaned up (minimum limit: 50 MB).
/// @param maxSize Total file size. Default: 0 (unlimited).
- (void)setMaxTotalLogFileSize:(int64_t)maxSize;

/// Sets console log output.
/// @param enabled Whether to enable
- (void)setConsoleLogEnabled:(BOOL)enabled;

Log Information Retrieval

Get a list of log files (grouped by hour) within a specified time range (including the size limit feature), the log folder path, and the log encryption public key.
/// Gets a list of log files (hourly printed).
/// @param startTime Start timestamp
/// @param endTime End timestamp
- (nullable NSArray<NSString *> *)getPeroidLogFilesWithStartTime:(NSTimeInterval)startTime
endTime:(NSTimeInterval)endTime;
/// Gets the log list, supporting limiting the maximum log size.
/// (Discards old files first when the size limit is exceeded).
///
/// @param startTime Start timestamp
/// @param endTime End timestamp
/// @param sizeLimit Maximum log package
- (nullable NSArray<NSString *> *)getPeroidLogFilesWithStartTime:(NSTimeInterval)startTime
endTime:(NSTimeInterval)endTime
sizeLimit:(unsigned long long)sizeLimit;

/// Gets the log folder path.
- (NSString *)getLogFolderPath;

/// Gets the log encryption public key.
- (nullable NSString *)getLogEncryptPublicKey;

Push-triggered Proactive Log Retrieval (Optional)

You can integrate your app's Push channel to trigger proactive log retrieval. Using your own push capability enables more timely log retrieval, reducing wait times.
Note:
Your push delivery capability needs to be integrated with the RUM Pro platform, or you can proactively trigger the corresponding command after creating a new query.
When the client receives a push command, it must proactively call the following API of TDOS_Diagnose SDK to request the log retrieval configuration promptly.
/// Proactively pulls the log retrieval command.
///
/// Call this when a push message is received.
- (void)requestLogConfigFromServer;

// Calling example:
#import <TDOS_Diagnose/TDOS_Diagnose.h>
[TDLogSDK.sharedInstance requestLogConfigFromServer];


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback