Skip to main content

How can I set the log file?

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

Before v3.3.0

Set the log file path

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:
    • Sandbox enabled: App Sandbox/Library/Logs/agorasdk.log, such as /Users/<username>/Library/Containers/<App Bundle Identifier>/Data/Library/Logs/agorasdk.log
    • Sandbox disabled: /Users/<username>/Library/Caches/<App Bundle Identifier>/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.

Note

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

Set the log output level

You can call the setLogFilter method to set the output log 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


_10
// Java
_10
// Set the log filter to debug
_10
engine.setLogFilter(LOG_FILTER_DEBUG);
_10
_10
// Get the document path and save to sdcard
_10
// Get the current timestamp to separate log files
_10
String ts = new SimpleDateFormat("yyyyMMdd").format(new Date());
_10
String filepath = "/sdcard/" + ts + ".log";
_10
File file = new File(filepath);
_10
engine.setLogFile(filepath);


_15
// Objective-C
_15
// Set the log filter to debug
_15
[engine setLogFilter: AgoraLogFilterDebug];
_15
_15
// Get the document path
_15
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
_15
// Get the file path
_15
// Get the current timestamp to separate log files
_15
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
_15
[formatter setDateFormat:@"ddMMyyyyHHmm"];
_15
NSDate *currentDate = [NSDate date];
_15
NSString *dateString = [formatter stringFromDate:currentDate];
_15
NSString *logFilePath = [NSString stringWithFormat:@"%@/%@.log", [paths objectAtIndex:0], dateString];
_15
// Set the log file path
_15
[engine setLogFile:logFilePath]


_26
// C++
_26
TCHAR szAppFolder[MAX_PATH] = { 0 };
_26
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szAppFolder);
_26
_tcscat(szAppFolder, _T("\\AppName\\"));
_26
_26
if (!PathFileExists(szAppFolder)){
_26
// Create a directory if it does not exist
_26
CreateDirectory(szAppFolder, NULL);
_26
}
_26
_26
if (PathFileExists(szAppFolder)){
_26
// Create a file
_26
TCHAR szFile[MAX_PATH] = { 0 };
_26
SYSTEMTIME st = { 0 };
_26
GetLocalTime(&st);
_26
// Use the timestamp to separate log files
_26
_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);
_26
HANDLE hFile = CreateFile(szFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
_26
if (INVALID_HANDLE_VALUE != hFile){
_26
CloseHandle(hFile);
_26
char logFullPath[MAX_PATH] = { 0 };
_26
::WideCharToMultiByte(CP_UTF8, 0, szFile, -1, logFullPath, MAX_PATH, NULL, NULL);
_26
RtcEngineParameters rep(*engine);
_26
rep.setLogFile(logFullPath);
_26
}
_26
}

v3.3.0 and later

Use the mLogConfig parameter to set the log file immediately after you create and initialize RtcEngine.

Set the log file path

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

Set the log output level

You can use the level parameter in mLogConfig to set the output log level. Select a level, and all the logs in the levels preceding this level are generated.

  • INFO: (Default) Outputs logs of the FATAL, ERROR, WARN, and INFO level. We recommend setting your log filter as this level.
  • WARN: Outputs logs of the FATAL, ERROR, and WARN level.
  • ERROR: Outputs logs of the FATAL and ERROR level.
  • FATAL: Outputs logs of the FATAL level.
  • NONE: Do not output any log.

Set the log file size

The Agora SDK has five log files, each with a default size of 1024 KB. Use the fileSize parameter in mLogConfig to set the size of each log file.

Sample code


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


_17
// Swift
_17
let logConfig = AgoraLogConfig()
_17
// Set the log filter to ERROR
_17
logConfig.level = AgoraLogLevel.error
_17
// Set the log file path
_17
let formatter = DateFormatter()
_17
formatter.dateFormat = "ddMMyyyyHHmm"
_17
let folder = NSSearchPathForDirectoriesInDomains(.documentDirectoryuserDomainMask, true)
_17
logConfig.filePath = "\(folder[0])/logs/\(formatter.string(from: Date())).log"
_17
// Set the log file size to 2 MB
_17
logConfig.fileSize = 2 * 1024
_17
_17
let config = AgoraRtcEngineConfig()
_17
config.appId = KeyCenter.AppId
_17
config.areaCode = GlobalSettings.shared.area.rawValue
_17
config.logConfig = logConfig
_17
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)


_22
// C++
_22
LogConfig logConfig;
_22
// Set the log filter to ERROR
_22
logConfig.level = LOG_LEVEL::LOG_LEVEL_ERROR;
_22
// Set the log file path
_22
time_t rawtime;
_22
struct tm * timeinfo;
_22
char buffer[128];
_22
time(&rawtime);
_22
timeinfo = localtime(&rawtime);
_22
strftime(buffer, sizeof(buffer), "c:\\log\\%Y%m%d.log", timeinfo);
_22
logConfig.filePath = buffer;
_22
// Set the log file size to 2 MB
_22
logConfig.fileSize = 2048;
_22
_22
RtcEngineContext context;
_22
context.logConfig = logConfig;
_22
std::string strAppID = GET_APP_ID;
_22
context.appId = strAppID.c_str();
_22
context.eventHandler = &m_eventHandler;
_22
// Initialize the Agora Video SDK engine context.
_22
int ret = m_rtcEngine->initialize(context);

API reference

Get the stack information

You can also get the stack information when crashes occur:

  • Android: Run the adb bugreport command
  • iOS:XcodewindowDevices→ Select the corresponding device → Select the corresponding app → Click the Settings button below the app list → Download Container → Right click the downloaded file and select Show Package ContentsAppDataLibraryCachesagorasdk.log
  • macOS: ~/Library/Logs/DiagnosticReports/
  • Windows: 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

You can call enableLogUpload to upload the logs of the Agora Web SDK to the Agora servers, and call disaleLogUpload to stop the upload.

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

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

Set the log output level

Call setLogLevel 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 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

See the sample code based on your SDK version.

Web SDK 3.x


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

Web SDK 4.x


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

API reference

Web SDK 4.x

Web SDK 3.x

vundefined