Skip to main content

How can I set the log file?

The Agora SDK allows you to configure the output log file. All logs generated by the SDK are written to this file.

Native Platforms

Native platforms include Android, iOS, macOS, and Windows.

Set up log files

When you create and initialize an RtcEngine instance, use the mLogConfig parameter to set the log file.

Set log file path

By default, the SDK generates five log files for the SDK and five for API calls. All log files are encoded in UTF-8.

  • SDK log files: agorasdk.log, agorasdk.1.log, agorasdk.2.log, agorasdk.3.log, agorasdk.4.log
  • API call log files: agoraapi.log, agoraapi.1.log, agoraapi.2.log, agoraapi.3.log, agoraapi.4.log

The most recent logs are always written to agorasdk.log and agoraapi.log. When agorasdk.log is full, the SDK handles the log files as follows:

  1. Deletes agorasdk.4.log, if present.
  2. Renames agorasdk.3.log to agorasdk.4.log.
  3. Renames agorasdk.2.log to agorasdk.3.log.
  4. Renames agorasdk.1.log to agorasdk.2.log.
  5. Creates a new agorasdk.log.

The agoraapi.log file follows the same rules.

Default log file paths by platform

  • Android: /storage/emulated/0/Android/data/<package_name>/files/agorasdk.log
  • iOS: App Sandbox/Library/Caches/agorasdk.log
  • macOS:
    • Sandbox enabled: ~/Library/Containers/<App_Bundle_Identifier>/Data/Library/Logs/agorasdk.log
    • Sandbox disabled: ~/Library/Logs/agorasdk.log
  • Windows: C:\Users\<user_name>\AppData\Local\Agora\<process_name>\agorasdk.log
info

Agora recommends using the default log file storage path. If you need to change the path, make sure the specified path exists and is writable.

Set log output level

Use the level field in the mLogConfig parameter to set the log output level. You can choose from the following levels:

  • INFO (default): Logs at FATAL, ERROR, WARN, and INFO levels. Recommended.
  • WARN: Logs at FATAL, ERROR, and WARN levels.
  • ERROR: Logs at FATAL and ERROR levels.
  • FATAL: Logs only FATAL level.
  • NONE: No logs are recorded.

Set the log file size

By default, each SDK log file is 2,048 KB. The API call log file size is also 2,048 KB. To set a custom log file size, use the fileSizeInKB field in the mLogConfig parameter.

  • The size of each agorasdk.log file can be between 128 and 20,480 KB.
  • This setting applies only to agorasdk.log, not agoraapi.log.

Sample Code

RtcEngineConfig.LogConfig logConfig = new RtcEngineConfig.LogConfig();// Set log filter level to ERRORlogConfig.level = Constants.LogLevel.getValue(Constants.LogLevel.LOG_LEVEL_ERROR);// Set log file pathString ts = new SimpleDateFormat("yyyyMMdd").format(new Date());logConfig.filePath = "/sdcard/" + ts + ".log";// Set log file size to 2 MBlogConfig.fileSize = 2048;RtcEngineConfig config = new RtcEngineConfig();config.mAppId = getString(R.string.agora_app_id);config.mEventHandler = iRtcEngineEventHandler;config.mContext = context.getApplicationContext();config.mAreaCode = getAreaCode();config.mLogConfig = logConfig;mRtcEngine = RtcEngine.create(config);

API reference

Get the stack information

You can also get the stack information when crashes occur:

  • Android: Run the adb bugreport command
  • iOS:
    • Open Xcode and go to Window > Devices and Simulators.
    • Select the Devices tab and choose the device where the crash occurred.
    • Under Installed Apps, find the relevant app.
    • Click the Settings icon (gear button) below the app list.
    • Select Download Container.
    • Once downloaded, right-click the container file and choose Show Package Contents.
    • Navigate to AppData > Library > Caches to find the agorasdk.log file with stack information
  • macOS: ~/Library/Logs/DiagnosticReports/
  • Windows: You need to capture dump files

On Android and iOS, if you have integrated Bugly in your app, you can also use Bugly to get the stack information.

Web

Enable or disable log upload

Call enableLogUpload to upload Agora Web SDK logs to Agora servers, and call disaleLogUpload to stop the upload.

To ensure that the output log is complete, call enableLogUpload before creating the client object.

If you fail to join a channel, logs are unavailable on Agora servers.

Set the log output level

Call setLogLevel to set the log output level. When you select a level, you can see the logs in the preceding levels.

  • DEBUG: Outputs all logs.
  • INFO: Outputs logs in the INFO, WARNING and ERROR levels.
  • WARNING: Outputs logs in the WARNING and ERROR levels.
  • ERROR: Outputs logs in the ERROR level.
  • NONE: Outputs no log.

Sample code


_5
// Javascript
_5
// Enable log upload
_5
AgoraRTC.enableLogUpload();
_5
// Set the log output level as INFO
_5
AgoraRTC.setLogLevel(1);

API reference

vundefined