tencent cloud

Tencent Cloud Observability Platform

SDK Initialization

Download
Focus Mode
Font Size
Last updated: 2026-05-25 18:01:57
This article describes how to initialize the Terminal Performance Monitoring Pro (RUM Pro) log SDK.

Sample Code

Use the Builder pattern to configure and initialize the log system (TDLog) and diagnostic system (TDDiag). Set parameters such as log path, log level, size limits, and diagnostic configurations including AppId, environment, and adapters.
// Logger (optional)
TDLogConfig logConfig = new TDLogConfig.Builder(context)
.setLogPath(logPath) // Log output directory. Write permission must be obtained in advance.
.setLogLevel(LogLevel.DEBUG) // Default: VERBOSE
.setConsoleLog(true) // Default: true
.setMaxFileSize(byte) // Default: 50 MB
.setMaxAliveFileSize(byte) // Default: unlimited, minimum: 200
.setMaxAliveDay(day) // Default: 7 days, minimum: 1 day
.setPubKey(pubKey) // Public key for log encryption (optional). Contact the RUM Pro assistant to configure the key pair on the backend.
.build();
TDLog.initialize(context, logConfig);

// Diagnose
TDDiagConfig diagConfig = new TDDiagConfig.Builder()
.setAppId(appId) // [Important] App ID obtained from RUM Pro
.setAppKey(appKey) // [Important] App Key obtained from RUM Pro
.setEnvironment(TDDiagConfig.ENV_CLOUD) // [Important] Sets the environment. For Tencent Cloud, use TDDiagConfig.ENV_CLOUD.
.setLoggerAdapter(TDLog.getLogImpl()) // Integrate with your own log tools by implementing LoggerAdapter.
.setDeviceInfoAdapter(deviceInfoAdapter) // Inject privacy information as required by privacy compliance. Optional; defaults to reading from android.os.Build.
.setAppVersion("1.0.0") // Custom app version. Optional; defaults to reading from PackageInfo.
.setTrafficQuota(total, metered) // Sets daily traffic quota. Optional; unlimited by default. Recommended to set.
.setUploadCountLimit(limit, period, timeUnit) // Sets automatic reporting frequency limit. Optional; unlimited by default. Recommended to set.
.setImportantLabels(...label) // Sets an allowlist of tags that are exempt from TrafficQuota and UploadCountLimit.
.build();
TDDiag.initialize(context, config);
After initialization is complete, you can start logging.
TDLog.i("tag", "xxxxxx");
TDLog.e("tag", "xxxxxx", e);
For more usage of TDLog and TDDiag, see the API Description.

Setting the Device Unique ID

In the Android log SDK, userId is used as an identifier for log retrieval and coloring (named userId for historical reasons). It is recommended to use a unique device ID. You can call this method to set the userId synchronously after initialization or asynchronously after the app obtains the unique identifier.
TDDiag.setUserId("uid");


Help and Support

Was this page helpful?

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

Feedback