Dev Center
All
Agora.io Community
How can I set the log file?
Type: Integration issues    Platform: Android / iOS / macOS / Web / Windows   Last Updated: 2020/11/11 20:17:55

The Agora SDK provides API methods for you to generate an output log file that records all the log data of the SDK operation.

Native

The native platform includes Android, iOS, macOS, and Windows.

Set the log file

To ensure that the output log is complete, we recommend calling the setLogFile method to set the log file immediately after you create and initialize RtcEngine.

By default, the SDK outputs five log files, agorasdk.log, agorasdk_1.log, agorasdk_2.log, agorasdk_3.log, agorasdk_4.log, each with a default size of 1024 KB. These log files are encoded in UTF-8. The SDK writes the latest logs in agorasdk.log. When agorasdk.log is full, the SDK deletes the log file with the earliest modification time among the other four, renames agorasdk.log to the name of the deleted log file, and creates a new agorasdk.log to record latest logs.

The default output log file path for each platform is as follows:

  • Android: /storage/emulated/0/Android/data/<package name>/files/agorasdk.log
  • iOS: App Sandbox/Library/Caches/agorasdk.log
  • macOS: ~/Library/Logs/agorasdk.log
    • Sandbox enabled: App Sandbox/Library/Logs/agorasdk.log, such as /Users/<username>/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

You can change the directory for the log files by setting the filePath parameter when calling setLogFile.

Set the log output level

You can call the setLogFilter method to set the output lof level. Select a level, and all the logs in the levels preceding this level are generated.

  • DEBUG: Outputs all API logs. Set your log filter as DEBUG if you want to get the most complete log file.
  • INFO: Outputs logs of the CRITICAL, ERROR, WARNING, and INFO level. We recommend setting your log filter as this level.
  • WARNING: Outputs logs of the CRITICAL, ERROR, and WARNING level.
  • ERROR: Outputs logs of the CRITICAL and ERROR level.
  • CRITICAL: Outputs logs of the CRITICAL level.
  • OFF: Outputs no log.

Set the log file size

The Agora SDK has five log files, each with a default size of 1024 KB. Call the setLogFileSize method if you want to increase the size of each log file.

Sample code

// Java
// set log filter to debug
engine.setLogFilter(LOG_FILTER_DEBUG);

// get document path and save to sdcard
// get current timestamp to separate log files
String ts = new SimpleDateFormat("yyyyMMdd").format(new Date());
String filepath = "/sdcard/" + ts + ".log";
File file = new File(filepath);
engine.setLogFile(filepath);
// Objective-C
// set log filter to debug
[engine setLogFilter: AgoraLogFilterDebug];

// get document path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// get file path
// get current timestamp to separate log files
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"ddMMyyyyHHmm"];
NSDate *currentDate = [NSDate date];
NSString *dateString = [formatter stringFromDate:currentDate];
NSString *logFilePath = [NSString stringWithFormat:@"%@/%@.log", [paths objectAtIndex:0], dateString];
// set log file path
[engine setLogFile:logFilePath]
// C++
TCHAR szAppFolder[MAX_PATH] = { 0 };
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szAppFolder);
_tcscat(szAppFolder, _T("\\AppName\\"));

if (!PathFileExists(szAppFolder)){
    // create directory if not exists
    CreateDirectory(szAppFolder, NULL);
}

if (PathFileExists(szAppFolder)){
    // create file
    TCHAR szFile[MAX_PATH] = { 0 };
    SYSTEMTIME st = { 0 };
    GetLocalTime(&st);
    // Use timestamp to separate log files
    _stprintf_s(szFile, _T("%s%d%02d%02d_%02d%02d%02d.log"), szAppFolder, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
    HANDLE hFile = CreateFile(szFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
    if (INVALID_HANDLE_VALUE != hFile){
        CloseHandle(hFile);
        char logFullPath[MAX_PATH] = { 0 };
        ::WideCharToMultiByte(CP_UTF8, 0, szFile, -1, logFullPath, MAX_PATH, NULL, NULL);
        RtcEngineParameters rep(*engine);
        rep.setLogFile(logFullPath);
    }
}

Get the stack information

You can also get the stack information when crashes occur:

  • Android: Run the adb bugreport command
  • iOS: Xcode → window → Devices → Select a device → view device logs → View logs of a certain app at a certain time → Right click export log
  • macOS: ~/Library/Logs/DiagnosticReports/

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

API reference

Web

Enable or disable log upload

You can use the enableLogUpload method to upload logs on to the Agora Server, or call the disaleLogUpload method to stop the upload.

To ensure that the output log is complete, we recommend calling the enableLogUpload method to upload logs before initializing the Client object.

If you fail to join the channel, the logs are unavailable on the Agora Server.

Set the log output level

Call the setLogLevel method to set the log output level. Select a level, and you can see the logs in the preceding levels.

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

Sample code

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

API reference

score