Offline Log

Last Updated on : 2024-06-17 08:36:00download

Set log interception

IPC SDK provides the API method that implements the output of custom logs. This helps you troubleshoot problems that might arise during the integration with the IPC SDK.

API description

By default, the system logs are printed in this method. During development and testing, you can get logs by using the console or the command adb logcat. However, after the app is launched, the retrieval of adb logs is difficult.

Therefore, Tuya provides this API method to output custom logs. You can set an interceptor to store and upload logs on top of your own log system.

public static void setLogInterception(int level, ILogInterception iLogInterception);

Parameters

Parameter Description
level The minimum level of the logs to be intercepted.
iLogInterception The log interceptor.

Log level

Log level Value
VERBOSE 2
DEBUG 3
INFO 4
WARN 5
ERROR 6

Example

L.setLogInterception(2, new ILogInterception() {
@Override
public void log(int i, String tag, String msg) {
        // Use your own log system to store and upload logs.
        }
        });

Get local offline logs

IPC SDK provides the component to implement the output of SDK running logs. This helps you troubleshoot problems that arise during the integration with the IPC SDK. You only need to integrate the log library into your project to get the local encrypted logs. In the case of any problem, you can submit a ticket, so Tuya will help you trouble the problem based on the encrypted logs.

To integrate the log component into your project, perform the following steps:

  1. Add the following dependencies to the file build.gradle:

     // Offline log
    implementation 'com.thingclips.smart:thingsmart-logsdk:5.0.1'
    implementation 'com.thingclips.smart:thing-log-sdk:5.0.0'
    
    implementation 'com.thingclips.smart:thingsmart:5.0.0'
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.14.9'
    
  2. Initialize application.

        // (Default) Method 1: You do not need to set the file size and quantity. Apply the default settings: The size of a single log file is up to 60 MB. Up to 3 log files are supported.
        TLogSDK.init(this);
    
         /* Method 2:
         * The size of a single log file is up to 10 MB. Up to 5 log files are supported for the same type.
         * If the upper limit of log file quantity is reached, when a new log file is created, the earliest log file will be deleted.
         */
        TLogSDK.init(application, 10, 5);
    
  3. Get local offline logs.

    TLogSDK.fetchLogs(getApplicationContext(), new LogFileCallback() {
    
    @Override
    public void onSuccess(ArrayList<String> logPaths) {
        // The local path of the logs.
    }
    
    @Override
    public void onFail(String errorMsg) {
    
    }
    });
    

    To ensure app information security, the offline log files are encrypted and cannot be viewed without decryption. To view the offline logs, export the log files and submit a ticket to request support.