# How can I set the log file? (/en/api-reference/faq/integration/set_log_file)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

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]

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

### Set up log files [#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 [#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 [#default-log-file-paths-by-platform]

* **Android:** `/storage/emulated/0/Android/data/&lt;package_name&gt;/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\&lt;user_name&gt;\AppData\Local\Agora\&lt;process_name&gt;\agorasdk.log`

<CalloutContainer type="info">
  <CalloutDescription>
    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.
  </CalloutDescription>
</CalloutContainer>

#### Set log output level [#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 [#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 [#sample-code]

<CodeBlockTabs defaultValue="Java">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="Java">
      Java
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="Swift">
      Swift
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="Objective-C">
      Objective-C
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="C++">
      C++
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="Java">
    ```java  tabGroup="set-log-file-native"
    RtcEngineConfig.LogConfig logConfig = new RtcEngineConfig.LogConfig();
    // Set log filter level to ERROR
    logConfig.level = Constants.LogLevel.getValue(Constants.LogLevel.LOG_LEVEL_ERROR);
    // Set log file path
    String ts = new SimpleDateFormat("yyyyMMdd").format(new Date());
    logConfig.filePath = "/sdcard/" + ts + ".log";
    // Set log file size to 2 MB
    logConfig.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);
    ```
  </CodeBlockTab>

  <CodeBlockTab value="Swift">
    ```swift  tabGroup="set-log-file-native"
    let logConfig = AgoraLogConfig()
    // Set log filter level to ERROR
    logConfig.level = AgoraLogLevel.error
    // Set log file path
    let 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 MB
    logConfig.fileSizeInKB = 2 * 1024

    let config = AgoraRtcEngineConfig()
    config.appId = KeyCenter.AppId
    config.areaCode = GlobalSettings.shared.area.rawValue
    config.logConfig = logConfig
    agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
    ```
  </CodeBlockTab>

  <CodeBlockTab value="Objective-C">
    ```objc  tabGroup="set-log-file-native"
    AgoraLogConfig *logConfig = [[AgoraLogConfig alloc] init];
    // Set log filter level to ERROR
    logConfig.level = AgoraLogLevelError;

    // Set log file path
    NSDateFormatter *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 2MB
    logConfig.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];
    ```
  </CodeBlockTab>

  <CodeBlockTab value="C++">
    ```cpp  tabGroup="set-log-file-native"
    LogConfig logConfig;
    // Set log filter level to ERROR
    logConfig.level = LOG_LEVEL::LOG_LEVEL_ERROR;
    // Set log file path
    time_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 2MB
    logConfig.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);
    ```
  </CodeBlockTab>
</CodeBlockTabs>

### API reference [#api-reference]

* Android
  * [`create[2/2\]`](https://api-ref.agora.io/en/video-sdk/android/3.x/classio_1_1agora_1_1rtc_1_1_rtc_engine.html#a45832a91b1051bc7641ccd8958288dba)
* iOS/macOS
  * [`sharedEngineWithConfig`](https://api-ref.agora.io/en/video-sdk/ios/3.x/Classes/AgoraRtcEngineKit.html#/api/name/sharedEngineWithConfig\:delegate:)
* Windows
  * [`initialize`](https://api-ref.agora.io/en/video-sdk/cpp/3.x/classagora_1_1rtc_1_1_i_rtc_engine.html#ac71db65e66942e4e0a0550e95c16890f)

### Get the stack information [#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 [#web]

### Enable or disable log upload [#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 [#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 [#sample-code-1]

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

### API reference [#api-reference-1]

* [`enableLogUpload`](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartc.html#enablelogupload)
* [`disableLogUpload`](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartc.html#disablelogupload)
* [`setLogLevel`](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartc.html#setloglevel)
