# Mini-Program Information Management

# 1. Log Initialization Configuration

Log management in the Android SDK is configured alongside initialization settings.

// Whether to enable logging; this has the highest priority for log control
public Builder setEnableLog(boolean enableLog);

// Whether to enable XLog console output; if false, logs are only persisted and not displayed in the console
// This configuration only takes effect after integrating the XLog SDK
public Builder setEnableXLogConsole(boolean enableXLogConsole);
    
// Set the log level; only logs above this level will take effect
public Builder setLogLevel(XLogLevel logLevel);

// Set the storage directory for log files; this configuration only takes effect after integrating the XLog SDK
public Builder setXLogDir(File xLogDir);

// Set the log file retention period (default is 10 days, minimum is 1 day); this configuration only takes effect after integrating the XLog SDK
// Expired log files will be removed within 1 to 2 minutes after the application starts, once the maximum retention period is exceeded
public Builder setLogMaxAliveSec(long logMaxAliveSec);

Example code:

FinAppConfig finAppConfig = new FinAppConfig.Builder()
        // Enable logging, default is false
        .setEnableLog(true)
        // Enable XLog SDK console output, default is true
        .setEnableXLogConsole(true)
        // Set log level, default is XLogLevel.LEVEL_NONE
        .setLogLevel(XLogLevel.LEVEL_VERBOSE)
        // Customize XLog SDK log file directory, default is /data/data/${packageName}/files/fino_log
        .setXLogDir(logDir)
        // Customize XLog SDK log file maximum retention time, minimum 1 day, default is 10 days
        .setLogMaxAliveSec(2 * 24 * 60 * 60)
        // Other configuration items omitted
        .build();
FinAppClient.INSTANCE.init(application, finAppConfig, callback);

# 2. Runtime Log Configuration Update

Starting from version 2.42.7, the SDK supports dynamically updating log-related configurations at runtime to enable scenarios like controlling log switches via server-side configurations for troubleshooting production issues.

/**
 * Update log-related configurations
 *
 * @param enableLog Whether to enable logging
 * @param enableXLogConsole Whether to output logs to the console when XLog SDK is integrated
 * @param logLevel Log level
 * @param logDir Log file storage location when XLog SDK is integrated
 * @param logMaxAliveSec Maximum retention time for log files when XLog SDK is integrated
 */
fun updateLogConfig(
    context: Context,
    enableLog: Boolean,
    enableXLogConsole: Boolean,
 logLevel: XLogLevel,
    logDir: File,
    logMaxAliveSec: Long
)

Code examples:

Main Process

    Mini-Program Process

      Note

      • When called in the main process, subsequently launched Mini-Programs will start with the updated log configuration, but currently running Mini-Programs will not be affected and require a cold restart.
      • When called in a Mini-Program process, the change takes effect immediately only for that specific Mini-Program process and does not affect the main process log configuration or subsequently launched Mini-Programs.

      # 3. Taking Over the SDK's Internal Logging System

      Create your own logging class and implement the IAppletLogDelegate interface, as shown below:

      class LogDelegate : IAppletLogDelegate {
      
          override fun logMessage(content: String) {
              val file = getLogFile()
              file.appendText("${content}\n")
          }
      }
      

      Set this logging delegate during SDK initialization:

       val finAppConfig = FinAppConfig.Builder()
      			// Other configuration items omitted
                  .setLogDelegate(LogDelegate::class.java)
                  .build()
      FinAppClient.init(application, finAppConfig, finCallback)
      

      When relevant log information is generated, the logMessage method will be called, with the parameter content containing the complete log details, including 【Log Time】, 【Log Level】, 【Log Tag】, and 【Log Details】.

      Note

      • Whether this class's logMessage method receives log content depends on the log level set via setLogLevel and the enableLog configuration.
      • Once this class is set, configuration items like setLogMaxAliveSec and setXLogDir will become ineffective. The SDK will no longer handle logs, and the client must manage them entirely.
      • An instance of this class will be created via reflection during SDK runtime, so it must contain exactly one parameterless constructor.
      • Instances of this class may run in different processes. Therefore, if temporary variables need to be recorded, do not store them directly within the class instance, and implement process-specific handling as necessary.

      # 4. Obtaining Performance Statistics Records from the SDK

      Create your own performance recording class and implement the IAppletPerformanceRecordDelegate interface, as shown below:

      class PerformanceRecordDelegate : IAppletPerformanceRecordDelegate {
      
          override fun appletReceivePerformanceRecords(
              appInfo: FinAppInfo,
              performance: Performance
          ) {
              val file = getLogFile()
              file.appendText("${Gson().toJson(performance)}\n")
          }
      }
      

      Set this performance recording delegate during SDK initialization:

       val finAppConfig = FinAppConfig.Builder()
      			// Other configuration items omitted
                  .setPerformanceRecordDelegate(PerformanceRecordDelegate::class.java)
                  .build()
      FinAppClient.init(application, finAppConfig, finCallback)
      

      When relevant performance records are generated, the appletReceivePerformanceRecords method will be called. The parameters include the Mini-Program information appInfo corresponding to this performance record and the detailed performance object.

      Note

      • An instance of this class will be created via reflection during SDK runtime, so it must contain exactly one parameterless constructor.
      • Instances of this class may run in different processes. Therefore, if temporary variables need to be recorded, do not store them directly within the class instance, and implement process-specific handling as necessary.

      Key fields explanation for performance statistics records:

      entryType Metric Type name Metric Name Description
      inner processLaunch Process startup time
      navigation appInfo Mini-Program details interface
      loadPackage downloadPackage Download Mini-Program (start)
      navigation frameworkInfo Base Library details interface; this log entry is absent if Base Library preloading is enabled
      loadPackage downloadFramework Download Base Library; this log entry is absent if Base Library preloading is enabled
      loadPackage unzipFramework Extract Base Library; this log entry is absent if Base Library preloading is enabled
      loadPackage downloadPackage Download Mini-Program (completion)
      loadPackage unzipApp Extract Mini-Program
      navigation appLaunch Total startup duration
      script frameworkLoad Base Library loading
      script evaluateScript Execute JavaScript code
      script serviceLoad Logic Layer execution time
      render frameworkRenderLoad View Layer Base Library loading time
      render viewRender View Layer execution time
      render firstRender View Layer Mini-Program loading time
      © FinClip with ❤ , Since 2017