object TDDiag {/*** Initialization.** @param context* @param config*/fun initialize(context: Context, config: TDDiagConfig)/*** Initialization.** @param context* @param config* @param host When multiple processes are initialized, this should be set to true for only one process. By default, this process is the main process and is used to pull configurations and upload logs.*/fun initialize(context: Context, config: TDDiagConfig, host: Boolean)/*** Configures userId.*/fun setUserId(id: String)/*** This is used to receive push requests.*/fun onPush(data: String)/*** Proactively reports logs.** @param label Tag. This is required and cannot exceed 64 bytes.* @param fileList List of file paths.* @param summary Summary. This cannot exceed 256 bytes and can be searched.* @param extraInfo Additional information.* @param listener UI callback.* @param saveSync Indicates whether to only synchronously save the task and upload data on the next startup.* @see upload*/@Deprecated("Use TDDiag.upload(param) instead")@JvmStaticfun uploadFiles(label: String,fileList: List<File>,summary: String? = null,extraInfo: String? = null,listener: UploadListener? = null,saveSync: Boolean = false)/*** Proactively reports logs.** @param label Tag. This is required and cannot exceed 64 bytes.* @param pathList List of file paths.* @param summary Summary. This cannot exceed 256 bytes and can be searched.* @param extraInfo Additional information.* @param listener UI callback.* @param saveSync Indicates whether to only synchronously save the task and upload data on the next startup.* @see upload*/@Deprecated("Use TDDiag.upload(param) instead")@JvmStaticfun uploadPaths(label: String,pathList: List<String>,summary: String? = null,extraInfo: String? = null,listener: UploadListener? = null,saveSync: Boolean = false)/*** Proactively reports logs.** @param label Tag. This is required and cannot exceed 64 bytes.* @param startTimestamp Starting timestamp (unit: seconds). This value is included.* @param endTimestamp Ending timestamp (unit: seconds). This value is not included.* @param extraPathList List of file paths.* @param summary Summary. This cannot exceed 256 bytes and can be searched.* @param extraInfo Additional information.* @param listener UI callback.* @param saveSync Indicates whether to only synchronously save the task and upload data on the next startup.* @param sizeLimit File size limit (before compression). This is effective when the value is less than the [limits](README.md). No limit is applied by default.* @see upload*/@Deprecated("Use TDDiag.upload(param) instead")@JvmStaticfun uploadLogs(label: String,startTimestamp: Long,endTimestamp: Long,extraPathList: List<String>? = null,summary: String? = null,extraInfo: String? = null,listener: UploadListener? = null,saveSync: Boolean = false,sizeLimit: Long = Long.MAX_VALUE)/*** Proactively reports logs.*/@JvmStaticfun upload(param: UploadParam)/*** Proactively refreshes the configuration.** @param force Indicates whether to force refresh without checking the pull interval.*/fun syncConfig(force: Boolean = false): Boolean}
class TDDiagConfig.Builder {/*** Configures the appId applied on the [TDS - Debugging and Diagnostics Platform](https://diagnose.woa.com/).*/fun setAppId(appId: String): Builder/*** Configures the appKey applied on the [TDS - Debugging and Diagnostics Platform](https://diagnose.woa.com/).*/fun setAppKey(appKey: String): Builder/*** Configures LoggerAdapter for the logging module.*/fun setLoggerAdapter(loggerAdapter: LoggerAdapter): Builder/*** Inject compliant privacy information (optional; this information is read from android.os.Build by default).*/fun setDeviceInfoAdapter(deviceInfoAdapter: DeviceInfoAdapter): Builder/*** Custom app version (optional; this information is read from PackageInfo by default).*/fun setAppVersion(appVersion: String): Builder/*** Configures the tag allowlist.*/fun setImportantLabels(vararg labels: String): Builder/*** Configures the daily traffic quota (optional; unlimited by default).** @param total Total traffic (unit: bytes). The value must be greater than or equal to [metered].* @param metered 4G traffic (unit: bytes). The value must be greater than 0.*/fun setTrafficQuota(total: Long, metered: Long): Builder/*** Configures the automatic reporting frequency limit (optional; unlimited by default).** @param limit Frequency limit.* @param period Period.* @param timeUnit Period unit.*/fun setUploadCountLimit(limit: Long, period: Long, timeUnit: TimeUnit): Builder/*** Configures the environment (optional).** @param env Default value: [TDDiagConfig.ENV_NORMAL]. Value for global edition: [TDDiagConfig.ENV_OVERSEAS].*/fun setEnvironment(env: String): Builder/*** Generates [TDDiagConfig].*/fun build(): TDDiagConfig}
/*** Proactive upload parameter class.*/class UploadParam {/*** @param label Tag. This is required and cannot exceed 64 bytes.*/constructor(label: String)/*** Configures the log range.** @param startTimestamp Starting timestamp (unit: seconds). This value is included.* @param endTimestamp Ending timestamp (unit: seconds). This value is not included.*/fun setTimestamp(startTimestamp: Long, endTimestamp: Long): UploadParam/*** Configures the list of attached files (or folders).*/fun setExtraPaths(pathList: List<String>): UploadParam/*** Configures the list of attached files (or folders).*/fun setExtraFiles(fileList: List<File>): UploadParam/*** Configures additional information.** @param summary Summary. This cannot exceed 256 bytes and can be searched.* @param extraInfo Additional information.*/fun setExtraInfo(summary: String?, extraInfo: String?): UploadParam/*** Configures the UI callback.** @param listener UI callback.* @param disableAsyncRetry Indicates whether to disable retry. The default value is false. Set it to true to customize the retry method at the upper layer.*/fun setListener(listener: UploadListener?, disableAsyncRetry: Boolean): UploadParam/*** Configures whether to only synchronously save the task and upload data on the next startup.*/fun setSaveSync(saveSync: Boolean = true): UploadParam/*** Configures the file size limit (before compression). This is effective when the value is less than the [limits](README.md).*/fun setSizeLimit(sizeLimit: Long): UploadParam/*** Configures whether to collect log cache files. Cache files are not collected by default.*/fun setIncludeCache(includeCache: Boolean = true): UploadParam/*** Additional search information for platform interoperability (cross-system search).** @param queryKey Key used to search logs. The value cannot exceed 128 bytes.* @param source Caller source. The value cannot exceed 128 bytes.*/fun appendExtQueryInfo(queryKey: String, source: String): UploadParam}
/*** Log component adapter API.*/public interface LoggerAdapter {/*** Configures the color level.*/void setColorLevel(@LogLevel int level);/*** Obtains the log files.** @param startTimestamp Starting timestamp (unit: seconds). This value is included.* @param endTimestamp Ending timestamp (unit: seconds). This value is not included.* @return List of log files.*/@NullableList<File> getLogFiles(long startTimestamp, long endTimestamp);/*** Obtains the log files.** @param startTimestamp Starting timestamp (unit: seconds). This value is included.* @param endTimestamp Ending timestamp (unit: seconds). This value is not included.* @param includeCache Indicates whether to collect cache files.* @return List of log files.*/@Nullabledefault List<File> getLogFiles(long startTimestamp, long endTimestamp, boolean includeCache) {return getLogFiles(startTimestamp, endTimestamp);}/*** Forces to write logs to files.*/void flushLog();/*** Prints the SDK logs.*/void printDiagnoseLog(@NotNull String tag, @NotNull String msg, @Nullable Throwable tr);/*** Obtains the log encryption public key (optional; the default value is null, which indicates that encryption is not enabled).*/@Nullabledefault String getPubKey() {return null;}}
/*** Privacy information adapter API.*/interface DeviceInfoAdapter {/*** {@link android.os.Build#BRAND}*/fun getBrand(): String/*** {@link android.os.Build#MODEL}*/fun getModel(): String}
interface UploadListener {/*** Upload starts.*/fun onStart()/*** Progress updates. This callback may trigger 0 or multiple times.** @param percent 0–100.*/fun onProgress(percent: Int)/*** Upload succeeds.*/fun onSuccess()/*** Upload fails.** @param reason Failure reason:* * -4: Local restriction policy, including frequency limit, traffic limit, and circuit breaker.* * -3: Failure to synchronize the upload URL to the backend, usually due to network fluctuations.* * -2: Tag sampling limit configured on the console.* * -1: Repetitive task.* * 1: File upload network error.* * 2: Compressed log file size exceeds the threshold.* * 3: Compression IO error, usually due to insufficient storage.* * 4: During file upload, the Cloud Object Storage (COS) backend returns an HTTP error.* * 5: No local logs.*/fun onFailure(@UploadLogFailReasonType reason: Int)
public class TDLog {/*** Initialization.*/public static void initialize(Context context, TDLogConfig config)/*** Creates a sub-instance.*/public static ILogInstance getSubInstance(String category, boolean consoleLog, int maxAliveDay, long maxAliveFileSize)/*** Obtains the default {@link LoggerAdapter} instance.*/public static ITDLog getLogImpl()/*** Prints {@link LogLevel#VERBOSE} logs.*/public static void v(String tag, String message)/*** Prints {@link LogLevel#VERBOSE} logs.*/public static void v(String tag, String message, Throwable throwable)/*** Prints {@link LogLevel#DEBUG} logs.*/public static void d(String tag, String message)/*** Prints {@link LogLevel#DEBUG} logs.*/public static void d(String tag, String message, Throwable throwable)/*** Prints {@link LogLevel#INFO} logs.*/public static void i(String tag, String message)/*** Prints {@link LogLevel#INFO} logs.*/public static void i(String tag, String message, Throwable throwable)/*** Prints {@link LogLevel#WARN} logs.*/public static void w(String tag, String message)/*** Prints {@link LogLevel#WARN} logs.*/public static void w(String tag, String message, Throwable throwable)/*** Prints {@link LogLevel#ERROR} logs.*/public static void e(String tag, String message)/*** Prints {@link LogLevel#ERROR} logs.*/public static void e(String tag, String message, Throwable throwable)/*** Prints {@link TDLogInfo} logs.*/public static void log(TDLogInfo info)/*** Forces to write buffer logs to files.*/public static void flushLog()/*** Closes the log instance.*/public static void closeLog()}
/*** Log component configuration builder.*/public static class TDLogConfig.Build {/*** constructor*/public Builder(Context context)/*** Configures the lowest log level.*/public Builder setLogLevel(@LogLevel int logLevel)/*** Configures whether to output to Logcat.*/public Builder setConsoleLog(boolean consoleLog)/*** Configures the log file storage path.*/public Builder setLogPath(String logPath)/*** Configures the public key for log file encryption.*/public Builder setPubKey(String key)/*** Configures the maximum size of a single log file.*/public Builder setMaxFileSize(long maxFileSize)/*** Configures the retention days for log files.*/public Builder setMaxAliveDay(int maxAliveDay)/*** Configures the maximum total size of log files.*/public Builder setMaxAliveFileSize(long maxAliveFileSize)/*** Creates a {@link TDLogConfig} instance.*/public TDLogConfig build()}
public class TDLogInfo {/*** Tag*/public String tag;/*** Secondary tag.*/public String subTag;/*** Tertiary tag.*/public String thirdTag;/*** Log level.*/@LogLevelpublic int level;/*** Thread ID.*/public long tid;/*** Thread name.*/public String tName;/*** Log content.*/public String message;/*** Throwable object.*/public Throwable throwable;/*** Time, in milliseconds. The default value is 0, which indicates unspecified.*/public long timeMillis;}
/*** Log instance API.*/public interface ILogInstance {/*** Prints logs.*/void log(String tag, @LogLevel int level, String message, @Nullable Throwable throwable);/*** Prints logs with custom information.*/void log(TDLogInfo info);/*** Forces to write logs to files.*/void flushLog();/*** Closes the current log instance.*/void closeLog();}
TDDiag.onPush("{}");
TDDiag.syncConfig(false); // False indicates a non-forced refresh.
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback