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:
- Deletes
agorasdk.4.log
, if present. - Renames
agorasdk.3.log
toagorasdk.4.log
. - Renames
agorasdk.2.log
toagorasdk.3.log
. - Renames
agorasdk.1.log
toagorasdk.2.log
. - 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
- Sandbox enabled:
- Windows:
C:\Users\<user_name>\AppData\Local\Agora\<process_name>\agorasdk.log
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
, andINFO
levels. Recommended. - WARN: Logs at
FATAL
,ERROR
, andWARN
levels. - ERROR: Logs at
FATAL
andERROR
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
, notagoraapi.log
.
Sample Code
- Java
- Swift
- Objective-C
- C++
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);
let logConfig = AgoraLogConfig()// Set log filter level to ERRORlogConfig.level = AgoraLogLevel.error// Set log file pathlet formatter = DateFormatter()formatter.dateFormat = "ddMMyyyyHHmm"let folder = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)logConfig.filePath = "(folder[0])/logs/(formatter.string(from: Date())).log"// Set log file size to 2 MBlogConfig.fileSize = 2 * 1024let config = AgoraRtcEngineConfig()config.appId = KeyCenter.AppIdconfig.areaCode = GlobalSettings.shared.area.rawValueconfig.logConfig = logConfigagoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
AgoraLogConfig *logConfig = [[AgoraLogConfig alloc] init];// Set log filter level to ERRORlogConfig.level = AgoraLogLevelError;// Set log file pathNSDateFormatter *formatter = [[NSDateFormatter alloc] init];[formatter setDateFormat:@"ddMMyyyyHHmm"];NSString *folder = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES )[0];logConfig.filePath = [NSString stringWithFormat:@"%@/logs/%@.log", folder, [formatter stringFromDate:[NSDate date]]];// Set log file size to 2MBlogConfig.fileSizeInKB = 2 * 1024;AgoraRtcEngineConfig *config = [[AgoraRtcEngineConfig alloc] init];config.appId = KeyCenter.AppId;config.areaCode = [GlobalSettings sharedSettings].areaCode;config.logConfig = logConfig;self.agoraKit = [AgoraRtcEngineKit sharedEngineWithConfig:config delegate: self];
LogConfig logConfig;// Set log filter level to ERRORlogConfig.level = LOG_LEVEL::LOG_LEVEL_ERROR;// Set log file pathtime_t rawtime;struct tm * timeinfo;char buffer[128];time(&rawtime);timeinfo = localtime(&rawtime);strftime(buffer, sizeof(buffer), "c:\log\%Y%m%d.log", timeinfo);logConfig.filePath = buffer;// Set log file size to 2MBlogConfig.fileSize = 2048;RtcEngineContext context;context.logConfig = logConfig;std::string strAppID = GET_APP_ID;context.appId = strAppID.c_str();context.eventHandler = &m_eventHandler;int ret = m_rtcEngine->initialize(context);
API reference
- Android
- iOS/macOS
- Windows
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 theINFO
,WARNING
andERROR
levels.WARNING
: Outputs logs in theWARNING
andERROR
levels.ERROR
: Outputs logs in theERROR
level.NONE
: Outputs no log.